GNU Radio 3.3.0 C++ API
|
00001 /* -*- c++ -*- */ 00002 /* 00003 * Copyright 2007 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 #ifndef INCLUDED_USRP2_BYTESEX_H 00019 #define INCLUDED_USRP2_BYTESEX_H 00020 00021 // The USRP2 speaks big-endian... 00022 // Use the standard include files or provide substitutions for 00023 // htons and friends 00024 00025 #if defined(HAVE_ARPA_INET_H) 00026 #include <arpa/inet.h> 00027 #elif defined(HAVE_NETINET_IN_H) 00028 #include <netinet/in.h> 00029 #else 00030 #include <stdint.h> 00031 00032 #ifdef WORDS_BIGENDIAN // nothing to do... 00033 00034 static inline uint32_t htonl(uint32_t x){ return x; } 00035 static inline uint16_t htons(uint16_t x){ return x; } 00036 static inline uint32_t ntohl(uint32_t x){ return x; } 00037 static inline uint16_t ntohs(uint16_t x){ return x; } 00038 00039 #else 00040 00041 #ifdef HAVE_BYTESWAP_H 00042 #include <byteswap.h> 00043 #else 00044 00045 static inline uint16_t 00046 bswap_16 (uint16_t x) 00047 { 00048 return ((((x) >> 8) & 0xff) | (((x) & 0xff) << 8)); 00049 } 00050 00051 static inline uint32_t 00052 bswap_32 (uint32_t x) 00053 { 00054 return ((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >> 8) \ 00055 | (((x) & 0x0000ff00) << 8) | (((x) & 0x000000ff) << 24)); 00056 } 00057 #endif 00058 00059 static inline uint32_t htonl(uint32_t x){ return bswap_32(x); } 00060 static inline uint16_t htons(uint16_t x){ return bswap_16(x); } 00061 static inline uint32_t ntohl(uint32_t x){ return bswap_32(x); } 00062 static inline uint16_t ntohs(uint16_t x){ return bswap_16(x); } 00063 00064 #endif 00065 #endif 00066 #endif /* INCLUDED_USRP2_BYTESEX_H */