diff options
author | Peter Elliott <pelliott@ualberta.ca> | 2021-07-23 16:07:46 -0600 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-08-22 10:29:06 +0200 |
commit | db92e66902c691ca0d5dff8ec91e41c63149dc36 (patch) | |
tree | d77c38d8420f8752cdb873399874bb17d1796a52 | |
parent | f16aba405f68ad27f2e1188547d34e894978c608 (diff) | |
download | serenity-db92e66902c691ca0d5dff8ec91e41c63149dc36.zip |
LibC: Make <netinet/in.h> more POSIX compliant
1. Move htonl() etc. from <arpa/inet.h> to <netinet/in.h> (which
<arpa/inet.h> includes).
The htonl(), htons(), ntohl(), and ntohs() functions shall be
available as described in <arpa/inet.h>. Inclusion of the
<netinet/in.h> header may also make visible all symbols from
<arpa/inet.h>.
- POSIX
2. Define IN6_IS_ADDR_LOOPBACK() and IN6_IS_ADDR_V4MAPPED()
-rw-r--r-- | Userland/Libraries/LibC/arpa/inet.h | 29 | ||||
-rw-r--r-- | Userland/Libraries/LibC/netinet/in.h | 35 |
2 files changed, 35 insertions, 29 deletions
diff --git a/Userland/Libraries/LibC/arpa/inet.h b/Userland/Libraries/LibC/arpa/inet.h index 44200357d0..3ba673731f 100644 --- a/Userland/Libraries/LibC/arpa/inet.h +++ b/Userland/Libraries/LibC/arpa/inet.h @@ -6,7 +6,6 @@ #pragma once -#include <endian.h> #include <inttypes.h> #include <netinet/in.h> #include <sys/cdefs.h> @@ -27,32 +26,4 @@ static inline int inet_aton(const char* cp, struct in_addr* inp) char* inet_ntoa(struct in_addr); -static inline uint16_t htons(uint16_t value) -{ -#if __BYTE_ORDER == __LITTLE_ENDIAN - return __builtin_bswap16(value); -#else - return value; -#endif -} - -static inline uint16_t ntohs(uint16_t value) -{ - return htons(value); -} - -static inline uint32_t htonl(uint32_t value) -{ -#if __BYTE_ORDER == __LITTLE_ENDIAN - return __builtin_bswap32(value); -#else - return value; -#endif -} - -static inline uint32_t ntohl(uint32_t value) -{ - return htonl(value); -} - __END_DECLS diff --git a/Userland/Libraries/LibC/netinet/in.h b/Userland/Libraries/LibC/netinet/in.h index 6d389892dd..7be4b579a6 100644 --- a/Userland/Libraries/LibC/netinet/in.h +++ b/Userland/Libraries/LibC/netinet/in.h @@ -7,9 +7,44 @@ #pragma once #include <Kernel/API/POSIX/netinet/in.h> +#include <endian.h> __BEGIN_DECLS in_addr_t inet_addr(char const*); +static inline uint16_t htons(uint16_t value) +{ +#if __BYTE_ORDER == __LITTLE_ENDIAN + return __builtin_bswap16(value); +#else + return value; +#endif +} + +static inline uint16_t ntohs(uint16_t value) +{ + return htons(value); +} + +static inline uint32_t htonl(uint32_t value) +{ +#if __BYTE_ORDER == __LITTLE_ENDIAN + return __builtin_bswap32(value); +#else + return value; +#endif +} + +static inline uint32_t ntohl(uint32_t value) +{ + return htonl(value); +} + +#define IN6_IS_ADDR_LOOPBACK(addr) \ + (addr->s6_addr[0] == 0 && addr->s6_addr[1] == 0 && addr->s6_addr[2] == 0 && addr->s6_addr[3] == 0 && addr->s6_addr[4] == 0 && addr->s6_addr[5] == 0 && addr->s6_addr[6] == 0 && addr->s6_addr[7] == 0 && addr->s6_addr[8] == 0 && addr->s6_addr[9] == 0 && addr->s6_addr[10] == 0 && addr->s6_addr[11] == 0 && addr->s6_addr[12] == 0 && addr->s6_addr[13] == 0 && addr->s6_addr[14] == 0 && addr->s6_addr[15] == 1) + +#define IN6_IS_ADDR_V4MAPPED(addr) \ + (addr->s6_addr[0] == 0 && addr->s6_addr[1] == 0 && addr->s6_addr[2] == 0 && addr->s6_addr[3] == 0 && addr->s6_addr[4] == 0 && addr->s6_addr[5] == 0 && addr->s6_addr[6] == 0 && addr->s6_addr[7] == 0 && addr->s6_addr[8] == 0xff && addr->s6_addr[9] == 0xff && addr->s6_addr[10] == 0xff && addr->s6_addr[11] == 0xff) + __END_DECLS |