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 #include <stdint.h>
00023
00024 #if 1
00025 #if 0
00026
00027 static inline uint64_t htonll(uint64_t x){ return x;}
00028 static inline uint64_t ntohll(uint64_t x){ return x;}
00029 #else
00030 #if 1
00031 #include <byteswap.h>
00032 #else
00033
00034 static inline uint64_t
00035 bswap_64(uint64_t x)
00036 {
00037 return ((x & 0x00000000000000ffull) << 56) | ((x & 0x000000000000ff00ull) << 40) |
00038 ((x & 0x0000000000ff0000ull) << 24) | ((x & 0x00000000ff000000ull) << 8) |
00039 ((x & 0x000000ff00000000ull) >> 8) | ((x & 0x0000ff0000000000ull) >> 24) |
00040 ((x & 0x00ff000000000000ull) >> 40) | ((x & 0xff00000000000000ull) >> 56);
00041 }
00042
00043 #endif
00044
00045 static inline uint64_t htonll(uint64_t x){ return bswap_64(x);}
00046 static inline uint64_t ntohll(uint64_t x){ return bswap_64(x);}
00047
00048 #endif
00049 #endif
00050
00051 #if 1
00052 #include <arpa/inet.h>
00053 #elif 1
00054 #include <netinet/in.h>
00055 #else
00056 #include <stdint.h>
00057
00058 #if 0
00059
00060 static inline uint32_t htonl(uint32_t x){ return x; }
00061 static inline uint16_t htons(uint16_t x){ return x; }
00062 static inline uint32_t ntohl(uint32_t x){ return x; }
00063 static inline uint16_t ntohs(uint16_t x){ return x; }
00064 #else
00065 #if 1
00066 #include <byteswap.h>
00067 #else
00068 static inline uint16_t
00069 bswap_16 (uint16_t x)
00070 {
00071 return ((((x) >> 8) & 0xff) | (((x) & 0xff) << 8));
00072 }
00073
00074 static inline uint32_t
00075 bswap_32 (uint32_t x)
00076 {
00077 return ((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >> 8) \
00078 | (((x) & 0x0000ff00) << 8) | (((x) & 0x000000ff) << 24));
00079 }
00080 #endif
00081
00082 static inline uint32_t htonl(uint32_t x){ return bswap_32(x); }
00083 static inline uint16_t htons(uint16_t x){ return bswap_16(x); }
00084 static inline uint32_t ntohl(uint32_t x){ return bswap_32(x); }
00085 static inline uint16_t ntohs(uint16_t x){ return bswap_16(x); }
00086 #endif
00087
00088 #endif
00089
00090 static inline uint8_t ntohx(uint8_t x){ return x; }
00091 static inline uint16_t ntohx(uint16_t x){ return ntohs(x); }
00092 static inline uint32_t ntohx(uint32_t x){ return ntohl(x); }
00093 static inline uint64_t ntohx(uint64_t x){ return ntohll(x);}
00094 static inline uint8_t htonx(uint8_t x){ return x; }
00095 static inline uint16_t htonx(uint16_t x){ return htons(x); }
00096 static inline uint32_t htonx(uint32_t x){ return htonl(x); }
00097 static inline uint64_t htonx(uint64_t x){ return htonll(x);}
00098
00099 #endif