diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 1999-06-23 22:17:33 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 1999-06-23 22:17:33 +0000 |
commit | f56f53c383ffaedfe8b92e03e3ae6a221477ad1d (patch) | |
tree | 82146f971849412998913842d78b6cc01557366c /lib/libc/net | |
parent | 94cb0cb5a0a4a74038cd87166c4703feee3ffd27 (diff) |
net_addrcmp(); needs man page
Diffstat (limited to 'lib/libc/net')
-rw-r--r-- | lib/libc/net/Makefile.inc | 6 | ||||
-rw-r--r-- | lib/libc/net/net_addrcmp.c | 37 |
2 files changed, 41 insertions, 2 deletions
diff --git a/lib/libc/net/Makefile.inc b/lib/libc/net/Makefile.inc index b4b94ad763d..3727045c1d8 100644 --- a/lib/libc/net/Makefile.inc +++ b/lib/libc/net/Makefile.inc @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile.inc,v 1.18 1999/06/23 21:55:28 cmetz Exp $ +# $OpenBSD: Makefile.inc,v 1.19 1999/06/23 22:17:32 deraadt Exp $ # net sources .PATH: ${LIBCSRCDIR}/arch/${MACHINE_ARCH}/net ${LIBCSRCDIR}/net @@ -13,7 +13,9 @@ SRCS+= __siocgifconf.c base64.c freeaddrinfo.c gai_strerror.c getaddrinfo.c \ inet_lnaof.c inet_makeaddr.c inet_neta.c inet_netof.c inet_network.c \ inet_net_ntop.c inet_net_pton.c inet_ntoa.c inet_ntop.c inet_pton.c \ ipx_addr.c ipx_ntoa.c iso_addr.c linkaddr.c ns_addr.c ns_ntoa.c \ - nsap_addr.c rcmd.c recv.c res_comp.c res_data.c res_debug.c \ + nsap_addr.c \ + net_addrcmp.c \ + rcmd.c recv.c res_comp.c res_data.c res_debug.c \ res_init.c res_mkquery.c res_query.c res_random.c res_send.c send.c \ sethostent.c ethers.c rcmdsh.c diff --git a/lib/libc/net/net_addrcmp.c b/lib/libc/net/net_addrcmp.c new file mode 100644 index 00000000000..003b2567e91 --- /dev/null +++ b/lib/libc/net/net_addrcmp.c @@ -0,0 +1,37 @@ +#include <sys/types.h> +#include <sys/socket.h> +#include <sys/un.h> +#include <netinet/in.h> +#include <netns/ns.h> +#include <string.h> + +int +net_addrcmp(sa1, sa2) + struct sockaddr *sa1; + struct sockaddr *sa2; +{ + if (sa1->sa_len != sa2->sa_len) + return (sa1->sa_len < sa2->sa_len) ? -1 : 1; + if (sa1->sa_family != sa2->sa_family) + return (sa1->sa_family < sa2->sa_family) ? -1 : 1; + + switch(sa1->sa_family) { + case AF_INET: + return (memcmp(&((struct sockaddr_in *)sa1)->sin_addr, + &((struct sockaddr_in *)sa2)->sin_addr, + sizeof(struct in_addr))); + case AF_INET6: + return (memcmp(&((struct sockaddr_in6 *)sa1)->sin6_addr, + &((struct sockaddr_in6 *)sa2)->sin6_addr, + sizeof(struct in6_addr))); + case AF_NS: + return (memcmp(&((struct sockaddr_ns *)sa1)->sns_addr, + &((struct sockaddr_ns *)sa2)->sns_addr, + sizeof(struct ns_addr))); + case AF_UNIX: + return (strcmp(((struct sockaddr_un *)sa1)->sun_path, + ((struct sockaddr_un *)sa1)->sun_path)); + default: + return -1; + } +} |