00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef _LINUX_IN_H
00023 #define _LINUX_IN_H
00024
00025
00026
00027 enum {
00028 IPPROTO_IP = 0,
00029 IPPROTO_ICMP = 1,
00030 IPPROTO_GGP = 2,
00031 IPPROTO_TCP = 6,
00032 IPPROTO_EGP = 8,
00033 IPPROTO_PUP = 12,
00034 IPPROTO_UDP = 17,
00035 IPPROTO_IDP = 22,
00036
00037 IPPROTO_RAW = 255,
00038 IPPROTO_MAX
00039 };
00040
00041
00042
00043 struct in_addr {
00044 unsigned long int s_addr;
00045 };
00046
00047
00048
00049 #define __SOCK_SIZE__ 16
00050 struct sockaddr_in {
00051 short int sin_family;
00052 unsigned short int sin_port;
00053 struct in_addr sin_addr;
00054
00055
00056 unsigned char __pad[__SOCK_SIZE__ - sizeof(short int) -
00057 sizeof(unsigned short int) - sizeof(struct in_addr)];
00058 };
00059 #define sin_zero __pad
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071 #define IN_CLASSA(a) ((((long int) (a)) & 0x80000000) == 0)
00072 #define IN_CLASSA_NET 0xff000000
00073 #define IN_CLASSA_NSHIFT 24
00074 #define IN_CLASSA_HOST (0xffffffff & ~IN_CLASSA_NET)
00075 #define IN_CLASSA_MAX 128
00076
00077 #define IN_CLASSB(a) ((((long int) (a)) & 0xc0000000) == 0x80000000)
00078 #define IN_CLASSB_NET 0xffff0000
00079 #define IN_CLASSB_NSHIFT 16
00080 #define IN_CLASSB_HOST (0xffffffff & ~IN_CLASSB_NET)
00081 #define IN_CLASSB_MAX 65536
00082
00083 #define IN_CLASSC(a) ((((long int) (a)) & 0xc0000000) == 0xc0000000)
00084 #define IN_CLASSC_NET 0xffffff00
00085 #define IN_CLASSC_NSHIFT 8
00086 #define IN_CLASSC_HOST (0xffffffff & ~IN_CLASSC_NET)
00087
00088 #define IN_CLASSD(a) ((((long int) (a)) & 0xf0000000) == 0xe0000000)
00089 #define IN_MULTICAST(a) IN_CLASSD(a)
00090
00091 #define IN_EXPERIMENTAL(a) ((((long int) (a)) & 0xe0000000) == 0xe0000000)
00092 #define IN_BADCLASS(a) ((((long int) (a)) & 0xf0000000) == 0xf0000000)
00093
00094
00095 #define INADDR_ANY ((unsigned long int) 0x00000000)
00096
00097
00098 #define INADDR_BROADCAST ((unsigned long int) 0xffffffff)
00099
00100
00101 #define INADDR_NONE 0xffffffff
00102
00103
00104 #define IN_LOOPBACKNET 127
00105
00106
00107 #define INADDR_LOOPBACK 0x7f000001
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119 #if 0
00120 # define IP_OPTIONS 1
00121 #endif
00122 #define IP_HDRINCL 2
00123
00124
00125
00126 #undef ntohl
00127 #undef ntohs
00128 #undef htonl
00129 #undef htons
00130
00131 extern unsigned long int ntohl(unsigned long int);
00132 extern unsigned short int ntohs(unsigned short int);
00133 extern unsigned long int htonl(unsigned long int);
00134 extern unsigned short int htons(unsigned short int);
00135
00136 static __inline__ unsigned long int
00137 __ntohl(unsigned long int x)
00138 {
00139 __asm__("xchgb %b0,%h0\n\t"
00140 "rorl $16,%0\n\t"
00141 "xchgb %b0,%h0"
00142 :"=q" (x)
00143 : "0" (x));
00144 return x;
00145 }
00146
00147 static __inline__ unsigned long int
00148 __constant_ntohl(unsigned long int x)
00149 {
00150 return (((x & 0x000000ff) << 24) |
00151 ((x & 0x0000ff00) << 8) |
00152 ((x & 0x00ff0000) >> 8) |
00153 ((x & 0xff000000) >> 24));
00154 }
00155
00156 static __inline__ unsigned short int
00157 __ntohs(unsigned short int x)
00158 {
00159 __asm__("xchgb %b0,%h0"
00160 : "=q" (x)
00161 : "0" (x));
00162 return x;
00163 }
00164
00165 static __inline__ unsigned short int
00166 __constant_ntohs(unsigned short int x)
00167 {
00168 return (((x & 0x00ff) << 8) |
00169 ((x & 0xff00) >> 8));
00170 }
00171
00172 #define __htonl(x) __ntohl(x)
00173 #define __htons(x) __ntohs(x)
00174 #define __constant_htonl(x) __constant_ntohl(x)
00175 #define __constant_htons(x) __constant_ntohs(x)
00176
00177 #ifdef __OPTIMIZE__
00178 # define ntohl(x) \
00179 (__builtin_constant_p((x)) ? \
00180 __constant_ntohl((x)) : \
00181 __ntohl((x)))
00182 # define ntohs(x) \
00183 (__builtin_constant_p((x)) ? \
00184 __constant_ntohs((x)) : \
00185 __ntohs((x)))
00186 # define htonl(x) \
00187 (__builtin_constant_p((x)) ? \
00188 __constant_htonl((x)) : \
00189 __htonl((x)))
00190 # define htons(x) \
00191 (__builtin_constant_p((x)) ? \
00192 __constant_htons((x)) : \
00193 __htons((x)))
00194 #endif
00195
00196 #endif // _LINUX_IN_H