summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorderaadt <>2012-01-17 02:33:20 +0000
committerderaadt <>2012-01-17 02:33:20 +0000
commitefaeb5589cc66ce5e81f0b91547c67428ad04ed5 (patch)
tree5090bba1dda56e8f957fd1c71b693d6b9f9b9642
parent63acf152ffa3695a60c6ec29545c5c9a7d6f1148 (diff)
downloadopenbsd-efaeb5589cc66ce5e81f0b91547c67428ad04ed5.tar.gz
openbsd-efaeb5589cc66ce5e81f0b91547c67428ad04ed5.tar.bz2
openbsd-efaeb5589cc66ce5e81f0b91547c67428ad04ed5.zip
net_addrcmp() dies. found out to be a horrific function by eric
ok guenther
-rw-r--r--src/lib/libc/net/Makefile.inc7
-rw-r--r--src/lib/libc/net/net_addrcmp.391
-rw-r--r--src/lib/libc/net/net_addrcmp.c63
3 files changed, 3 insertions, 158 deletions
diff --git a/src/lib/libc/net/Makefile.inc b/src/lib/libc/net/Makefile.inc
index 530bc3f3f0..48279d2423 100644
--- a/src/lib/libc/net/Makefile.inc
+++ b/src/lib/libc/net/Makefile.inc
@@ -1,4 +1,4 @@
1# $OpenBSD: Makefile.inc,v 1.48 2010/07/01 19:15:30 deraadt Exp $ 1# $OpenBSD: Makefile.inc,v 1.49 2012/01/17 02:33:20 deraadt Exp $
2 2
3# net sources 3# net sources
4.PATH: ${LIBCSRCDIR}/arch/${MACHINE_CPU}/net ${LIBCSRCDIR}/net 4.PATH: ${LIBCSRCDIR}/arch/${MACHINE_CPU}/net ${LIBCSRCDIR}/net
@@ -12,7 +12,7 @@ SRCS+= base64.c freeaddrinfo.c gai_strerror.c getaddrinfo.c gethostnamadr.c \
12 herror.c if_indextoname.c if_nameindex.c if_nametoindex.c inet_addr.c \ 12 herror.c if_indextoname.c if_nameindex.c if_nametoindex.c inet_addr.c \
13 inet_lnaof.c inet_makeaddr.c inet_neta.c inet_netof.c inet_network.c \ 13 inet_lnaof.c inet_makeaddr.c inet_neta.c inet_netof.c inet_network.c \
14 inet_net_ntop.c inet_net_pton.c inet_ntoa.c inet_ntop.c inet_pton.c \ 14 inet_net_ntop.c inet_net_pton.c inet_ntoa.c inet_ntop.c inet_pton.c \
15 linkaddr.c net_addrcmp.c nsap_addr.c \ 15 linkaddr.c nsap_addr.c \
16 rcmd.c ruserok.c rresvport.c recv.c res_comp.c res_data.c res_debug.c \ 16 rcmd.c ruserok.c rresvport.c recv.c res_comp.c res_data.c res_debug.c \
17 res_debug_syms.c \ 17 res_debug_syms.c \
18 res_init.c res_mkquery.c res_query.c res_random.c res_send.c send.c \ 18 res_init.c res_mkquery.c res_query.c res_random.c res_send.c send.c \
@@ -31,8 +31,7 @@ MAN+= byteorder.3 ethers.3 gai_strerror.3 getaddrinfo.3 gethostbyname.3 \
31 getifaddrs.3 getnameinfo.3 getnetent.3 getpeereid.3 getprotoent.3 \ 31 getifaddrs.3 getnameinfo.3 getnetent.3 getpeereid.3 getprotoent.3 \
32 getrrsetbyname.3 getservent.3 if_indextoname.3 inet.3 \ 32 getrrsetbyname.3 getservent.3 if_indextoname.3 inet.3 \
33 inet_net.3 inet6_option_space.3 inet6_rthdr_space.3 \ 33 inet_net.3 inet6_option_space.3 inet6_rthdr_space.3 \
34 inet6_opt_init.3 inet6_rth_space.3 \ 34 inet6_opt_init.3 inet6_rth_space.3 link_addr.3 \
35 link_addr.3 net_addrcmp.3 \
36 rcmd.3 rcmdsh.3 resolver.3 35 rcmd.3 rcmdsh.3 resolver.3
37 36
38MLINKS+=byteorder.3 htonl.3 byteorder.3 htons.3 byteorder.3 ntohl.3 \ 37MLINKS+=byteorder.3 htonl.3 byteorder.3 htons.3 byteorder.3 ntohl.3 \
diff --git a/src/lib/libc/net/net_addrcmp.3 b/src/lib/libc/net/net_addrcmp.3
deleted file mode 100644
index a02e6e2619..0000000000
--- a/src/lib/libc/net/net_addrcmp.3
+++ /dev/null
@@ -1,91 +0,0 @@
1.\" $OpenBSD: net_addrcmp.3,v 1.4 2007/05/31 19:19:30 jmc Exp $
2.\"
3.\" Copyright (c) 1999 Theo de Raadt
4.\"
5.\" Redistribution and use in source and binary forms, with or without
6.\" modification, are permitted provided that the following conditions
7.\" are met:
8.\" 1. Redistributions of source code must retain the above copyright
9.\" notice, this list of conditions and the following disclaimer.
10.\" 2. Redistributions in binary form must reproduce the above copyright
11.\" notice, this list of conditions and the following disclaimer in the
12.\" documentation and/or other materials provided with the distribution.
13.\"
14.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
15.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
18.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24.\"
25.Dd $Mdocdate: May 31 2007 $
26.Dt NET_ADDRCMP 3
27.Os
28.Sh NAME
29.Nm net_addrcmp
30.Nd compare socket address structures
31.Sh SYNOPSIS
32.Fd #include <netdb.h>
33.Ft int
34.Fn net_addrcmp "struct sockaddr *sa1" "struct sockaddr *sa2"
35.Sh DESCRIPTION
36The
37.Fn net_addrcmp
38function compares two socket address structures,
39.Fa sa1
40and
41.Fa sa2 .
42.Sh RETURN VALUES
43If
44.Fa sa1
45and
46.Fa sa2
47are for the same address,
48.Fn net_addrcmp
49returns 0.
50.Pp
51The
52.Fa sa_len
53fields are compared first.
54If they do not match,
55.Fn net_addrcmp
56returns \-1 or 1 if
57.Li sa1->sa_len
58is less than or greater than
59.Li sa2->sa_len ,
60respectively.
61.Pp
62Next, the
63.Fa sa_family
64members are compared.
65If they do not match,
66.Fn net_addrcmp
67returns \-1 or 1 if
68.Li sa1->sa_family
69is less than or greater than
70.Li sa2->sa_family ,
71respectively.
72.Pp
73Lastly, if each socket address structure's
74.Fa sa_len
75and
76.Fa sa_family
77fields match,
78the protocol-specific data (the
79.Fa sa_data
80field) is compared.
81If there's a match, both
82.Fa sa1
83and
84.Fa sa2
85must refer to the same address, and 0 is returned; otherwise, a value >0
86or <0 is returned.
87.Sh HISTORY
88A
89.Fn net_addrcmp
90function was added in
91.Ox 2.5 .
diff --git a/src/lib/libc/net/net_addrcmp.c b/src/lib/libc/net/net_addrcmp.c
deleted file mode 100644
index c2630a5265..0000000000
--- a/src/lib/libc/net/net_addrcmp.c
+++ /dev/null
@@ -1,63 +0,0 @@
1/* $OpenBSD: net_addrcmp.c,v 1.10 2005/06/17 20:36:16 henning Exp $ */
2
3/*
4 * Copyright (c) 1999 Theo de Raadt
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28#include <sys/types.h>
29#include <sys/socket.h>
30#include <sys/un.h>
31#include <netinet/in.h>
32#include <string.h>
33
34int
35net_addrcmp(struct sockaddr *sa1, struct sockaddr *sa2)
36{
37
38 if (sa1->sa_len != sa2->sa_len)
39 return (sa1->sa_len < sa2->sa_len) ? -1 : 1;
40 if (sa1->sa_family != sa2->sa_family)
41 return (sa1->sa_family < sa2->sa_family) ? -1 : 1;
42
43 switch(sa1->sa_family) {
44 case AF_INET:
45 return (memcmp(&((struct sockaddr_in *)sa1)->sin_addr,
46 &((struct sockaddr_in *)sa2)->sin_addr,
47 sizeof(struct in_addr)));
48 case AF_INET6:
49 if (((struct sockaddr_in6 *)sa1)->sin6_scope_id !=
50 ((struct sockaddr_in6 *)sa2)->sin6_scope_id)
51 return (((struct sockaddr_in6 *)sa1)->sin6_scope_id <
52 ((struct sockaddr_in6 *)sa2)->sin6_scope_id)
53 ? -1 : 1;
54 return memcmp(&((struct sockaddr_in6 *)sa1)->sin6_addr,
55 &((struct sockaddr_in6 *)sa2)->sin6_addr,
56 sizeof(struct in6_addr));
57 case AF_LOCAL:
58 return (strcmp(((struct sockaddr_un *)sa1)->sun_path,
59 ((struct sockaddr_un *)sa1)->sun_path));
60 default:
61 return -1;
62 }
63}