diff --git a/ChangeLog b/ChangeLog index e7eec04..f6b41bb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +2005-11-01 Guillem Jover + + * ip_icmp.h: Move to ... + * include/bsd/ip_icmp.h: ... here. + * md5.h: Move to ... + * include/bsd/md5.h: ... here. + * bsd.h: Move to ... + * include/bsd/bsd.h: ... here. Split contents ... + * include/bsd/random.h: ... here ... + * include/bsd/queue.h: ... here ... + * include/bsd/string.h: ... and here. + * md5c.c: Change md5.h include line. + * Makefile (MK_CFLAGS): Include from the proper dir. + 2005-08-03 Hector Garcia * Makefile: Fixed to place soft links instead in soname and shared_so diff --git a/Makefile b/Makefile index 1a08c25..f0e2c06 100644 --- a/Makefile +++ b/Makefile @@ -21,7 +21,7 @@ LIB_SHARED_SO = $(LIB_NAME).so LIB_SONAME = $(LIB_SHARED_SO).$(LIB_VERSION_MAJOR) LIB_SHARED = $(LIB_SONAME).$(LIB_VERSION_MINOR) -MK_CFLAGS = -include bsd.h -D_GNU_SOURCE +MK_CFLAGS = -Iinclude/ -include bsd/bsd.h -D_GNU_SOURCE libs: $(LIB_STATIC) $(LIB_SHARED_SO) diff --git a/bsd.h b/bsd.h deleted file mode 100644 index cd0cdc3..0000000 --- a/bsd.h +++ /dev/null @@ -1,266 +0,0 @@ -#ifndef LIBPORT_H -#define LIBPORT_H - -#define setproctitle(fmt, args...) - -#define __dead2 -#define __printflike(x,y) -#define __FBSDID(x) - -#include -#include - - -typedef char * __va_list; -#if !defined(__GNUC_VA_LIST) -#define __GNUC_VA_LIST -typedef __va_list __gnuc_va_list; /* compatibility w/GNU headers*/ -#endif - - -/* - * Missing BSD sys/queue.h definitions - */ - -/* - * Singly-linked Tail queue declarations. - */ -#define STAILQ_HEAD(name, type) \ -struct name { \ - struct type *stqh_first;/* first element */ \ - struct type **stqh_last;/* addr of last next element */ \ -} - -#define STAILQ_HEAD_INITIALIZER(head) \ - { NULL, &(head).stqh_first } - -#define STAILQ_ENTRY(type) \ -struct { \ - struct type *stqe_next; /* next element */ \ -} - -/* - * Singly-linked Tail queue functions. - */ -#define STAILQ_CONCAT(head1, head2) do { \ - if (!STAILQ_EMPTY((head2))) { \ - *(head1)->stqh_last = (head2)->stqh_first; \ - (head1)->stqh_last = (head2)->stqh_last; \ - STAILQ_INIT((head2)); \ - } \ -} while (0) - -#define STAILQ_EMPTY(head) ((head)->stqh_first == NULL) - -#define STAILQ_FIRST(head) ((head)->stqh_first) - -#define STAILQ_FOREACH(var, head, field) \ - for((var) = STAILQ_FIRST((head)); \ - (var); \ - (var) = STAILQ_NEXT((var), field)) - -#define STAILQ_INIT(head) do { \ - STAILQ_FIRST((head)) = NULL; \ - (head)->stqh_last = &STAILQ_FIRST((head)); \ -} while (0) - -#define STAILQ_INSERT_AFTER(head, tqelm, elm, field) do { \ - if ((STAILQ_NEXT((elm), field) = STAILQ_NEXT((tqelm), field)) == NULL)\ - (head)->stqh_last = &STAILQ_NEXT((elm), field); \ - STAILQ_NEXT((tqelm), field) = (elm); \ -} while (0) - -#define STAILQ_INSERT_HEAD(head, elm, field) do { \ - if ((STAILQ_NEXT((elm), field) = STAILQ_FIRST((head))) == NULL) \ - (head)->stqh_last = &STAILQ_NEXT((elm), field); \ - STAILQ_FIRST((head)) = (elm); \ -} while (0) - -#define STAILQ_INSERT_TAIL(head, elm, field) do { \ - STAILQ_NEXT((elm), field) = NULL; \ - *(head)->stqh_last = (elm); \ - (head)->stqh_last = &STAILQ_NEXT((elm), field); \ -} while (0) - -#define STAILQ_LAST(head, type, field) \ - (STAILQ_EMPTY((head)) ? \ - NULL : \ - ((struct type *) \ - ((char *)((head)->stqh_last) - __offsetof(struct type, field)))) - -#define STAILQ_NEXT(elm, field) ((elm)->field.stqe_next) - -#define STAILQ_REMOVE(head, elm, type, field) do { \ - if (STAILQ_FIRST((head)) == (elm)) { \ - STAILQ_REMOVE_HEAD((head), field); \ - } \ - else { \ - struct type *curelm = STAILQ_FIRST((head)); \ - while (STAILQ_NEXT(curelm, field) != (elm)) \ - curelm = STAILQ_NEXT(curelm, field); \ - if ((STAILQ_NEXT(curelm, field) = \ - STAILQ_NEXT(STAILQ_NEXT(curelm, field), field)) == NULL)\ - (head)->stqh_last = &STAILQ_NEXT((curelm), field);\ - } \ -} while (0) - -#define STAILQ_REMOVE_HEAD(head, field) do { \ - if ((STAILQ_FIRST((head)) = \ - STAILQ_NEXT(STAILQ_FIRST((head)), field)) == NULL) \ - (head)->stqh_last = &STAILQ_FIRST((head)); \ -} while (0) - -#define STAILQ_REMOVE_HEAD_UNTIL(head, elm, field) do { \ - if ((STAILQ_FIRST((head)) = STAILQ_NEXT((elm), field)) == NULL) \ - (head)->stqh_last = &STAILQ_FIRST((head)); \ -} while (0) - -/* - * List declarations. - */ -#define LIST_HEAD(name, type) \ -struct name { \ - struct type *lh_first; /* first element */ \ -} - -#define LIST_HEAD_INITIALIZER(head) \ - { NULL } - -#define LIST_ENTRY(type) \ -struct { \ - struct type *le_next; /* next element */ \ - struct type **le_prev; /* address of previous next element */ \ -} - -/* - * List functions. - */ - -#define LIST_EMPTY(head) ((head)->lh_first == NULL) - -#define LIST_FIRST(head) ((head)->lh_first) - -#define LIST_FOREACH(var, head, field) \ - for ((var) = LIST_FIRST((head)); \ - (var); \ - (var) = LIST_NEXT((var), field)) - -#define LIST_INSERT_BEFORE(listelm, elm, field) do { \ - (elm)->field.le_prev = (listelm)->field.le_prev; \ - LIST_NEXT((elm), field) = (listelm); \ - *(listelm)->field.le_prev = (elm); \ - (listelm)->field.le_prev = &LIST_NEXT((elm), field); \ -} while (0) - -#define LIST_NEXT(elm, field) ((elm)->field.le_next) - -#define TAILQ_FIRST(head) ((head)->tqh_first) - -#define TAILQ_FOREACH(var, head, field) \ - for ((var) = TAILQ_FIRST((head)); \ - (var); \ - (var) = TAILQ_NEXT((var), field)) - -#define TAILQ_NEXT(elm, field) ((elm)->field.tqe_next) - -#define TAILQ_HEAD_INITIALIZER(head) \ - { NULL, &(head).tqh_first } - - -#include -#include -#include - -#define ICMP_TRACEROUTE 30 /* traceroute */ -#define ICMP_DATACONVERR 31 /* data conversion error */ -#define ICMP_MOBILE_REDIRECT 32 /* mobile host redirect */ -#define ICMP_IPV6_WHEREAREYOU 33 /* IPv6 where-are-you */ -#define ICMP_IPV6_IAMHERE 34 /* IPv6 i-am-here */ -#define ICMP_MOBILE_REGREQUEST 35 /* mobile registration req */ -#define ICMP_MOBILE_REGREPLY 36 /* mobile registration reply */ -#define ICMP_SKIP 39 /* SKIP */ -#define ICMP_PHOTURIS 40 /* Photuris */ -#define MLD_LISTENER_QUERY 130 /* multicast listener query */ -#define MLD_LISTENER_REPORT 131 /* multicast listener report */ -#define MLD_LISTENER_DONE 132 /* multicast listener done */ -#define ICMP6_ROUTER_RENUMBERING 138 /* router renumbering */ -#define ICMP6_WRUREQUEST 139 /* who are you request */ -#define ICMP6_WRUREPLY 140 /* who are you reply */ -#define ICMP6_FQDN_QUERY 139 /* FQDN query */ -#define ICMP6_FQDN_REPLY 140 /* FQDN reply */ -#define ICMP6_NI_QUERY 139 /* node information request */ -#define ICMP6_NI_REPLY 140 /* node information reply */ -#define MLD_MTRACE_RESP 200 /* mtrace resp (to sender) */ -#define MLD_MTRACE 201 /* mtrace messages */ -#define ICMP_ROUTERADVERT_NORMAL 0 /* normal advertisement */ -#define ICMP_ROUTERADVERT_NOROUTE_COMMON 16 /* selective routing */ -#define ICMP_PHOTURIS_UNKNOWN_INDEX 1 /* unknown sec index */ -#define ICMP_PHOTURIS_AUTH_FAILED 2 /* auth failed */ -#define ICMP_PHOTURIS_DECRYPT_FAILED 3 /* decrypt failed */ -#define ICMP6_DST_UNREACH_BEYONDSCOPE 2 /* beyond scope of source address */ -#define ND_REDIRECT_ONLINK 0 /* redirect to an on-link node */ -#define ND_REDIRECT_ROUTER 1 /* redirect to a better router */ - - -#define GID_MAX UINT_MAX /* max value for a gid_t */ -#define UID_MAX UINT_MAX /* max value for a uid_t */ - -#define SIZE_T_MAX __SIZE_T_MAX /* max value for a size_t */ - -// This depends on the arch, so this must be ported in other manner -#define __SIZE_T_MAX __UINT_MAX /* max value for a size_t */ -#define __UINT_MAX 0xffffffffU /* max value for an unsigned int */ - -#define ICMP_ALTHOSTADDR 6 /* alternate host address */ - -#define HTONL(x) (x) = htonl((__uint32_t)(x)) - -#if _BYTE_ORDER == _LITTLE_ENDIAN - -#define be64toh(x) bswap64((x)) -#else /* _BYTE_ORDER != _LITTLE_ENDIAN */ - -#define be64toh(x) ((uint64_t)(x)) -#endif /* _BYTE_ORDER == _LITTLE_ENDIAN */ - -#define bswap64(x) __bswap64(x) - -extern time_t time (time_t *__timer) __THROW; - - -static __inline __uint64_t -__bswap64(__uint64_t _x) -{ - return ((_x >> 56) | ((_x >> 40) & 0xff00) | ((_x >> 24) & 0xff0000) | - ((_x >> 8) & 0xff000000) | ((_x << 8) & ((__uint64_t)0xff << 32)) | - ((_x << 24) & ((__uint64_t)0xff << 40)) | - ((_x << 40) & ((__uint64_t)0xff << 48)) | ((_x << 56))); -} - - -size_t strlcpy(char *dst, const char *src, size_t siz); -size_t strlcat(char *dst, const char *src, size_t siz); -char * fgetln(FILE *fp, size_t *lenp); - -u_int32_t arc4random(void); - - -struct __sbuf { - unsigned char *_base; - int _size; -}; - - -// Directly from FreeBSD stdio.h - -//#define __SMOD 0x2000 /* true => fgetln modified _p text */ -//#define __SLBF 0x0001 /* line buffered */ -//#define __SWR 0x0008 /* OK to write */ -//#define __SEOF 0x0020 /* found EOF */ -//#define __SRD 0x0004 /* OK to read */ -//#define __SRW 0x0010 /* open for reading & writing */ -//#define __SERR 0x0040 /* found error */ -//#define __SNBF 0x0002 /* unbuffered */ -//#define __SIGN 0x8000 /* ignore this file in _fwalk */ - -#endif diff --git a/include/bsd/bsd.h b/include/bsd/bsd.h new file mode 100644 index 0000000..56afcce --- /dev/null +++ b/include/bsd/bsd.h @@ -0,0 +1,110 @@ +#ifndef LIBBSD_H +#define LIBBSD_H + +/* + * Generic definitions. + */ + +#define setproctitle(fmt, args...) + +#define __dead2 +#define __printflike(x,y) +#define __FBSDID(x) + +#include + +/* + * Include all bsd compat headers. + */ + +#include +#include +#include +#include + +/* + * Stuff to be moved. + */ + +#include + +typedef char * __va_list; +#if !defined(__GNUC_VA_LIST) +#define __GNUC_VA_LIST +typedef __va_list __gnuc_va_list; /* compatibility w/ GNU headers */ +#endif + +extern time_t time (time_t *__timer) __THROW; + +struct __sbuf { + unsigned char *_base; + int _size; +}; + +#define MLD_LISTENER_QUERY 130 /* multicast listener query */ +#define MLD_LISTENER_REPORT 131 /* multicast listener report */ +#define MLD_LISTENER_DONE 132 /* multicast listener done */ +#define ICMP6_ROUTER_RENUMBERING 138 /* router renumbering */ +#define ICMP6_WRUREQUEST 139 /* who are you request */ +#define ICMP6_WRUREPLY 140 /* who are you reply */ +#define ICMP6_FQDN_QUERY 139 /* FQDN query */ +#define ICMP6_FQDN_REPLY 140 /* FQDN reply */ +#define ICMP6_NI_QUERY 139 /* node information request */ +#define ICMP6_NI_REPLY 140 /* node information reply */ +#define MLD_MTRACE_RESP 200 /* mtrace resp (to sender) */ +#define MLD_MTRACE 201 /* mtrace messages */ +#define ICMP6_DST_UNREACH_BEYONDSCOPE 2 /* beyond scope of source address */ +#define ND_REDIRECT_ONLINK 0 /* redirect to an on-link node */ +#define ND_REDIRECT_ROUTER 1 /* redirect to a better router */ + +/* + * Limits. + */ + +#define GID_MAX UINT_MAX /* max value for a gid_t */ +#define UID_MAX UINT_MAX /* max value for a uid_t */ + +#define SIZE_T_MAX __SIZE_T_MAX /* max value for a size_t */ + +// This depends on the arch, so this must be ported in other manner +#define __SIZE_T_MAX __UINT_MAX /* max value for a size_t */ +#define __UINT_MAX 0xffffffffU /* max value for an unsigned int */ + +/* + * Endianness. + */ + +#define HTONL(x) (x) = htonl((__uint32_t)(x)) + +#if _BYTE_ORDER == _LITTLE_ENDIAN +#define be64toh(x) bswap64((x)) +#else /* _BYTE_ORDER != _LITTLE_ENDIAN */ +#define be64toh(x) ((uint64_t)(x)) +#endif /* _BYTE_ORDER == _LITTLE_ENDIAN */ + +#define bswap64(x) __bswap64(x) + +static __inline __uint64_t +__bswap64(__uint64_t _x) +{ + return ((_x >> 56) | ((_x >> 40) & 0xff00) | ((_x >> 24) & 0xff0000) | + ((_x >> 8) & 0xff000000) | ((_x << 8) & ((__uint64_t)0xff << 32)) | + ((_x << 24) & ((__uint64_t)0xff << 40)) | + ((_x << 40) & ((__uint64_t)0xff << 48)) | ((_x << 56))); +} + +/* + * Directly from FreeBSD stdio.h + */ + +//#define __SMOD 0x2000 /* true => fgetln modified _p text */ +//#define __SLBF 0x0001 /* line buffered */ +//#define __SWR 0x0008 /* OK to write */ +//#define __SEOF 0x0020 /* found EOF */ +//#define __SRD 0x0004 /* OK to read */ +//#define __SRW 0x0010 /* open for reading & writing */ +//#define __SERR 0x0040 /* found error */ +//#define __SNBF 0x0002 /* unbuffered */ +//#define __SIGN 0x8000 /* ignore this file in _fwalk */ + +#endif diff --git a/ip_icmp.h b/include/bsd/ip_icmp.h similarity index 100% rename from ip_icmp.h rename to include/bsd/ip_icmp.h diff --git a/md5.h b/include/bsd/md5.h similarity index 100% rename from md5.h rename to include/bsd/md5.h diff --git a/include/bsd/queue.h b/include/bsd/queue.h new file mode 100644 index 0000000..8bf661b --- /dev/null +++ b/include/bsd/queue.h @@ -0,0 +1,151 @@ +#ifndef LIBBSD_QUEUE_H +#define LIBBSD_QUEUE_H + +#include + +/* + * Singly-linked Tail queue declarations. + */ +#define STAILQ_HEAD(name, type) \ +struct name { \ + struct type *stqh_first;/* first element */ \ + struct type **stqh_last;/* addr of last next element */ \ +} + +#define STAILQ_HEAD_INITIALIZER(head) \ + { NULL, &(head).stqh_first } + +#define STAILQ_ENTRY(type) \ +struct { \ + struct type *stqe_next; /* next element */ \ +} + +/* + * Singly-linked Tail queue functions. + */ +#define STAILQ_CONCAT(head1, head2) do { \ + if (!STAILQ_EMPTY((head2))) { \ + *(head1)->stqh_last = (head2)->stqh_first; \ + (head1)->stqh_last = (head2)->stqh_last; \ + STAILQ_INIT((head2)); \ + } \ +} while (0) + +#define STAILQ_EMPTY(head) ((head)->stqh_first == NULL) + +#define STAILQ_FIRST(head) ((head)->stqh_first) + +#define STAILQ_FOREACH(var, head, field) \ + for((var) = STAILQ_FIRST((head)); \ + (var); \ + (var) = STAILQ_NEXT((var), field)) + +#define STAILQ_INIT(head) do { \ + STAILQ_FIRST((head)) = NULL; \ + (head)->stqh_last = &STAILQ_FIRST((head)); \ +} while (0) + +#define STAILQ_INSERT_AFTER(head, tqelm, elm, field) do { \ + if ((STAILQ_NEXT((elm), field) = STAILQ_NEXT((tqelm), field)) == NULL)\ + (head)->stqh_last = &STAILQ_NEXT((elm), field); \ + STAILQ_NEXT((tqelm), field) = (elm); \ +} while (0) + +#define STAILQ_INSERT_HEAD(head, elm, field) do { \ + if ((STAILQ_NEXT((elm), field) = STAILQ_FIRST((head))) == NULL) \ + (head)->stqh_last = &STAILQ_NEXT((elm), field); \ + STAILQ_FIRST((head)) = (elm); \ +} while (0) + +#define STAILQ_INSERT_TAIL(head, elm, field) do { \ + STAILQ_NEXT((elm), field) = NULL; \ + *(head)->stqh_last = (elm); \ + (head)->stqh_last = &STAILQ_NEXT((elm), field); \ +} while (0) + +#define STAILQ_LAST(head, type, field) \ + (STAILQ_EMPTY((head)) ? \ + NULL : \ + ((struct type *) \ + ((char *)((head)->stqh_last) - __offsetof(struct type, field)))) + +#define STAILQ_NEXT(elm, field) ((elm)->field.stqe_next) + +#define STAILQ_REMOVE(head, elm, type, field) do { \ + if (STAILQ_FIRST((head)) == (elm)) { \ + STAILQ_REMOVE_HEAD((head), field); \ + } \ + else { \ + struct type *curelm = STAILQ_FIRST((head)); \ + while (STAILQ_NEXT(curelm, field) != (elm)) \ + curelm = STAILQ_NEXT(curelm, field); \ + if ((STAILQ_NEXT(curelm, field) = \ + STAILQ_NEXT(STAILQ_NEXT(curelm, field), field)) == NULL)\ + (head)->stqh_last = &STAILQ_NEXT((curelm), field);\ + } \ +} while (0) + +#define STAILQ_REMOVE_HEAD(head, field) do { \ + if ((STAILQ_FIRST((head)) = \ + STAILQ_NEXT(STAILQ_FIRST((head)), field)) == NULL) \ + (head)->stqh_last = &STAILQ_FIRST((head)); \ +} while (0) + +#define STAILQ_REMOVE_HEAD_UNTIL(head, elm, field) do { \ + if ((STAILQ_FIRST((head)) = STAILQ_NEXT((elm), field)) == NULL) \ + (head)->stqh_last = &STAILQ_FIRST((head)); \ +} while (0) + +/* + * List declarations. + */ +#define LIST_HEAD(name, type) \ +struct name { \ + struct type *lh_first; /* first element */ \ +} + +#define LIST_HEAD_INITIALIZER(head) \ + { NULL } + +#define LIST_ENTRY(type) \ +struct { \ + struct type *le_next; /* next element */ \ + struct type **le_prev; /* address of previous next element */ \ +} + +/* + * List functions. + */ + +#define LIST_EMPTY(head) ((head)->lh_first == NULL) + +#define LIST_FIRST(head) ((head)->lh_first) + +#define LIST_FOREACH(var, head, field) \ + for ((var) = LIST_FIRST((head)); \ + (var); \ + (var) = LIST_NEXT((var), field)) + +#define LIST_INSERT_BEFORE(listelm, elm, field) do { \ + (elm)->field.le_prev = (listelm)->field.le_prev; \ + LIST_NEXT((elm), field) = (listelm); \ + *(listelm)->field.le_prev = (elm); \ + (listelm)->field.le_prev = &LIST_NEXT((elm), field); \ +} while (0) + +#define LIST_NEXT(elm, field) ((elm)->field.le_next) + +#define TAILQ_FIRST(head) ((head)->tqh_first) + +#define TAILQ_FOREACH(var, head, field) \ + for ((var) = TAILQ_FIRST((head)); \ + (var); \ + (var) = TAILQ_NEXT((var), field)) + +#define TAILQ_NEXT(elm, field) ((elm)->field.tqe_next) + +#define TAILQ_HEAD_INITIALIZER(head) \ + { NULL, &(head).tqh_first } + +#endif + diff --git a/include/bsd/random.h b/include/bsd/random.h new file mode 100644 index 0000000..a20236e --- /dev/null +++ b/include/bsd/random.h @@ -0,0 +1,9 @@ +#ifndef LIBBSD_RANDOM_H +#define LIBBSD_RANDOM_H + +#include + +u_int32_t arc4random(); + +#endif + diff --git a/include/bsd/string.h b/include/bsd/string.h new file mode 100644 index 0000000..ed31933 --- /dev/null +++ b/include/bsd/string.h @@ -0,0 +1,11 @@ +#ifndef LIBBSD_STRING_H +#define LIBBSD_STRING_H + +#include +#include + +size_t strlcpy(char *dst, const char *src, size_t siz); +size_t strlcat(char *dst, const char *src, size_t siz); +char *fgetln(FILE *fp, size_t *lenp); + +#endif diff --git a/md5c.c b/md5c.c index ca10d68..07cba93 100644 --- a/md5c.c +++ b/md5c.c @@ -39,7 +39,7 @@ __FBSDID("$FreeBSD: src/lib/libmd/md5c.c,v 1.16 2003/06/05 13:17:32 markm Exp $" //#include //#include -#include "md5.h" +#include static void MD5Transform(u_int32_t [4], const unsigned char [64]);