Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef INCLUDED_INET_H
00020 #define INCLUDED_INET_H
00021
00022 #if 1
00023 #include <arpa/inet.h>
00024 #elif 1
00025 #include <netinet/in.h>
00026 #else
00027 #include <stdint.h>
00028
00029 #if 0
00030
00031 static inline uint32_t htonl(uint32_t x){ return x; }
00032 static inline uint16_t htons(uint16_t x){ return x; }
00033 static inline uint32_t ntohl(uint32_t x){ return x; }
00034 static inline uint16_t ntohs(uint16_t x){ return x; }
00035 #else
00036 #if 1
00037 #include <byteswap.h>
00038 #else
00039 static inline uint16_t
00040 bswap_16 (uint16_t x)
00041 {
00042 return ((((x) >> 8) & 0xff) | (((x) & 0xff) << 8));
00043 }
00044
00045 static inline uint32_t
00046 bswap_32 (uint32_t x)
00047 {
00048 return ((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >> 8) \
00049 | (((x) & 0x0000ff00) << 8) | (((x) & 0x000000ff) << 24));
00050 }
00051 #endif
00052
00053 static inline uint32_t htonl(uint32_t x){ return bswap_32(x); }
00054 static inline uint16_t htons(uint16_t x){ return bswap_16(x); }
00055 static inline uint32_t ntohl(uint32_t x){ return bswap_32(x); }
00056 static inline uint16_t ntohs(uint16_t x){ return bswap_16(x); }
00057 #endif
00058
00059 #endif
00060
00061 static inline uint8_t ntohx(uint8_t x){ return x; }
00062 static inline uint16_t ntohx(uint16_t x){ return ntohs(x); }
00063 static inline uint32_t ntohx(uint32_t x){ return ntohl(x); }
00064 static inline uint8_t htonx(uint8_t x){ return x; }
00065 static inline uint16_t htonx(uint16_t x){ return htons(x); }
00066 static inline uint32_t htonx(uint32_t x){ return htonl(x); }
00067
00068 #endif