summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornaddy <>2024-04-15 14:30:48 +0000
committernaddy <>2024-04-15 14:30:48 +0000
commitf7646eb021595fb6f85c38b99e043277fa2436bc (patch)
tree161adc5a1fbde78ccfb6b293bd0da5239b8b5045
parent22372f5970deb0d15444f4ce803b5a44934b22e5 (diff)
downloadopenbsd-f7646eb021595fb6f85c38b99e043277fa2436bc.tar.gz
openbsd-f7646eb021595fb6f85c38b99e043277fa2436bc.tar.bz2
openbsd-f7646eb021595fb6f85c38b99e043277fa2436bc.zip
drop htonl(), htons(), ntohl(), ntohs() MD functions from libc
Userland code compiled in a normal fashion picks up the htonl(), htons(), ntohl(), ntohs() macros implemented by endian.h. The functions in libc are effectively unused. Keep the MI functions in case something looks for the symbols in libc or plays games with #undef, but change them to wrap the implementation from endian.h. tweaks suggested by claudio@, ok miod@
-rw-r--r--src/lib/libc/net/Makefile.inc15
-rw-r--r--src/lib/libc/net/htonl.c14
-rw-r--r--src/lib/libc/net/htons.c14
-rw-r--r--src/lib/libc/net/ntohl.c14
-rw-r--r--src/lib/libc/net/ntohs.c14
5 files changed, 21 insertions, 50 deletions
diff --git a/src/lib/libc/net/Makefile.inc b/src/lib/libc/net/Makefile.inc
index 41a3164d6a..db2c75dad6 100644
--- a/src/lib/libc/net/Makefile.inc
+++ b/src/lib/libc/net/Makefile.inc
@@ -1,7 +1,7 @@
1# $OpenBSD: Makefile.inc,v 1.60 2019/08/30 18:33:17 deraadt Exp $ 1# $OpenBSD: Makefile.inc,v 1.61 2024/04/15 14:30:48 naddy Exp $
2 2
3# net sources 3# net sources
4.PATH: ${LIBCSRCDIR}/arch/${MACHINE_CPU}/net ${LIBCSRCDIR}/net 4.PATH: ${LIBCSRCDIR}/net
5 5
6CFLAGS+=-DRESOLVSORT 6CFLAGS+=-DRESOLVSORT
7 7
@@ -10,10 +10,11 @@ SRCS+= base64.c ethers.c freeaddrinfo.c \
10 getifaddrs.c getnameinfo.c getnetent.c \ 10 getifaddrs.c getnameinfo.c getnetent.c \
11 getnetnamadr.c getpeereid.c getproto.c getprotoent.c getprotoname.c \ 11 getnetnamadr.c getpeereid.c getproto.c getprotoent.c getprotoname.c \
12 getservbyname.c getservbyport.c getservent.c getrrsetbyname.c \ 12 getservbyname.c getservbyport.c getservent.c getrrsetbyname.c \
13 herror.c if_indextoname.c if_nameindex.c if_nametoindex.c inet_addr.c \ 13 herror.c htonl.c htons.c \
14 if_indextoname.c if_nameindex.c if_nametoindex.c inet_addr.c \
14 inet_lnaof.c inet_makeaddr.c inet_neta.c inet_netof.c inet_network.c \ 15 inet_lnaof.c inet_makeaddr.c inet_neta.c inet_netof.c inet_network.c \
15 inet_net_ntop.c inet_net_pton.c inet_ntoa.c inet_ntop.c inet_pton.c \ 16 inet_net_ntop.c inet_net_pton.c inet_ntoa.c inet_ntop.c inet_pton.c \
16 linkaddr.c rcmd.c rcmdsh.c ruserok.c \ 17 linkaddr.c ntohl.c ntohs.c rcmd.c rcmdsh.c ruserok.c \
17 rresvport.c recv.c res_comp.c res_data.c \ 18 rresvport.c recv.c res_comp.c res_data.c \
18 res_debug.c res_debug_syms.c res_init.c res_mkquery.c res_query.c \ 19 res_debug.c res_debug_syms.c res_init.c res_mkquery.c res_query.c \
19 res_random.c res_send.c \ 20 res_random.c res_send.c \
@@ -22,12 +23,6 @@ SRCS+= base64.c ethers.c freeaddrinfo.c \
22# IPv6 23# IPv6
23SRCS+= ip6opt.c rthdr.c vars6.c 24SRCS+= ip6opt.c rthdr.c vars6.c
24 25
25# machine-dependent net sources
26# m-d Makefile.inc must include sources for:
27# htonl() htons() ntohl() ntohs()
28
29.include "${LIBCSRCDIR}/arch/${MACHINE_CPU}/net/Makefile.inc"
30
31MAN+= htobe64.3 ether_aton.3 gai_strerror.3 getaddrinfo.3 gethostbyname.3 \ 26MAN+= htobe64.3 ether_aton.3 gai_strerror.3 getaddrinfo.3 gethostbyname.3 \
32 getifaddrs.3 getnameinfo.3 getnetent.3 getpeereid.3 getprotoent.3 \ 27 getifaddrs.3 getnameinfo.3 getnetent.3 getpeereid.3 getprotoent.3 \
33 getrrsetbyname.3 getservent.3 htonl.3 if_indextoname.3 \ 28 getrrsetbyname.3 getservent.3 htonl.3 if_indextoname.3 \
diff --git a/src/lib/libc/net/htonl.c b/src/lib/libc/net/htonl.c
index 6ee6e7efbf..58bfb4699a 100644
--- a/src/lib/libc/net/htonl.c
+++ b/src/lib/libc/net/htonl.c
@@ -1,6 +1,5 @@
1/* $OpenBSD: htonl.c,v 1.7 2014/07/21 01:51:10 guenther Exp $ */ 1/* $OpenBSD: htonl.c,v 1.8 2024/04/15 14:30:48 naddy Exp $ */
2/* 2/*
3 * Written by J.T. Conklin <jtc@netbsd.org>.
4 * Public domain. 3 * Public domain.
5 */ 4 */
6 5
@@ -9,13 +8,8 @@
9 8
10#undef htonl 9#undef htonl
11 10
12u_int32_t 11uint32_t
13htonl(u_int32_t x) 12htonl(uint32_t x)
14{ 13{
15#if BYTE_ORDER == LITTLE_ENDIAN 14 return htobe32(x);
16 u_char *s = (u_char *)&x;
17 return (u_int32_t)(s[0] << 24 | s[1] << 16 | s[2] << 8 | s[3]);
18#else
19 return x;
20#endif
21} 15}
diff --git a/src/lib/libc/net/htons.c b/src/lib/libc/net/htons.c
index f48d91ee03..28b13cef98 100644
--- a/src/lib/libc/net/htons.c
+++ b/src/lib/libc/net/htons.c
@@ -1,6 +1,5 @@
1/* $OpenBSD: htons.c,v 1.9 2014/07/21 01:51:10 guenther Exp $ */ 1/* $OpenBSD: htons.c,v 1.10 2024/04/15 14:30:48 naddy Exp $ */
2/* 2/*
3 * Written by J.T. Conklin <jtc@netbsd.org>.
4 * Public domain. 3 * Public domain.
5 */ 4 */
6 5
@@ -9,13 +8,8 @@
9 8
10#undef htons 9#undef htons
11 10
12u_int16_t 11uint16_t
13htons(u_int16_t x) 12htons(uint16_t x)
14{ 13{
15#if BYTE_ORDER == LITTLE_ENDIAN 14 return htobe16(x);
16 u_char *s = (u_char *) &x;
17 return (u_int16_t)(s[0] << 8 | s[1]);
18#else
19 return x;
20#endif
21} 15}
diff --git a/src/lib/libc/net/ntohl.c b/src/lib/libc/net/ntohl.c
index 0d05bac78a..7592398e8c 100644
--- a/src/lib/libc/net/ntohl.c
+++ b/src/lib/libc/net/ntohl.c
@@ -1,6 +1,5 @@
1/* $OpenBSD: ntohl.c,v 1.7 2014/07/21 01:51:10 guenther Exp $ */ 1/* $OpenBSD: ntohl.c,v 1.8 2024/04/15 14:30:48 naddy Exp $ */
2/* 2/*
3 * Written by J.T. Conklin <jtc@netbsd.org>.
4 * Public domain. 3 * Public domain.
5 */ 4 */
6 5
@@ -9,13 +8,8 @@
9 8
10#undef ntohl 9#undef ntohl
11 10
12u_int32_t 11uint32_t
13ntohl(u_int32_t x) 12ntohl(uint32_t x)
14{ 13{
15#if BYTE_ORDER == LITTLE_ENDIAN 14 return be32toh(x);
16 u_char *s = (u_char *)&x;
17 return (u_int32_t)(s[0] << 24 | s[1] << 16 | s[2] << 8 | s[3]);
18#else
19 return x;
20#endif
21} 15}
diff --git a/src/lib/libc/net/ntohs.c b/src/lib/libc/net/ntohs.c
index b5ea361f83..ef22ea3068 100644
--- a/src/lib/libc/net/ntohs.c
+++ b/src/lib/libc/net/ntohs.c
@@ -1,6 +1,5 @@
1/* $OpenBSD: ntohs.c,v 1.9 2014/07/21 01:51:10 guenther Exp $ */ 1/* $OpenBSD: ntohs.c,v 1.10 2024/04/15 14:30:48 naddy Exp $ */
2/* 2/*
3 * Written by J.T. Conklin <jtc@netbsd.org>.
4 * Public domain. 3 * Public domain.
5 */ 4 */
6 5
@@ -9,13 +8,8 @@
9 8
10#undef ntohs 9#undef ntohs
11 10
12u_int16_t 11uint16_t
13ntohs(u_int16_t x) 12ntohs(uint16_t x)
14{ 13{
15#if BYTE_ORDER == LITTLE_ENDIAN 14 return be16toh(x);
16 u_char *s = (u_char *) &x;
17 return (u_int16_t)(s[0] << 8 | s[1]);
18#else
19 return x;
20#endif
21} 15}