add Vcs entries to control file
[debian/gnuradio] / gruel / src / include / gruel / inet.h
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2008 Free Software Foundation, Inc.
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17  */
18
19 #ifndef INCLUDED_INET_H
20 #define INCLUDED_INET_H
21
22 #if 1  /* GR_HAVE_ARPA_INET */
23 #include <arpa/inet.h>
24 #elif 1  /* GR_HAVE_NETINET_IN */
25 #include <netinet/in.h>
26 #else
27 #include <stdint.h>
28
29 #if 0  /* GR_ARCH_BIGENDIAN */
30 // Nothing to do...
31 static inline uint32_t htonl(uint32_t x){ return x; }
32 static inline uint16_t htons(uint16_t x){ return x; }
33 static inline uint32_t ntohl(uint32_t x){ return x; }
34 static inline uint16_t ntohs(uint16_t x){ return x; }
35 #else
36 #if 1  /* GR_HAVE_BYTESWAP */
37 #include <byteswap.h>
38 #else
39 static inline uint16_t
40 bswap_16 (uint16_t x)
41 {
42   return ((((x) >> 8) & 0xff) | (((x) & 0xff) << 8));
43 }
44
45 static inline uint32_t
46 bswap_32 (uint32_t x)
47 {
48   return ((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >>  8) \
49         | (((x) & 0x0000ff00) <<  8) | (((x) & 0x000000ff) << 24));
50 }
51 #endif /* GR_HAVE_BYTESWAP */
52
53 static inline uint32_t htonl(uint32_t x){ return bswap_32(x); }
54 static inline uint16_t htons(uint16_t x){ return bswap_16(x); }
55 static inline uint32_t ntohl(uint32_t x){ return bswap_32(x); }
56 static inline uint16_t ntohs(uint16_t x){ return bswap_16(x); }
57 #endif /* GR_ARCH_BIGENDIAN */
58
59 #endif /* !(GR_HAVE_NETINET_IN || GR_HAVE_ARPA_INET) */
60
61 static inline uint8_t  ntohx(uint8_t  x){ return x;        }
62 static inline uint16_t ntohx(uint16_t x){ return ntohs(x); }
63 static inline uint32_t ntohx(uint32_t x){ return ntohl(x); }
64 static inline uint8_t  htonx(uint8_t  x){ return x;        }
65 static inline uint16_t htonx(uint16_t x){ return htons(x); }
66 static inline uint32_t htonx(uint32_t x){ return htonl(x); }
67
68 #endif /* INCLUDED_INET_H */