This source file includes following definitions.
- __ntohl
- __constant_ntohl
- __ntohs
- __constant_ntohs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 #ifndef _LINUX_IN_H
19 #define _LINUX_IN_H
20
21
22
23 enum {
24 IPPROTO_IP = 0,
25 IPPROTO_ICMP = 1,
26 IPPROTO_IGMP = 2,
27 IPPROTO_TCP = 6,
28 IPPROTO_EGP = 8,
29 IPPROTO_PUP = 12,
30 IPPROTO_UDP = 17,
31 IPPROTO_IDP = 22,
32
33 IPPROTO_RAW = 255,
34 IPPROTO_MAX
35 };
36
37
38
39 struct in_addr {
40 unsigned long int s_addr;
41 };
42
43
44
45 struct ip_mreq
46 {
47 struct in_addr imr_multiaddr;
48 struct in_addr imr_interface;
49 };
50
51
52
53 #define __SOCK_SIZE__ 16
54 struct sockaddr_in {
55 short int sin_family;
56 unsigned short int sin_port;
57 struct in_addr sin_addr;
58
59
60 unsigned char __pad[__SOCK_SIZE__ - sizeof(short int) -
61 sizeof(unsigned short int) - sizeof(struct in_addr)];
62 };
63 #define sin_zero __pad
64
65
66
67
68
69
70
71 #define IN_CLASSA(a) ((((long int) (a)) & 0x80000000) == 0)
72 #define IN_CLASSA_NET 0xff000000
73 #define IN_CLASSA_NSHIFT 24
74 #define IN_CLASSA_HOST (0xffffffff & ~IN_CLASSA_NET)
75 #define IN_CLASSA_MAX 128
76
77 #define IN_CLASSB(a) ((((long int) (a)) & 0xc0000000) == 0x80000000)
78 #define IN_CLASSB_NET 0xffff0000
79 #define IN_CLASSB_NSHIFT 16
80 #define IN_CLASSB_HOST (0xffffffff & ~IN_CLASSB_NET)
81 #define IN_CLASSB_MAX 65536
82
83 #define IN_CLASSC(a) ((((long int) (a)) & 0xc0000000) == 0xc0000000)
84 #define IN_CLASSC_NET 0xffffff00
85 #define IN_CLASSC_NSHIFT 8
86 #define IN_CLASSC_HOST (0xffffffff & ~IN_CLASSC_NET)
87
88 #define IN_CLASSD(a) ((((long int) (a)) & 0xf0000000) == 0xe0000000)
89 #define IN_MULTICAST(a) IN_CLASSD(a)
90 #define IN_MULTICAST_NET 0xF0000000
91
92 #define IN_EXPERIMENTAL(a) ((((long int) (a)) & 0xe0000000) == 0xe0000000)
93 #define IN_BADCLASS(a) ((((long int) (a)) & 0xf0000000) == 0xf0000000)
94
95
96 #define INADDR_ANY ((unsigned long int) 0x00000000)
97
98
99 #define INADDR_BROADCAST ((unsigned long int) 0xffffffff)
100
101
102 #define INADDR_NONE 0xffffffff
103
104
105 #define IN_LOOPBACKNET 127
106
107
108 #define INADDR_LOOPBACK 0x7f000001
109
110
111 #define INADDR_UNSPEC_GROUP 0xe0000000
112 #define INADDR_ALLHOSTS_GROUP 0xe0000001
113 #define INADDR_MAX_LOCAL_GROUP 0xe00000ff
114
115
116
117 #undef ntohl
118 #undef ntohs
119 #undef htonl
120 #undef htons
121
122 extern unsigned long int ntohl(unsigned long int);
123 extern unsigned short int ntohs(unsigned short int);
124 extern unsigned long int htonl(unsigned long int);
125 extern unsigned short int htons(unsigned short int);
126
127 extern __inline__ unsigned long int
128 __ntohl(unsigned long int x)
129 {
130 __asm__("xchgb %b0,%h0\n\t"
131 "rorl $16,%0\n\t"
132 "xchgb %b0,%h0"
133 :"=q" (x)
134 : "0" (x));
135 return x;
136 }
137
138 extern __inline__ unsigned long int
139 __constant_ntohl(unsigned long int x)
140 {
141 return (((x & 0x000000ffU) << 24) |
142 ((x & 0x0000ff00U) << 8) |
143 ((x & 0x00ff0000U) >> 8) |
144 ((x & 0xff000000U) >> 24));
145 }
146
147 extern __inline__ unsigned short int
148 __ntohs(unsigned short int x)
149 {
150 __asm__("xchgb %b0,%h0"
151 : "=q" (x)
152 : "0" (x));
153 return x;
154 }
155
156 extern __inline__ unsigned short int
157 __constant_ntohs(unsigned short int x)
158 {
159 return (((x & 0x00ff) << 8) |
160 ((x & 0xff00) >> 8));
161 }
162
163 #define __htonl(x) __ntohl(x)
164 #define __htons(x) __ntohs(x)
165 #define __constant_htonl(x) __constant_ntohl(x)
166 #define __constant_htons(x) __constant_ntohs(x)
167
168 #ifdef __OPTIMIZE__
169 # define ntohl(x) \
170 (__builtin_constant_p((long)(x)) ? \
171 __constant_ntohl((x)) : \
172 __ntohl((x)))
173 # define ntohs(x) \
174 (__builtin_constant_p((short)(x)) ? \
175 __constant_ntohs((x)) : \
176 __ntohs((x)))
177 # define htonl(x) \
178 (__builtin_constant_p((long)(x)) ? \
179 __constant_htonl((x)) : \
180 __htonl((x)))
181 # define htons(x) \
182 (__builtin_constant_p((short)(x)) ? \
183 __constant_htons((x)) : \
184 __htons((x)))
185 #endif
186
187 #endif