Commit 5c02d318 authored by Michael Graff's avatar Michael Graff
Browse files

add isc_sockaddr_equal()

parent b456d806
......@@ -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
......
......@@ -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 */
......@@ -19,6 +19,7 @@
#define ISC_TYPES_H 1
#include <isc/int.h>
#include <isc/boolean.h>
#include <isc/list.h>
/***
......
/*
* 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 <config.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <isc/types.h>
#include <isc/assertions.h>
#include <isc/error.h>
#include <isc/sockaddr.h>
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);
}
......@@ -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}
......
......@@ -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 */
/*
* 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 <config.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <isc/types.h>
#include <isc/assertions.h>
#include <isc/error.h>
#include <isc/sockaddr.h>
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);
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment