GNU Radio 3.5.3.2 C++ API
|
00001 /* -*- c++ -*- */ 00002 /* 00003 * Copyright 2008, 2009 Free Software Foundation, Inc. 00004 * 00005 * This program is free software: you can redistribute it and/or modify 00006 * it under the terms of the GNU General Public License as published by 00007 * the Free Software Foundation, either version 3 of the License, or 00008 * (at your option) any later version. 00009 * 00010 * This program is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 * GNU General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU General Public License 00016 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00017 */ 00018 00019 #ifndef INCLUDED_INET_H 00020 #define INCLUDED_INET_H 00021 00022 #include <gruel/api.h> 00023 #include <stdint.h> 00024 00025 #if 1 /* missing htonll or ntohll */ 00026 #if 0 /* GR_ARCH_BIGENDIAN */ 00027 // Nothing to do... 00028 static inline uint64_t htonll(uint64_t x){ return x;} 00029 static inline uint64_t ntohll(uint64_t x){ return x;} 00030 #else 00031 #if 1 /* GR_HAVE_BYTESWAP */ 00032 #include <byteswap.h> 00033 #else 00034 00035 static inline uint64_t 00036 bswap_64(uint64_t x) 00037 { 00038 return ((x & 0x00000000000000ffull) << 56) | ((x & 0x000000000000ff00ull) << 40) | 00039 ((x & 0x0000000000ff0000ull) << 24) | ((x & 0x00000000ff000000ull) << 8) | 00040 ((x & 0x000000ff00000000ull) >> 8) | ((x & 0x0000ff0000000000ull) >> 24) | 00041 ((x & 0x00ff000000000000ull) >> 40) | ((x & 0xff00000000000000ull) >> 56); 00042 } 00043 00044 #endif /* GR_HAVE_BYTESWAP */ 00045 00046 static inline uint64_t htonll(uint64_t x){ return bswap_64(x);} 00047 static inline uint64_t ntohll(uint64_t x){ return bswap_64(x);} 00048 00049 #endif /* GR_ARCH_BIGENDIAN */ 00050 #endif /* missing htonll or ntohll */ 00051 00052 #if 1 /* GR_HAVE_ARPA_INET */ 00053 #include <arpa/inet.h> 00054 #elif 1 /* GR_HAVE_NETINET_IN */ 00055 #include <netinet/in.h> 00056 #else 00057 #include <stdint.h> 00058 00059 #if 0 /* GR_ARCH_BIGENDIAN */ 00060 // Nothing to do... 00061 static inline uint32_t htonl(uint32_t x){ return x; } 00062 static inline uint16_t htons(uint16_t x){ return x; } 00063 static inline uint32_t ntohl(uint32_t x){ return x; } 00064 static inline uint16_t ntohs(uint16_t x){ return x; } 00065 #else 00066 #if 1 /* GR_HAVE_BYTESWAP */ 00067 #include <byteswap.h> 00068 #else 00069 static inline uint16_t 00070 bswap_16 (uint16_t x) 00071 { 00072 return ((((x) >> 8) & 0xff) | (((x) & 0xff) << 8)); 00073 } 00074 00075 static inline uint32_t 00076 bswap_32 (uint32_t x) 00077 { 00078 return ((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >> 8) \ 00079 | (((x) & 0x0000ff00) << 8) | (((x) & 0x000000ff) << 24)); 00080 } 00081 #endif /* GR_HAVE_BYTESWAP */ 00082 00083 static inline uint32_t htonl(uint32_t x){ return bswap_32(x); } 00084 static inline uint16_t htons(uint16_t x){ return bswap_16(x); } 00085 static inline uint32_t ntohl(uint32_t x){ return bswap_32(x); } 00086 static inline uint16_t ntohs(uint16_t x){ return bswap_16(x); } 00087 #endif /* GR_ARCH_BIGENDIAN */ 00088 00089 #endif /* !(GR_HAVE_NETINET_IN || GR_HAVE_ARPA_INET) */ 00090 00091 static inline uint8_t ntohx(uint8_t x){ return x; } 00092 static inline uint16_t ntohx(uint16_t x){ return ntohs(x); } 00093 static inline uint32_t ntohx(uint32_t x){ return ntohl(x); } 00094 static inline uint64_t ntohx(uint64_t x){ return ntohll(x);} 00095 static inline uint8_t htonx(uint8_t x){ return x; } 00096 static inline uint16_t htonx(uint16_t x){ return htons(x); } 00097 static inline uint32_t htonx(uint32_t x){ return htonl(x); } 00098 static inline uint64_t htonx(uint64_t x){ return htonll(x);} 00099 00100 #endif /* INCLUDED_INET_H */