diff options
author | Christian Weisgerber <naddy@cvs.openbsd.org> | 2024-04-15 14:30:49 +0000 |
---|---|---|
committer | Christian Weisgerber <naddy@cvs.openbsd.org> | 2024-04-15 14:30:49 +0000 |
commit | 92ffdf62f0c7372c385f5fb5d38a9a95f8ce4d27 (patch) | |
tree | 90b69e2b6bd030412953041d6759df2b462908bb /lib/libc/net | |
parent | 4161c1af9e4927e0422058e0ad35fbf0f555b59e (diff) |
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@
Diffstat (limited to 'lib/libc/net')
-rw-r--r-- | lib/libc/net/Makefile.inc | 15 | ||||
-rw-r--r-- | lib/libc/net/htonl.c | 14 | ||||
-rw-r--r-- | lib/libc/net/htons.c | 14 | ||||
-rw-r--r-- | lib/libc/net/ntohl.c | 14 | ||||
-rw-r--r-- | lib/libc/net/ntohs.c | 14 |
5 files changed, 21 insertions, 50 deletions
diff --git a/lib/libc/net/Makefile.inc b/lib/libc/net/Makefile.inc index 41a3164d6a9..db2c75dad67 100644 --- a/lib/libc/net/Makefile.inc +++ b/lib/libc/net/Makefile.inc @@ -1,7 +1,7 @@ -# $OpenBSD: Makefile.inc,v 1.60 2019/08/30 18:33:17 deraadt Exp $ +# $OpenBSD: Makefile.inc,v 1.61 2024/04/15 14:30:48 naddy Exp $ # net sources -.PATH: ${LIBCSRCDIR}/arch/${MACHINE_CPU}/net ${LIBCSRCDIR}/net +.PATH: ${LIBCSRCDIR}/net CFLAGS+=-DRESOLVSORT @@ -10,10 +10,11 @@ SRCS+= base64.c ethers.c freeaddrinfo.c \ getifaddrs.c getnameinfo.c getnetent.c \ getnetnamadr.c getpeereid.c getproto.c getprotoent.c getprotoname.c \ getservbyname.c getservbyport.c getservent.c getrrsetbyname.c \ - herror.c if_indextoname.c if_nameindex.c if_nametoindex.c inet_addr.c \ + herror.c htonl.c htons.c \ + if_indextoname.c if_nameindex.c if_nametoindex.c inet_addr.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 \ - linkaddr.c rcmd.c rcmdsh.c ruserok.c \ + linkaddr.c ntohl.c ntohs.c rcmd.c rcmdsh.c ruserok.c \ rresvport.c recv.c res_comp.c res_data.c \ res_debug.c res_debug_syms.c res_init.c res_mkquery.c res_query.c \ res_random.c res_send.c \ @@ -22,12 +23,6 @@ SRCS+= base64.c ethers.c freeaddrinfo.c \ # IPv6 SRCS+= ip6opt.c rthdr.c vars6.c -# machine-dependent net sources -# m-d Makefile.inc must include sources for: -# htonl() htons() ntohl() ntohs() - -.include "${LIBCSRCDIR}/arch/${MACHINE_CPU}/net/Makefile.inc" - MAN+= htobe64.3 ether_aton.3 gai_strerror.3 getaddrinfo.3 gethostbyname.3 \ getifaddrs.3 getnameinfo.3 getnetent.3 getpeereid.3 getprotoent.3 \ getrrsetbyname.3 getservent.3 htonl.3 if_indextoname.3 \ diff --git a/lib/libc/net/htonl.c b/lib/libc/net/htonl.c index 6ee6e7efbf3..58bfb4699a7 100644 --- a/lib/libc/net/htonl.c +++ b/lib/libc/net/htonl.c @@ -1,6 +1,5 @@ -/* $OpenBSD: htonl.c,v 1.7 2014/07/21 01:51:10 guenther Exp $ */ +/* $OpenBSD: htonl.c,v 1.8 2024/04/15 14:30:48 naddy Exp $ */ /* - * Written by J.T. Conklin <jtc@netbsd.org>. * Public domain. */ @@ -9,13 +8,8 @@ #undef htonl -u_int32_t -htonl(u_int32_t x) +uint32_t +htonl(uint32_t x) { -#if BYTE_ORDER == LITTLE_ENDIAN - u_char *s = (u_char *)&x; - return (u_int32_t)(s[0] << 24 | s[1] << 16 | s[2] << 8 | s[3]); -#else - return x; -#endif + return htobe32(x); } diff --git a/lib/libc/net/htons.c b/lib/libc/net/htons.c index f48d91ee035..28b13cef986 100644 --- a/lib/libc/net/htons.c +++ b/lib/libc/net/htons.c @@ -1,6 +1,5 @@ -/* $OpenBSD: htons.c,v 1.9 2014/07/21 01:51:10 guenther Exp $ */ +/* $OpenBSD: htons.c,v 1.10 2024/04/15 14:30:48 naddy Exp $ */ /* - * Written by J.T. Conklin <jtc@netbsd.org>. * Public domain. */ @@ -9,13 +8,8 @@ #undef htons -u_int16_t -htons(u_int16_t x) +uint16_t +htons(uint16_t x) { -#if BYTE_ORDER == LITTLE_ENDIAN - u_char *s = (u_char *) &x; - return (u_int16_t)(s[0] << 8 | s[1]); -#else - return x; -#endif + return htobe16(x); } diff --git a/lib/libc/net/ntohl.c b/lib/libc/net/ntohl.c index 0d05bac78a1..7592398e8ca 100644 --- a/lib/libc/net/ntohl.c +++ b/lib/libc/net/ntohl.c @@ -1,6 +1,5 @@ -/* $OpenBSD: ntohl.c,v 1.7 2014/07/21 01:51:10 guenther Exp $ */ +/* $OpenBSD: ntohl.c,v 1.8 2024/04/15 14:30:48 naddy Exp $ */ /* - * Written by J.T. Conklin <jtc@netbsd.org>. * Public domain. */ @@ -9,13 +8,8 @@ #undef ntohl -u_int32_t -ntohl(u_int32_t x) +uint32_t +ntohl(uint32_t x) { -#if BYTE_ORDER == LITTLE_ENDIAN - u_char *s = (u_char *)&x; - return (u_int32_t)(s[0] << 24 | s[1] << 16 | s[2] << 8 | s[3]); -#else - return x; -#endif + return be32toh(x); } diff --git a/lib/libc/net/ntohs.c b/lib/libc/net/ntohs.c index b5ea361f830..ef22ea30680 100644 --- a/lib/libc/net/ntohs.c +++ b/lib/libc/net/ntohs.c @@ -1,6 +1,5 @@ -/* $OpenBSD: ntohs.c,v 1.9 2014/07/21 01:51:10 guenther Exp $ */ +/* $OpenBSD: ntohs.c,v 1.10 2024/04/15 14:30:48 naddy Exp $ */ /* - * Written by J.T. Conklin <jtc@netbsd.org>. * Public domain. */ @@ -9,13 +8,8 @@ #undef ntohs -u_int16_t -ntohs(u_int16_t x) +uint16_t +ntohs(uint16_t x) { -#if BYTE_ORDER == LITTLE_ENDIAN - u_char *s = (u_char *) &x; - return (u_int16_t)(s[0] << 8 | s[1]); -#else - return x; -#endif + return be16toh(x); } |