From fdf325c7e3b96db9e732079e17393ef97320c58d Mon Sep 17 00:00:00 2001 From: "chao.an" Date: Mon, 7 Jun 2021 11:04:49 +0800 Subject: [PATCH] netinet: move the byte ordering convert functions to "netinet/in.h" Signed-off-by: chao.an --- include/arpa/inet.h | 48 -------------------------------------------- include/netinet/in.h | 44 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 48 deletions(-) diff --git a/include/arpa/inet.h b/include/arpa/inet.h index ae46379bb7..ef4c54b94a 100644 --- a/include/arpa/inet.h +++ b/include/arpa/inet.h @@ -31,38 +31,6 @@ #include #include -/**************************************************************************** - * Public Type Definitions - ****************************************************************************/ - -/* This macro to convert a 16/32-bit constant values quantity from host byte - * order to network byte order. The 16-bit version of this macro is required - * for uIP: - * - * Author Adam Dunkels - * Copyright (c) 2001-2003, Adam Dunkels. - * All rights reserved. - */ - -#ifdef CONFIG_ENDIAN_BIG -# define HTONS(ns) (ns) -# define HTONL(nl) (nl) -#else -# define HTONS(ns) \ - (unsigned short) \ - (((((unsigned short)(ns)) & 0x00ff) << 8) | \ - ((((unsigned short)(ns)) >> 8) & 0x00ff)) -# define HTONL(nl) \ - (unsigned long) \ - (((((unsigned long)(nl)) & 0x000000ffUL) << 24) | \ - ((((unsigned long)(nl)) & 0x0000ff00UL) << 8) | \ - ((((unsigned long)(nl)) & 0x00ff0000UL) >> 8) | \ - ((((unsigned long)(nl)) & 0xff000000UL) >> 24)) -#endif - -#define NTOHS(hs) HTONS(hs) -#define NTOHL(hl) HTONL(hl) - /**************************************************************************** * Public Function Prototypes ****************************************************************************/ @@ -75,22 +43,6 @@ extern "C" #define EXTERN extern #endif -/* Functions to convert between host and network byte ordering. - * - * REVISIT: Since network order is defined as big-endian, the following - * functions are equivalent to functions declared in endian.h: - * - * htonl htobe32 - * htons htobe16 - * ntohl be32toh - * ntohs be16toh - */ - -uint32_t ntohl(uint32_t nl); -uint16_t ntohs(uint16_t ns); -uint32_t htonl(uint32_t hl); -uint16_t htons(uint16_t hs); - /* Functions to manipulate address representations */ int inet_aton(FAR const char *cp, FAR struct in_addr *inp); diff --git a/include/netinet/in.h b/include/netinet/in.h index 06bfb4008c..be38111862 100644 --- a/include/netinet/in.h +++ b/include/netinet/in.h @@ -189,6 +189,34 @@ (a)->s6_addr32[1] == 0 && \ (a)->s6_addr32[2] == HTONL(0xffff)) +/* This macro to convert a 16/32-bit constant values quantity from host byte + * order to network byte order. The 16-bit version of this macro is required + * for uIP: + * + * Author Adam Dunkels + * Copyright (c) 2001-2003, Adam Dunkels. + * All rights reserved. + */ + +#ifdef CONFIG_ENDIAN_BIG +# define HTONS(ns) (ns) +# define HTONL(nl) (nl) +#else +# define HTONS(ns) \ + (unsigned short) \ + (((((unsigned short)(ns)) & 0x00ff) << 8) | \ + ((((unsigned short)(ns)) >> 8) & 0x00ff)) +# define HTONL(nl) \ + (unsigned long) \ + (((((unsigned long)(nl)) & 0x000000ffUL) << 24) | \ + ((((unsigned long)(nl)) & 0x0000ff00UL) << 8) | \ + ((((unsigned long)(nl)) & 0x00ff0000UL) >> 8) | \ + ((((unsigned long)(nl)) & 0xff000000UL) >> 24)) +#endif + +#define NTOHS(hs) HTONS(hs) +#define NTOHL(hl) HTONL(hl) + /**************************************************************************** * Public Type Definitions ****************************************************************************/ @@ -308,6 +336,22 @@ EXTERN const struct in6_addr in6addr_any; * Public Function Prototypes ****************************************************************************/ +/* Functions to convert between host and network byte ordering. + * + * REVISIT: Since network order is defined as big-endian, the following + * functions are equivalent to functions declared in endian.h: + * + * htonl htobe32 + * htons htobe16 + * ntohl be32toh + * ntohs be16toh + */ + +uint32_t ntohl(uint32_t nl); +uint16_t ntohs(uint16_t ns); +uint32_t htonl(uint32_t hl); +uint16_t htons(uint16_t hs); + #undef EXTERN #if defined(__cplusplus) }