bitkeeper revision 1.1159.183.2 (41a216ce6YIv6IWbateVWedQylK5rA)

Restructure libxutil to prepare for adding vnets.
Move common files from xfrd into libxutil.
This commit is contained in:
mjw@wray-m-3.hpl.hp.com committed 2004-11-22 16:41:50 +00:00
1 parent c81cf54c19
commit 4b64c0d7ea
24 files changed
+596 -27

No files matched your search

+15 -10
View File
@@ -336,20 +336,35 @@
40e1b09dMYB4ItGCqcMIzirdMd9I-w tools/libxutil/Makefile
40e033325Sjqs-_4TuzeUEprP_gYFg tools/libxutil/allocate.c
40e03332KYz7o1bn2MG_KPbBlyoIMA tools/libxutil/allocate.h
41a216cav5JJbtDQnusfuMa_1x_Xpw tools/libxutil/debug.h
40e9808eyjiahG5uF6AMelNVujBzCg tools/libxutil/enum.c
40e9808eZpbdn9q2KSSMGCNvY_ZgpQ tools/libxutil/enum.h
40e03332p5Dc_owJQRuN72ymJZddFQ tools/libxutil/file_stream.c
40e03332jWfB2viAhLSkq1WK0r_iDQ tools/libxutil/file_stream.h
40e03332rUjNMGg11n2rN6V4DCrvOg tools/libxutil/gzip_stream.c
40e033321O5Qg22haLoq5lpmk4tooQ tools/libxutil/gzip_stream.h
40e9808easXCzzAZQodEfKAhgUXSPA tools/libxutil/hash_table.c
40e9808e94BNXIVVKBFHC3rnkvwtJg tools/libxutil/hash_table.h
40e03332ihnBGzHykVwZnFmkAppb4g tools/libxutil/iostream.c
40e03332UGwbLR4wsw4ft14p0Yw5pg tools/libxutil/iostream.h
40e0333245DLDzJemeSVBLuutHtzEQ tools/libxutil/kernel_stream.c
40e03332aK0GkgpDdc-PVTkWKTeOBg tools/libxutil/kernel_stream.h
40e9808epW9iHcLXuO3QfUfLzB7onw tools/libxutil/lexis.c
40e9808egccMhCizayQRGtpBA3L5MQ tools/libxutil/lexis.h
41a216caM4z39Fzjb91rv9Ed_4By1A tools/libxutil/socket_stream.c
41a216caqinvF1I5FQMHA4HTRz8MSA tools/libxutil/socket_stream.h
40e03332KT_tnnoAMbPVAZBB7kSOAQ tools/libxutil/string_stream.c
40e03332-VtK6_OZa1vMHXFil8uq6w tools/libxutil/string_stream.h
40e9808e5_PLdodqVOSx0b4T_f5aeg tools/libxutil/sxpr.c
40e9808e0O4sHZtkDv5hlSqjYcdQAQ tools/libxutil/sxpr.h
40ec1cc6SIiGbynOi-1NtPesOlzF-Q tools/libxutil/sxpr_parser.c
40ec1cc6wpvvGxZiq4EFvNOcw0tUFg tools/libxutil/sxpr_parser.h
40e03332Rkvq6nn_UNjzAAK_Tk9v1g tools/libxutil/sys_net.c
40e03332lQHvQHw4Rh7VsT1_sui29A tools/libxutil/sys_net.h
40e033321smklZd7bDSdWvQCeIshtg tools/libxutil/sys_string.c
40e03332h5V611rRWURRLqb1Ekatxg tools/libxutil/sys_string.h
41a216cayFe2FQroFuzvNPw1AvNiqQ tools/libxutil/util.c
41a216ca7mgVSnCBHPCLkGOIqPS1CQ tools/libxutil/util.h
3f776bd2Xd-dUcPKlPN2vG89VGtfvQ tools/misc/Makefile
40ab2cfawIw8tsYo0dQKtp83h4qfTQ tools/misc/fakei386xen
3f6dc136ZKOjd8PIqLbFBl_v-rnkGg tools/misc/miniterm/Makefile
@@ -544,23 +559,13 @@
40e9808eysqT4VNDlJFqsZB2rdg4Qw tools/xfrd/connection.c
40e9808eyXfJUi4E0C3WSgrEXqQ1sQ tools/xfrd/connection.h
40e9808eULGwffNOE4kBrAfZ9YAVMA tools/xfrd/debug.h
40e9808eyjiahG5uF6AMelNVujBzCg tools/xfrd/enum.c
40e9808eZpbdn9q2KSSMGCNvY_ZgpQ tools/xfrd/enum.h
40e9808easXCzzAZQodEfKAhgUXSPA tools/xfrd/hash_table.c
40e9808e94BNXIVVKBFHC3rnkvwtJg tools/xfrd/hash_table.h
411b5139tfKZfWs1LQHmwDR_wjKoxQ tools/xfrd/http.h
40e9808epW9iHcLXuO3QfUfLzB7onw tools/xfrd/lexis.c
40e9808egccMhCizayQRGtpBA3L5MQ tools/xfrd/lexis.h
40e9808ePADCSKL1YgGCt2TbYPnYkw tools/xfrd/lzi_stream.c
40e9808eDNAdpF71o5teYb9DTT-PRw tools/xfrd/lzi_stream.h
40e9808eQxi0EzTcPJtosrzxEIjA-Q tools/xfrd/marshal.c
40e9808etg13xfRm0Lqd8vY-jHOoTg tools/xfrd/marshal.h
40e9808eCsmywryb036TdtRMJHDMmQ tools/xfrd/select.c
40e9808e99OcM547cKMTfmCVSoWVAw tools/xfrd/select.h
40e9808e5_PLdodqVOSx0b4T_f5aeg tools/xfrd/sxpr.c
40e9808e0O4sHZtkDv5hlSqjYcdQAQ tools/xfrd/sxpr.h
40ec1cc6SIiGbynOi-1NtPesOlzF-Q tools/xfrd/sxpr_parser.c
40ec1cc6wpvvGxZiq4EFvNOcw0tUFg tools/xfrd/sxpr_parser.h
40e9808eF3NVldqRNS5IHM8gbFAvpw tools/xfrd/xdr.c
40e9808ezXzoRHm7pybXU69NtnjimA tools/xfrd/xdr.h
40e9808edpUtf4bJ8IbqClPJj_OvbA tools/xfrd/xen_domain.c
+12 -1
View File
@@ -5,11 +5,18 @@ CC = gcc
LIB_SRCS :=
LIB_SRCS += allocate.c
LIB_SRCS += enum.c
LIB_SRCS += file_stream.c
LIB_SRCS += gzip_stream.c
LIB_SRCS += hash_table.c
LIB_SRCS += iostream.c
#LIB_SRCS += sys_net.c
LIB_SRCS += lexis.c
LIB_SRCS += string_stream.c
LIB_SRCS += sxpr.c
LIB_SRCS += sxpr_parser.c
LIB_SRCS += sys_net.c
LIB_SRCS += sys_string.c
LIB_SRCS += util.c
LIB_OBJS := $(LIB_SRCS:.c=.o)
@@ -29,6 +36,7 @@ LIB_NAME := libxutil
LIB := $(LIB_NAME).so
LIB += $(LIB_NAME).so.$(MAJOR)
LIB += $(LIB_NAME).so.$(MAJOR).$(MINOR)
LIB += $(LIB_NAME).a
all: check-for-zlib
$(MAKE) $(LIB)
@@ -42,6 +50,9 @@ $(LIB_NAME).so.$(MAJOR): $(LIB_NAME).so.$(MAJOR).$(MINOR)
$(LIB_NAME).so.$(MAJOR).$(MINOR): $(LIB_OBJS)
$(CC) -Wl,-soname -Wl,$(LIB_NAME).so.$(MAJOR) -shared -o $@ $^
$(LIB_NAME).a: $(LIB_OBJS)
$(AR) rc $@ $^
check-for-zlib:
@if [ ! -e /usr/include/zlib.h ]; then \
echo "***********************************************************"; \
+72
View File
@@ -0,0 +1,72 @@
/*
* Copyright (C) 2004 Mike Wray <mike.wray@hp.com>
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef _XUTIL_DEBUG_H_
#define _XUTIL_DEBUG_H_
#ifndef MODULE_NAME
#define MODULE_NAME ""
#endif
#ifdef __KERNEL__
#include <linux/config.h>
#include <linux/kernel.h>
#ifdef DEBUG
#define dprintf(fmt, args...) printk(KERN_DEBUG "[DBG] " MODULE_NAME ">%s" fmt, __FUNCTION__, ##args)
#define wprintf(fmt, args...) printk(KERN_WARNING "[WRN] " MODULE_NAME ">%s" fmt, __FUNCTION__, ##args)
#define iprintf(fmt, args...) printk(KERN_INFO "[INF] " MODULE_NAME ">%s" fmt, __FUNCTION__, ##args)
#define eprintf(fmt, args...) printk(KERN_ERR "[ERR] " MODULE_NAME ">%s" fmt, __FUNCTION__, ##args)
#else
#define dprintf(fmt, args...) do {} while(0)
#define wprintf(fmt, args...) printk(KERN_WARNING "[WRN] " MODULE_NAME fmt, ##args)
#define iprintf(fmt, args...) printk(KERN_INFO "[INF] " MODULE_NAME fmt, ##args)
#define eprintf(fmt, args...) printk(KERN_ERR "[ERR] " MODULE_NAME fmt, ##args)
#endif
#else
#include <stdio.h>
#ifdef DEBUG
#define dprintf(fmt, args...) fprintf(stdout, "%d [DBG] " MODULE_NAME ">%s" fmt, getpid(), __FUNCTION__, ##args)
#define wprintf(fmt, args...) fprintf(stderr, "%d [WRN] " MODULE_NAME ">%s" fmt, getpid(),__FUNCTION__, ##args)
#define iprintf(fmt, args...) fprintf(stderr, "%d [INF] " MODULE_NAME ">%s" fmt, getpid(),__FUNCTION__, ##args)
#define eprintf(fmt, args...) fprintf(stderr, "%d [ERR] " MODULE_NAME ">%s" fmt, getpid(),__FUNCTION__, ##args)
#else
#define dprintf(fmt, args...) do {} while(0)
#define wprintf(fmt, args...) fprintf(stderr, "%d [WRN] " MODULE_NAME fmt, getpid(), ##args)
#define iprintf(fmt, args...) fprintf(stderr, "%d [INF] " MODULE_NAME fmt, getpid(), ##args)
#define eprintf(fmt, args...) fprintf(stderr, "%d [ERR] " MODULE_NAME fmt, getpid(), ##args)
#endif
#endif
/** Print format for an IP address.
* See NIPQUAD(), HIPQUAD()
*/
#define IPFMT "%u.%u.%u.%u"
#endif /* ! _XUTIL_DEBUG_H_ */
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
+18
View File
@@ -1,3 +1,21 @@
/*
* Copyright (C) 2001 - 2004 Mike Wray <mike.wray@hp.com>
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "iostream.h"
#include "sys_string.h"
+25 -5
View File
@@ -1,14 +1,34 @@
#ifndef _XC_LINUX_SAVE_H_
#define _XC_LINUX_SAVE_H_
/*
* Copyright (C) 2001 - 2004 Mike Wray <mike.wray@hp.com>
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef _XUTIL_IOSTREAM_H_
#define _XUTIL_IOSTREAM_H_
#include <stdarg.h>
#include <stdint.h>
#include <stddef.h>
#ifdef __KERNEL__
#include <linux/config.h>
#include <linux/types.h>
#include <linux/errno.h>
#else
#include <errno.h>
#include <stdint.h>
#include <stddef.h>
#endif
#include "allocate.h"
@@ -240,4 +260,4 @@ static inline int IOStream_get_written(IOStream *stream){
}
#endif /* ! _XC_LINUX_SAVE_H_ */
#endif /* ! _XUTIL_IOSTREAM_H_ */
+4 -4
View File
@@ -50,7 +50,7 @@ typedef struct KernelData {
char buf[BUF_N];
} KernelData;
static int kernel_write(IOStream *s, const char *msg, int n);
static int kernel_write(IOStream *s, const void *msg, size_t n);
static void kernel_free(IOStream *s);
static void kernel_stream_lock(IOStream *s);
static void kernel_stream_unlock(IOStream *s);
@@ -145,13 +145,13 @@ void kernel_stream_unlock(IOStream *s){
* @param args print arguments
* @return result of the print
*/
static int kernel_write(IOStream *stream, const char *buf, int n){
static int kernel_write(IOStream *stream, const void *buf, size_t n){
KernelData *kdata = get_kernel_data(stream);
int k;
k = kdata->buf_n - 1;
if(n < k) k = n;
memcpy(kdata->buf, buf, k);
kdata->buf[k] = '\0'
kdata->buf[k] = '\0';
printk(kdata->buf);
return k;
}
@@ -167,7 +167,7 @@ static void kernel_free(IOStream *io){
KernelData *kdata;
if(io == &iokernel) return;
kdata = get_kernel_data(io);
zero(kdata, sizeof(*kdata));
memset(kdata, 0, sizeof(*kdata));
deallocate(kdata);
}
#endif /* __KERNEL__ */
@@ -1,4 +1,5 @@
/*
* Copyright (C) 2001 - 2004 Mike Wray <mike.wray@hp.com>
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
@@ -1,4 +1,5 @@
/*
* Copyright (C) 2001 - 2004 Mike Wray <mike.wray@hp.com>
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
+230
View File
@@ -0,0 +1,230 @@
/*
* Copyright (C) 2004 Mike Wray <mike.wray@hp.com>
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/** @file
* An IOStream implementation using sockets.
*/
#ifndef __KERNEL__
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include "allocate.h"
#include "socket_stream.h"
#define MODULE_NAME "sock"
#define DEBUG 0
//#undef DEBUG
#include "debug.h"
static int socket_read(IOStream *s, void *buf, size_t n);
static int socket_write(IOStream *s, const void *buf, size_t n);
static int socket_error(IOStream *s);
static int socket_close(IOStream *s);
static void socket_free(IOStream *s);
static int socket_flush(IOStream *s);
/** Methods used by a socket IOStream. */
static const IOMethods socket_methods = {
read: socket_read,
write: socket_write,
error: socket_error,
close: socket_close,
free: socket_free,
flush: socket_flush,
};
/** Get the socket data.
*
* @param io socket stream
* @return data
*/
static inline SocketData * socket_data(IOStream *io){
return (SocketData *)io->data;
}
/** Test if a stream is a socket stream.
*
* @param io stream
* @return 0 if a socket stream, -EINVAL if not
*/
int socket_stream_check(IOStream *io){
return (io && io->methods == &socket_methods ? 0 : -EINVAL);
}
/** Get the data for a socket stream.
*
* @param io stream
* @param data return value for the data
* @return 0 if a socket stream, -EINVAL if not
*/
int socket_stream_data(IOStream *io, SocketData **data){
int err = socket_stream_check(io);
if(err){
*data = NULL;
} else {
*data = socket_data(io);
}
return err;
}
/** Set the destination address for a socket stream.
*
* @param io stream
* @param addr address
* @return 0 if a socket stream, -EINVAL if not
*/
int socket_stream_set_addr(IOStream *io, struct sockaddr_in *addr){
int err = 0;
SocketData *data = NULL;
err = socket_stream_data(io, &data);
if(!err){
data->daddr = *addr;
}
return err;
}
/** Set the send flags for a socket stream.
*
* @param io stream
* @param flags flags
* @return 0 if a socket stream, -EINVAL if not
*/
int socket_stream_set_flags(IOStream *io, int flags){
int err = 0;
SocketData *data = NULL;
err = socket_stream_data(io, &data);
if(!err){
data->flags = flags;
}
return err;
}
/** Write to the underlying socket using sendto.
*
* @param stream input
* @param buf where to put input
* @param n number of bytes to write
* @return number of bytes written
*/
static int socket_write(IOStream *s, const void *buf, size_t n){
SocketData *data = socket_data(s);
struct sockaddr *daddr = (struct sockaddr *)&data->daddr;
socklen_t daddr_n = sizeof(data->daddr);
int k;
dprintf("> sock=%d addr=%s:%d n=%d\n",
data->fd, inet_ntoa(data->daddr.sin_addr), ntohs(data->daddr.sin_port), n);
if(0){
struct sockaddr_in self = {};
socklen_t self_n;
getsockname(data->fd, (struct sockaddr *)&self, &self_n);
dprintf("> sockname sock=%d %s:%d\n",
data->fd, inet_ntoa(self.sin_addr), ntohs(self.sin_port));
}
k = sendto(data->fd, buf, n, data->flags, daddr, daddr_n);
dprintf("> sendto=%d\n", k);
return k;
}
/** Read from the underlying stream using recv();
*
* @param stream input
* @param buf where to put input
* @param n number of bytes to read
* @return number of bytes read
*/
static int socket_read(IOStream *s, void *buf, size_t n){
SocketData *data = socket_data(s);
int k;
struct sockaddr *saddr = (struct sockaddr *)&data->saddr;
socklen_t saddr_n = sizeof(data->saddr);
k = recvfrom(data->fd, buf, n, data->flags, saddr, &saddr_n);
return k;
}
/** Flush the socket (no-op).
*
* @param s socket stream
* @return 0 on success, error code otherwise
*/
static int socket_flush(IOStream *s){
return 0;
}
/** Check if a socket stream has an error (no-op).
*
* @param s socket stream
* @return 1 if has an error, 0 otherwise
*/
static int socket_error(IOStream *s){
// Read SOL_SOCKET/SO_ERROR ?
return 0;
}
/** Close a socket stream.
*
* @param s socket stream to close
* @return result of the close
*/
static int socket_close(IOStream *s){
SocketData *data = socket_data(s);
return close(data->fd);
}
/** Free a socket stream.
*
* @param s socket stream
*/
static void socket_free(IOStream *s){
SocketData *data = socket_data(s);
deallocate(data);
}
/** Create an IOStream for a socket.
*
* @param fd socket to wtap
* @return new IOStream using fd for i/o
*/
IOStream *socket_stream_new(int fd){
int err = -ENOMEM;
IOStream *io = NULL;
SocketData *data = NULL;
io = ALLOCATE(IOStream);
if(!io) goto exit;
io->methods = &socket_methods;
data = ALLOCATE(SocketData);
if(!data) goto exit;
io->data = data;
data->fd = fd;
data->buf_n = sizeof(data->buf);
err = 0;
exit:
if(err){
if(io){
if(data) deallocate(data);
deallocate(io);
io = NULL;
}
}
return io;
}
#endif
+53
View File
@@ -0,0 +1,53 @@
/*
* Copyright (C) 2004 Mike Wray <mike.wray@hp.com>
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef _XEN_LIB_SOCKET_STREAM_H_
#define _XEN_LIB_SOCKET_STREAM_H_
#ifndef __KERNEL__
#include "iostream.h"
#include <stdio.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
/** Data associated with a socket stream. */
typedef struct SocketData {
/** The socket file descriptor. */
int fd;
/** Source address from last read (recvfrom). */
struct sockaddr_in saddr;
/** Destination address for writes (sendto). */
struct sockaddr_in daddr;
/** Write flags (sendto). */
int flags;
/** Buffer size. */
int buf_n;
/** Buffer for formatted printing. */
char buf[1024];
} SocketData;
extern IOStream *socket_stream_new(int fd);
extern int socket_stream_data(IOStream *io, SocketData **data);
extern int socket_stream_check(IOStream *io);
extern int socket_stream_set_addr(IOStream *io, struct sockaddr_in *addr);
extern int socket_stream_set_flags(IOStream *io, int flags);
#endif
#endif /* !_XEN_LIB_SOCKET_STREAM_H_ */
+1 -1
View File
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2001, 2002 Hewlett-Packard Company.
* Copyright (C) 2001 - 2004 Mike Wray <mike.wray@hp.com>
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
+1 -1
View File
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2001, 2002 Hewlett-Packard Company.
* Copyright (C) 2001 - 2004 Mike Wray <mike.wray@hp.com>
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
@@ -1,4 +1,5 @@
/*
* Copyright (C) 2001 - 2004 Mike Wray <mike.wray@hp.com>
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
@@ -21,7 +22,12 @@
#include "hash_table.h"
#include "sxpr.h"
#ifdef __KERNEL__
#include <linux/errno.h>
#else
#include <errno.h>
#endif
#undef free
/** @file
@@ -1,4 +1,5 @@
/*
* Copyright (C) 2001 - 2004 Mike Wray <mike.wray@hp.com>
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
@@ -16,7 +17,12 @@
#ifndef _XUTIL_SXPR_H_
#define _XUTIL_SXPR_H_
#ifdef __KERNEL__
#include <linux/config.h>
#include <linux/types.h>
#else
#include <stdint.h>
#endif
#include "hash_table.h"
#include "iostream.h"
@@ -1,3 +1,19 @@
/*
* Copyright (C) 2001 - 2004 Mike Wray <mike.wray@hp.com>
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of the
* License, or (at your option) any later version. This library is
* distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifdef __KERNEL__
# include <linux/config.h>
@@ -1,4 +1,5 @@
/*
* Copyright (C) 2001 - 2004 Mike Wray <mike.wray@hp.com>
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
-4
View File
@@ -232,21 +232,17 @@ char *get_port_service(unsigned long port){
int convert_service_to_port(const char *s, unsigned long *port){
int err = 0;
unsigned long value;
printf("%s> %s\n", __FUNCTION__, s);
if(convert_atoul(s, &value) == 0){
int ok = (0 <= value) && (value <= PORT_MAX);
printf("> value = %ld\n", value);
if(ok){
value = htons((unsigned short)value);
} else {
err = -EINVAL;
}
} else {
printf("> get_service_port...\n");
err = get_service_port(s, &value);
}
*port = (err ? 0: value);
printf("%s< err=%d\n", __FUNCTION__, err);
return err;
}
+106
View File
@@ -0,0 +1,106 @@
/*
* Copyright (C) 2002 - 2004 Mike Wray <mike.wray@hp.com>.
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of the
* License, or (at your option) any later version. This library is
* distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "sys_net.h"
#include "sys_string.h"
#ifndef __KERNEL__
# include <grp.h>
# include <pwd.h>
#endif
#include "util.h"
/** @file Various utility functions.
*/
/** Print an address (in network order) as an IPv4 address string
* in dot notation.
*
* @param io where to print address
* @param address to print (in network order)
* @return bytes printed
*/
int print_address(IOStream *io, unsigned long address){
#ifdef __KERNEL__
address = ntohl(address);
return IOStream_print(io, "%u.%u.%u.%u",
(unsigned)((address >> 24) & 0xff),
(unsigned)((address >> 16) & 0xff),
(unsigned)((address >> 8) & 0xff),
(unsigned)((address ) & 0xff));
#else
struct in_addr inaddr = { s_addr: address };
return IOStream_print(io, inet_ntoa(inaddr));
#endif
}
/** Get the protocol number for a protocol.
*
* @param name protocol name
* @param protocol where to put the protocol number
* @return 0 if OK, error otherwise
*/
int get_protocol_number(char *name, unsigned long *protocol){
#ifdef __KERNEL__
return -1;
#else
struct protoent *proto = getprotobyname(name);
if(!proto){
return -1;
}
*protocol = proto->p_proto;
return 0;
#endif
}
/** Get the protocol name for a protocol number.
*
* @param protocol number
* @return name or null
*/
char *get_protocol_name(unsigned long protocol){
#ifdef __KERNEL__
return 0;
#else
struct protoent *proto = getprotobynumber(protocol);
if(!proto){
return 0;
}
return proto->p_name;
#endif
}
/** Get the host name for an address.
*
* @param addr address
* @return host name or null
*/
char *get_host_name(unsigned long addr){
#ifdef __KERNEL__
return 0;
#else
struct in_addr inaddr;
struct hostent *host = 0;
inaddr.s_addr = addr;
host = gethostbyaddr((char*)&inaddr, sizeof(inaddr), AF_INET);
if(!host) return NULL;
return host->h_name;
#endif
}
+28
View File
@@ -0,0 +1,28 @@
/*
* Copyright (C) 2002 - 2004 Mike Wray <mike.wray@hp.com>.
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of the
* License, or (at your option) any later version. This library is
* distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef _XEN_LIB_UTIL_H_
#define _XEN_LIB_UTIL_H_
#include "iostream.h"
extern int print_address(IOStream *io, unsigned long address);
extern int get_protocol_number(char *name, unsigned long *protocol);
extern char *get_protocol_name(unsigned long protocol);
extern char *get_host_name(unsigned long addr);
#endif /* ! _XEN_LIB_UTIL_H_ */
-1
View File
@@ -26,7 +26,6 @@ UTIL_LIB_SRC += xdr.c
XFRD_PROG_SRC =
XFRD_PROG_SRC += xfrd.c
#XFRD_PROG_SRC += xfr_msg.c
XFRD_PROG_SRC += xen_domain.c
XFRD_PROG_SRC += select.c
XFRD_PROG_SRC += connection.c
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.