diff --git a/lib/isc/Makefile.in b/lib/isc/Makefile.in index 4bc9f02773..53f7545adc 100644 --- a/lib/isc/Makefile.in +++ b/lib/isc/Makefile.in @@ -25,12 +25,18 @@ CINCLUDES = -I${srcdir}/unix/include \ CDEFINES = CWARNINGS = +UNIXOBJS = unix/app.o unix/time.o unix/stdtime.o unix/socket.o \ + unix/interfaceiter.o unix/sockaddr.o + +NLSOBJS = nls/msgcat.o + +PTHREADOBJS = pthreads/condition.o + OBJS = @ISC_EXTRA_OBJS@ \ assertions.o base64.o buffer.o error.o heap.o lex.o lib.o \ mem.o result.o rwlock.o symtab.o str.o event.o task.o timer.o \ version.o \ - unix/app.o unix/time.o unix/stdtime.o unix/socket.o \ - unix/interfaceiter.o nls/msgcat.o pthreads/condition.o + ${UNIXOBJS} ${NLSOBJS} ${PTHREADOBJS} SUBDIRS = include unix nls pthreads TARGETS = timestamp diff --git a/lib/isc/include/isc/sockaddr.h b/lib/isc/include/isc/sockaddr.h index 4766aae8f2..13fdc9238a 100644 --- a/lib/isc/include/isc/sockaddr.h +++ b/lib/isc/include/isc/sockaddr.h @@ -36,6 +36,9 @@ typedef struct isc_sockaddr { } type; } isc_sockaddr_t; +isc_boolean_t +isc_sockaddr_equal(isc_sockaddr_t *, isc_sockaddr_t *); + ISC_LANG_ENDDECLS #endif /* ISC_SOCKADDR_H */ diff --git a/lib/isc/include/isc/types.h b/lib/isc/include/isc/types.h index 5496b6e09c..b8cdc2afd2 100644 --- a/lib/isc/include/isc/types.h +++ b/lib/isc/include/isc/types.h @@ -19,6 +19,7 @@ #define ISC_TYPES_H 1 #include +#include #include /*** diff --git a/lib/isc/sockaddr.c b/lib/isc/sockaddr.c new file mode 100644 index 0000000000..4515c17af9 --- /dev/null +++ b/lib/isc/sockaddr.c @@ -0,0 +1,73 @@ +/* + * Copyright (C) 1999 Internet Software Consortium. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS + * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE + * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL + * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR + * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS + * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS + * SOFTWARE. + */ + +#include + +#include +#include +#include +#include + +#include +#include + +#include +#include +#include +#include + +isc_boolean_t +isc_sockaddr_equal(isc_sockaddr_t *a, isc_sockaddr_t *b) +{ + struct sockaddr *sa, *sb; + + sa = (struct sockaddr *)&a->type; + sb = (struct sockaddr *)&b->type; + + if (sa->sa_family != sb->sa_family) + return (ISC_FALSE); + +#ifdef HAVE_SA_LEN + if (sa->sa_len != sb->sa_len) + return (ISC_FALSE); + if (memcmp(sa->sa_data, sb->sa_data, sa->sa_len) != 0) + return (ISC_FALSE); +#else + switch (sa->sa_family) { + case AF_INET: { + struct sockaddr_in *sina, *sinb; + + sina = (struct sockaddr_in)sa; + sinb = (struct sockaddr_in)sb; + + if (sina->sin_port != sinb->sin_port) + return (ISC_FALSE); + if (memcmp(&sina->sin_addr, &sinb->sin_addr, 4) != 0) + return (ISC_FALSE); + + return (ISC_TRUE); + } + default: + INSIST("Unknown socket protocol"); + break; + } + +#endif + + UNEXPECTED_ERROR(__FILE__, __LINE__, "Cannot happen"); + return (ISC_FALSE); +} diff --git a/lib/isc/unix/Makefile.in b/lib/isc/unix/Makefile.in index 7f534e12b6..e392d2a85f 100644 --- a/lib/isc/unix/Makefile.in +++ b/lib/isc/unix/Makefile.in @@ -24,7 +24,7 @@ CINCLUDES = -I${srcdir}/.. \ CDEFINES = CWARNINGS = -OBJS = app.o time.o stdtime.o socket.o interfaceiter.o +OBJS = app.o time.o stdtime.o socket.o interfaceiter.o sockaddr.o SUBDIRS = include TARGETS = ${OBJS} diff --git a/lib/isc/unix/include/isc/sockaddr.h b/lib/isc/unix/include/isc/sockaddr.h index 4766aae8f2..13fdc9238a 100644 --- a/lib/isc/unix/include/isc/sockaddr.h +++ b/lib/isc/unix/include/isc/sockaddr.h @@ -36,6 +36,9 @@ typedef struct isc_sockaddr { } type; } isc_sockaddr_t; +isc_boolean_t +isc_sockaddr_equal(isc_sockaddr_t *, isc_sockaddr_t *); + ISC_LANG_ENDDECLS #endif /* ISC_SOCKADDR_H */ diff --git a/lib/isc/unix/sockaddr.c b/lib/isc/unix/sockaddr.c new file mode 100644 index 0000000000..4515c17af9 --- /dev/null +++ b/lib/isc/unix/sockaddr.c @@ -0,0 +1,73 @@ +/* + * Copyright (C) 1999 Internet Software Consortium. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS + * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE + * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL + * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR + * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS + * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS + * SOFTWARE. + */ + +#include + +#include +#include +#include +#include + +#include +#include + +#include +#include +#include +#include + +isc_boolean_t +isc_sockaddr_equal(isc_sockaddr_t *a, isc_sockaddr_t *b) +{ + struct sockaddr *sa, *sb; + + sa = (struct sockaddr *)&a->type; + sb = (struct sockaddr *)&b->type; + + if (sa->sa_family != sb->sa_family) + return (ISC_FALSE); + +#ifdef HAVE_SA_LEN + if (sa->sa_len != sb->sa_len) + return (ISC_FALSE); + if (memcmp(sa->sa_data, sb->sa_data, sa->sa_len) != 0) + return (ISC_FALSE); +#else + switch (sa->sa_family) { + case AF_INET: { + struct sockaddr_in *sina, *sinb; + + sina = (struct sockaddr_in)sa; + sinb = (struct sockaddr_in)sb; + + if (sina->sin_port != sinb->sin_port) + return (ISC_FALSE); + if (memcmp(&sina->sin_addr, &sinb->sin_addr, 4) != 0) + return (ISC_FALSE); + + return (ISC_TRUE); + } + default: + INSIST("Unknown socket protocol"); + break; + } + +#endif + + UNEXPECTED_ERROR(__FILE__, __LINE__, "Cannot happen"); + return (ISC_FALSE); +}