source: svn/trunk/newcon3bcm2_21bu/toolchain/mips-linux-uclibc/include/netinet/in.h @ 76

Last change on this file since 76 was 2, checked in by phkim, 11 years ago

1.phkim

  1. revision copy newcon3sk r27
  • Property svn:executable set to *
File size: 12.4 KB
Line 
1/* Copyright (C) 1991-1999, 2000, 2001 Free Software Foundation, Inc.
2   This file is part of the GNU C Library.
3
4   The GNU C Library is free software; you can redistribute it and/or
5   modify it under the terms of the GNU Lesser General Public
6   License as published by the Free Software Foundation; either
7   version 2.1 of the License, or (at your option) any later version.
8
9   The GNU C Library is distributed in the hope that it will be useful,
10   but WITHOUT ANY WARRANTY; without even the implied warranty of
11   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12   Lesser General Public License for more details.
13
14   You should have received a copy of the GNU Lesser General Public
15   License along with the GNU C Library; if not, write to the Free
16   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
17   02111-1307 USA.  */
18
19#ifndef _NETINET_IN_H
20#define _NETINET_IN_H   1
21
22#include <features.h>
23#include <stdint.h>
24#include <bits/types.h>
25
26
27__BEGIN_DECLS
28
29/* Standard well-defined IP protocols.  */
30enum
31  {
32    IPPROTO_IP = 0,        /* Dummy protocol for TCP.  */
33#define IPPROTO_IP              IPPROTO_IP
34    IPPROTO_HOPOPTS = 0,   /* IPv6 Hop-by-Hop options.  */
35#define IPPROTO_HOPOPTS         IPPROTO_HOPOPTS
36    IPPROTO_ICMP = 1,      /* Internet Control Message Protocol.  */
37#define IPPROTO_ICMP            IPPROTO_ICMP
38    IPPROTO_IGMP = 2,      /* Internet Group Management Protocol. */
39#define IPPROTO_IGMP            IPPROTO_IGMP
40    IPPROTO_IPIP = 4,      /* IPIP tunnels (older KA9Q tunnels use 94).  */
41#define IPPROTO_IPIP            IPPROTO_IPIP
42    IPPROTO_TCP = 6,       /* Transmission Control Protocol.  */
43#define IPPROTO_TCP             IPPROTO_TCP
44    IPPROTO_EGP = 8,       /* Exterior Gateway Protocol.  */
45#define IPPROTO_EGP             IPPROTO_EGP
46    IPPROTO_PUP = 12,      /* PUP protocol.  */
47#define IPPROTO_PUP             IPPROTO_PUP
48    IPPROTO_UDP = 17,      /* User Datagram Protocol.  */
49#define IPPROTO_UDP             IPPROTO_UDP
50    IPPROTO_IDP = 22,      /* XNS IDP protocol.  */
51#define IPPROTO_IDP             IPPROTO_IDP
52    IPPROTO_TP = 29,       /* SO Transport Protocol Class 4.  */
53#define IPPROTO_TP              IPPROTO_TP
54    IPPROTO_IPV6 = 41,     /* IPv6 header.  */
55#define IPPROTO_IPV6            IPPROTO_IPV6
56    IPPROTO_ROUTING = 43,  /* IPv6 routing header.  */
57#define IPPROTO_ROUTING         IPPROTO_ROUTING
58    IPPROTO_FRAGMENT = 44, /* IPv6 fragmentation header.  */
59#define IPPROTO_FRAGMENT        IPPROTO_FRAGMENT
60    IPPROTO_RSVP = 46,     /* Reservation Protocol.  */
61#define IPPROTO_RSVP            IPPROTO_RSVP
62    IPPROTO_GRE = 47,      /* General Routing Encapsulation.  */
63#define IPPROTO_GRE             IPPROTO_GRE
64    IPPROTO_ESP = 50,      /* encapsulating security payload.  */
65#define IPPROTO_ESP             IPPROTO_ESP
66    IPPROTO_AH = 51,       /* authentication header.  */
67#define IPPROTO_AH              IPPROTO_AH
68    IPPROTO_ICMPV6 = 58,   /* ICMPv6.  */
69#define IPPROTO_ICMPV6          IPPROTO_ICMPV6
70    IPPROTO_NONE = 59,     /* IPv6 no next header.  */
71#define IPPROTO_NONE            IPPROTO_NONE
72    IPPROTO_DSTOPTS = 60,  /* IPv6 destination options.  */
73#define IPPROTO_DSTOPTS         IPPROTO_DSTOPTS
74    IPPROTO_MTP = 92,      /* Multicast Transport Protocol.  */
75#define IPPROTO_MTP             IPPROTO_MTP
76    IPPROTO_ENCAP = 98,    /* Encapsulation Header.  */
77#define IPPROTO_ENCAP           IPPROTO_ENCAP
78    IPPROTO_PIM = 103,     /* Protocol Independent Multicast.  */
79#define IPPROTO_PIM             IPPROTO_PIM
80    IPPROTO_COMP = 108,    /* Compression Header Protocol.  */
81#define IPPROTO_COMP            IPPROTO_COMP
82    IPPROTO_RAW = 255,     /* Raw IP packets.  */
83#define IPPROTO_RAW             IPPROTO_RAW
84    IPPROTO_MAX
85  };
86
87
88/* Type to represent a port.  */
89typedef uint16_t in_port_t;
90
91/* Standard well-known ports.  */
92enum
93  {
94    IPPORT_ECHO = 7,            /* Echo service.  */
95    IPPORT_DISCARD = 9,         /* Discard transmissions service.  */
96    IPPORT_SYSTAT = 11,         /* System status service.  */
97    IPPORT_DAYTIME = 13,        /* Time of day service.  */
98    IPPORT_NETSTAT = 15,        /* Network status service.  */
99    IPPORT_FTP = 21,            /* File Transfer Protocol.  */
100    IPPORT_TELNET = 23,         /* Telnet protocol.  */
101    IPPORT_SMTP = 25,           /* Simple Mail Transfer Protocol.  */
102    IPPORT_TIMESERVER = 37,     /* Timeserver service.  */
103    IPPORT_NAMESERVER = 42,     /* Domain Name Service.  */
104    IPPORT_WHOIS = 43,          /* Internet Whois service.  */
105    IPPORT_MTP = 57,
106
107    IPPORT_TFTP = 69,           /* Trivial File Transfer Protocol.  */
108    IPPORT_RJE = 77,
109    IPPORT_FINGER = 79,         /* Finger service.  */
110    IPPORT_TTYLINK = 87,
111    IPPORT_SUPDUP = 95,         /* SUPDUP protocol.  */
112
113
114    IPPORT_EXECSERVER = 512,    /* execd service.  */
115    IPPORT_LOGINSERVER = 513,   /* rlogind service.  */
116    IPPORT_CMDSERVER = 514,
117    IPPORT_EFSSERVER = 520,
118
119    /* UDP ports.  */
120    IPPORT_BIFFUDP = 512,
121    IPPORT_WHOSERVER = 513,
122    IPPORT_ROUTESERVER = 520,
123
124    /* Ports less than this value are reserved for privileged processes.  */
125    IPPORT_RESERVED = 1024,
126
127    /* Ports greater this value are reserved for (non-privileged) servers.  */
128    IPPORT_USERRESERVED = 5000
129  };
130
131
132/* Internet address.  */
133typedef uint32_t in_addr_t;
134struct in_addr
135  {
136    in_addr_t s_addr;
137  };
138
139
140/* Definitions of the bits in an Internet address integer.
141
142   On subnets, host and network parts are found according to
143   the subnet mask, not these masks.  */
144
145#define IN_CLASSA(a)            ((((in_addr_t)(a)) & 0x80000000) == 0)
146#define IN_CLASSA_NET           0xff000000
147#define IN_CLASSA_NSHIFT        24
148#define IN_CLASSA_HOST          (0xffffffff & ~IN_CLASSA_NET)
149#define IN_CLASSA_MAX           128
150
151#define IN_CLASSB(a)            ((((in_addr_t)(a)) & 0xc0000000) == 0x80000000)
152#define IN_CLASSB_NET           0xffff0000
153#define IN_CLASSB_NSHIFT        16
154#define IN_CLASSB_HOST          (0xffffffff & ~IN_CLASSB_NET)
155#define IN_CLASSB_MAX           65536
156
157#define IN_CLASSC(a)            ((((in_addr_t)(a)) & 0xe0000000) == 0xc0000000)
158#define IN_CLASSC_NET           0xffffff00
159#define IN_CLASSC_NSHIFT        8
160#define IN_CLASSC_HOST          (0xffffffff & ~IN_CLASSC_NET)
161
162#define IN_CLASSD(a)            ((((in_addr_t)(a)) & 0xf0000000) == 0xe0000000)
163#define IN_MULTICAST(a)         IN_CLASSD(a)
164
165#define IN_EXPERIMENTAL(a)      ((((in_addr_t)(a)) & 0xe0000000) == 0xe0000000)
166#define IN_BADCLASS(a)          ((((in_addr_t)(a)) & 0xf0000000) == 0xf0000000)
167
168/* Address to accept any incoming messages.  */
169#define INADDR_ANY              ((in_addr_t) 0x00000000)
170/* Address to send to all hosts.  */
171#define INADDR_BROADCAST        ((in_addr_t) 0xffffffff)
172/* Address indicating an error return.  */
173#define INADDR_NONE             ((in_addr_t) 0xffffffff)
174
175/* Network number for local host loopback.  */
176#define IN_LOOPBACKNET          127
177/* Address to loopback in software to local host.  */
178#ifndef INADDR_LOOPBACK
179# define INADDR_LOOPBACK        ((in_addr_t) 0x7f000001) /* Inet 127.0.0.1.  */
180#endif
181
182/* Defines for Multicast INADDR.  */
183#define INADDR_UNSPEC_GROUP     ((in_addr_t) 0xe0000000) /* 224.0.0.0 */
184#define INADDR_ALLHOSTS_GROUP   ((in_addr_t) 0xe0000001) /* 224.0.0.1 */
185#define INADDR_ALLRTRS_GROUP    ((in_addr_t) 0xe0000002) /* 224.0.0.2 */
186#define INADDR_MAX_LOCAL_GROUP  ((in_addr_t) 0xe00000ff) /* 224.0.0.255 */
187
188
189/* IPv6 address */
190struct in6_addr
191  {
192    union
193      {
194        uint8_t u6_addr8[16];
195        uint16_t u6_addr16[8];
196        uint32_t u6_addr32[4];
197      } in6_u;
198#define s6_addr                 in6_u.u6_addr8
199#define s6_addr16               in6_u.u6_addr16
200#define s6_addr32               in6_u.u6_addr32
201  };
202
203extern const struct in6_addr in6addr_any;        /* :: */
204extern const struct in6_addr in6addr_loopback;   /* ::1 */
205#define IN6ADDR_ANY_INIT { { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } } }
206#define IN6ADDR_LOOPBACK_INIT { { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 } } }
207
208#define INET_ADDRSTRLEN 16
209#define INET6_ADDRSTRLEN 46
210
211/* Get the definition of the macro to define the common sockaddr members.  */
212#include <bits/socket.h>
213
214
215/* Structure describing an Internet socket address.  */
216struct sockaddr_in
217  {
218    __SOCKADDR_COMMON (sin_);
219    in_port_t sin_port;                 /* Port number.  */
220    struct in_addr sin_addr;            /* Internet address.  */
221
222    /* Pad to size of `struct sockaddr'.  */
223    unsigned char sin_zero[sizeof (struct sockaddr) -
224                           __SOCKADDR_COMMON_SIZE -
225                           sizeof (in_port_t) -
226                           sizeof (struct in_addr)];
227  };
228
229/* Ditto, for IPv6.  */
230struct sockaddr_in6
231  {
232    __SOCKADDR_COMMON (sin6_);
233    in_port_t sin6_port;        /* Transport layer port # */
234    uint32_t sin6_flowinfo;     /* IPv6 flow information */
235    struct in6_addr sin6_addr;  /* IPv6 address */
236    uint32_t sin6_scope_id;     /* IPv6 scope-id */
237  };
238
239/* IPv6 multicast request.  */
240struct ipv6_mreq
241  {
242    /* IPv6 multicast address of group */
243    struct in6_addr ipv6mr_multiaddr;
244
245    /* local interface */
246    unsigned int ipv6mr_interface;
247  };
248
249/* Get system-specific definitions.  */
250#include <bits/in.h>
251
252/* Functions to convert between host and network byte order.
253
254   Please note that these functions normally take `unsigned long int' or
255   `unsigned short int' values as arguments and also return them.  But
256   this was a short-sighted decision since on different systems the types
257   may have different representations but the values are always the same.  */
258
259extern uint32_t ntohl (uint32_t __netlong) __THROW __attribute__ ((__const__));
260extern uint16_t ntohs (uint16_t __netshort)
261     __THROW __attribute__ ((__const__));
262extern uint32_t htonl (uint32_t __hostlong)
263     __THROW __attribute__ ((__const__));
264extern uint16_t htons (uint16_t __hostshort)
265     __THROW __attribute__ ((__const__));
266
267#include <endian.h>
268
269/* Get machine dependent optimized versions of byte swapping functions.  */
270#include <bits/byteswap.h>
271
272#ifndef __OPTIMIZE__
273#define __OPTIMIZE__
274#endif
275#ifdef __OPTIMIZE__
276/* We can optimize calls to the conversion functions.  Either nothing has
277   to be done or we are using directly the byte-swapping functions which
278   often can be inlined.  */
279# if __BYTE_ORDER == __BIG_ENDIAN
280/* The host byte order is the same as network byte order,
281   so these functions are all just identity.  */
282# define ntohl(x)       (x)
283# define ntohs(x)       (x)
284# define htonl(x)       (x)
285# define htons(x)       (x)
286# else
287#  if __BYTE_ORDER == __LITTLE_ENDIAN
288#   define ntohl(x)     __bswap_32 (x)
289#   define ntohs(x)     __bswap_16 (x)
290#   define htonl(x)     __bswap_32 (x)
291#   define htons(x)     __bswap_16 (x)
292#  endif
293# endif
294#endif
295
296#define IN6_IS_ADDR_UNSPECIFIED(a) \
297        (((__const uint32_t *) (a))[0] == 0                                   \
298         && ((__const uint32_t *) (a))[1] == 0                                \
299         && ((__const uint32_t *) (a))[2] == 0                                \
300         && ((__const uint32_t *) (a))[3] == 0)
301
302#define IN6_IS_ADDR_LOOPBACK(a) \
303        (((__const uint32_t *) (a))[0] == 0                                   \
304         && ((__const uint32_t *) (a))[1] == 0                                \
305         && ((__const uint32_t *) (a))[2] == 0                                \
306         && ((__const uint32_t *) (a))[3] == htonl (1))
307
308#define IN6_IS_ADDR_MULTICAST(a) (((__const uint8_t *) (a))[0] == 0xff)
309
310#define IN6_IS_ADDR_LINKLOCAL(a) \
311        ((((__const uint32_t *) (a))[0] & htonl (0xffc00000))                 \
312         == htonl (0xfe800000))
313
314#define IN6_IS_ADDR_SITELOCAL(a) \
315        ((((__const uint32_t *) (a))[0] & htonl (0xffc00000))                 \
316         == htonl (0xfec00000))
317
318#define IN6_IS_ADDR_V4MAPPED(a) \
319        ((((__const uint32_t *) (a))[0] == 0)                                 \
320         && (((__const uint32_t *) (a))[1] == 0)                              \
321         && (((__const uint32_t *) (a))[2] == htonl (0xffff)))
322
323#define IN6_IS_ADDR_V4COMPAT(a) \
324        ((((__const uint32_t *) (a))[0] == 0)                                 \
325         && (((__const uint32_t *) (a))[1] == 0)                              \
326         && (((__const uint32_t *) (a))[2] == 0)                              \
327         && (ntohl (((__const uint32_t *) (a))[3]) > 1))
328
329#define IN6_ARE_ADDR_EQUAL(a,b) \
330        ((((__const uint32_t *) (a))[0] == ((__const uint32_t *) (b))[0])     \
331         && (((__const uint32_t *) (a))[1] == ((__const uint32_t *) (b))[1])  \
332         && (((__const uint32_t *) (a))[2] == ((__const uint32_t *) (b))[2])  \
333         && (((__const uint32_t *) (a))[3] == ((__const uint32_t *) (b))[3]))
334
335/* Bind socket to a privileged IP port.  */
336extern int bindresvport (int __sockfd, struct sockaddr_in *__sock_in) __THROW;
337
338/* The IPv6 version of this function.  */
339extern int bindresvport6 (int __sockfd, struct sockaddr_in6 *__sock_in)
340     __THROW;
341
342
343#define IN6_IS_ADDR_MC_NODELOCAL(a) \
344        (IN6_IS_ADDR_MULTICAST(a)                                             \
345         && ((((__const uint8_t *) (a))[1] & 0xf) == 0x1))
346
347#define IN6_IS_ADDR_MC_LINKLOCAL(a) \
348        (IN6_IS_ADDR_MULTICAST(a)                                             \
349         && ((((__const uint8_t *) (a))[1] & 0xf) == 0x2))
350
351#define IN6_IS_ADDR_MC_SITELOCAL(a) \
352        (IN6_IS_ADDR_MULTICAST(a)                                             \
353         && ((((__const uint8_t *) (a))[1] & 0xf) == 0x5))
354
355#define IN6_IS_ADDR_MC_ORGLOCAL(a) \
356        (IN6_IS_ADDR_MULTICAST(a)                                             \
357         && ((((__const uint8_t *) (a))[1] & 0xf) == 0x8))
358
359#define IN6_IS_ADDR_MC_GLOBAL(a) \
360        (IN6_IS_ADDR_MULTICAST(a)                                             \
361         && ((((__const uint8_t *) (a))[1] & 0xf) == 0xe))
362
363/* IPv6 packet information.  */
364struct in6_pktinfo
365  {
366    struct in6_addr     ipi6_addr;    /* src/dst IPv6 address */
367    unsigned int        ipi6_ifindex; /* send/recv interface index */
368  };
369
370__END_DECLS
371
372#endif  /* netinet/in.h */
Note: See TracBrowser for help on using the repository browser.