]>
Commit | Line | Data |
---|---|---|
df4ef2ab | 1 | /* Copyright (C) 1991, 92, 93, 94, 95, 96, 97 Free Software Foundation, Inc. |
54d79e99 UD |
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 modify | |
5 | it under the terms of the GNU General Public License as published by | |
6 | the Free Software Foundation; either version 2, or (at your option) | |
7 | 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 | |
12 | GNU General Public License for more details. | |
13 | ||
14 | You should have received a copy of the GNU Library General Public | |
15 | License along with the GNU C Library; see the file COPYING.LIB. If not, | |
16 | write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
17 | Boston, MA 02111-1307, USA. */ | |
28f540f4 RM |
18 | |
19 | #ifndef _NETINET_IN_H | |
20 | ||
21 | #define _NETINET_IN_H 1 | |
22 | #include <features.h> | |
23 | ||
24 | #include <sys/socket.h> | |
f8b87ef0 | 25 | |
28f540f4 | 26 | |
df4ef2ab UD |
27 | /* Standard well-defined IP protocols. */ |
28 | enum | |
29 | { | |
30 | IPPROTO_IP = 0, /* Dummy protocol for TCP. */ | |
31 | IPPROTO_ICMP = 1, /* Internet Control Message Protocol. */ | |
32 | IPPROTO_IGMP = 2, /* Internet Group Management Protocol. */ | |
33 | IPPROTO_IPIP = 4, /* IPIP tunnels (older KA9Q tunnels use 94). */ | |
34 | IPPROTO_TCP = 6, /* Transmission Control Protocol. */ | |
35 | IPPROTO_EGP = 8, /* Exterior Gateway Protocol. */ | |
36 | IPPROTO_PUP = 12, /* PUP protocol. */ | |
37 | IPPROTO_UDP = 17, /* User Datagram Protocol. */ | |
38 | IPPROTO_IDP = 22, /* XNS IDP protocol. */ | |
39 | ||
40 | IPPROTO_RAW = 255, /* Raw IP packets. */ | |
41 | IPPROTO_MAX | |
42 | }; | |
43 | ||
44 | /* Standard well-known ports. */ | |
28f540f4 RM |
45 | enum |
46 | { | |
47 | IPPORT_ECHO = 7, /* Echo service. */ | |
48 | IPPORT_DISCARD = 9, /* Discard transmissions service. */ | |
49 | IPPORT_SYSTAT = 11, /* System status service. */ | |
50 | IPPORT_DAYTIME = 13, /* Time of day service. */ | |
51 | IPPORT_NETSTAT = 15, /* Network status service. */ | |
52 | IPPORT_FTP = 21, /* File Transfer Protocol. */ | |
53 | IPPORT_TELNET = 23, /* Telnet protocol. */ | |
54 | IPPORT_SMTP = 25, /* Simple Mail Transfer Protocol. */ | |
55 | IPPORT_TIMESERVER = 37, /* Timeserver service. */ | |
56 | IPPORT_NAMESERVER = 42, /* Domain Name Service. */ | |
293e360a | 57 | IPPORT_WHOIS = 43, /* Internet Whois service. */ |
28f540f4 RM |
58 | IPPORT_MTP = 57, |
59 | ||
60 | IPPORT_TFTP = 69, /* Trivial File Transfer Protocol. */ | |
61 | IPPORT_RJE = 77, | |
62 | IPPORT_FINGER = 79, /* Finger service. */ | |
63 | IPPORT_TTYLINK = 87, | |
64 | IPPORT_SUPDUP = 95, /* SUPDUP protocol. */ | |
65 | ||
66 | ||
67 | IPPORT_EXECSERVER = 512, /* execd service. */ | |
68 | IPPORT_LOGINSERVER = 513, /* rlogind service. */ | |
69 | IPPORT_CMDSERVER = 514, | |
70 | IPPORT_EFSSERVER = 520, | |
71 | ||
72 | /* UDP ports. */ | |
73 | IPPORT_BIFFUDP = 512, | |
74 | IPPORT_WHOSERVER = 513, | |
75 | IPPORT_ROUTESERVER = 520, | |
76 | ||
77 | /* Ports less than this value are reserved for privileged processes. */ | |
78 | IPPORT_RESERVED = 1024, | |
79 | ||
80 | /* Ports greater this value are reserved for (non-privileged) servers. */ | |
59dd8641 | 81 | IPPORT_USERRESERVED = 5000 |
28f540f4 RM |
82 | }; |
83 | ||
84 | ||
df4ef2ab UD |
85 | /* Internet address. */ |
86 | struct in_addr | |
87 | { | |
88 | unsigned int s_addr; | |
89 | }; | |
90 | ||
91 | ||
92 | /* Definitions of the bits in an Internet address integer. | |
93 | ||
94 | On subnets, host and network parts are found according to | |
95 | the subnet mask, not these masks. */ | |
96 | ||
97 | #define IN_CLASSA(a) ((((unsigned) (a)) & 0x80000000) == 0) | |
98 | #define IN_CLASSA_NET 0xff000000 | |
99 | #define IN_CLASSA_NSHIFT 24 | |
100 | #define IN_CLASSA_HOST (0xffffffff & ~IN_CLASSA_NET) | |
101 | #define IN_CLASSA_MAX 128 | |
102 | ||
103 | #define IN_CLASSB(a) ((((unsigned) (a)) & 0xc0000000) == 0x80000000) | |
104 | #define IN_CLASSB_NET 0xffff0000 | |
105 | #define IN_CLASSB_NSHIFT 16 | |
106 | #define IN_CLASSB_HOST (0xffffffff & ~IN_CLASSB_NET) | |
107 | #define IN_CLASSB_MAX 65536 | |
108 | ||
109 | #define IN_CLASSC(a) ((((unsigned) (a)) & 0xc0000000) == 0xc0000000) | |
110 | #define IN_CLASSC_NET 0xffffff00 | |
111 | #define IN_CLASSC_NSHIFT 8 | |
112 | #define IN_CLASSC_HOST (0xffffffff & ~IN_CLASSC_NET) | |
113 | ||
114 | #define IN_CLASSD(a) ((((unsigned) (a)) & 0xf0000000) == 0xe0000000) | |
115 | #define IN_MULTICAST(a) IN_CLASSD(a) | |
116 | ||
117 | #define IN_EXPERIMENTAL(a) ((((unsigned) (a)) & 0xe0000000) == 0xe0000000) | |
118 | #define IN_BADCLASS(a) ((((unsigned) (a)) & 0xf0000000) == 0xf0000000) | |
119 | ||
120 | /* Address to accept any incoming messages. */ | |
121 | #define INADDR_ANY ((unsigned) 0x00000000) | |
122 | /* Address to send to all hosts. */ | |
123 | #define INADDR_BROADCAST ((unsigned) 0xffffffff) | |
124 | /* Address indicating an error return. */ | |
125 | #define INADDR_NONE 0xffffffff | |
126 | ||
127 | /* Network number for local host loopback. */ | |
128 | #define IN_LOOPBACKNET 127 | |
129 | /* Address to loopback in software to local host. */ | |
130 | #ifndef INADDR_LOOPBACK | |
131 | #define INADDR_LOOPBACK 0x7f000001 /* Internet address 127.0.0.1. */ | |
132 | #endif | |
133 | ||
28f540f4 | 134 | |
28f540f4 RM |
135 | /* Get the definition of the macro to define the common sockaddr members. */ |
136 | #include <sockaddrcom.h> | |
137 | ||
df4ef2ab UD |
138 | |
139 | /* Structure describing an Internet socket address. */ | |
140 | struct sockaddr_in | |
141 | { | |
142 | __SOCKADDR_COMMON (sin_); | |
143 | unsigned short int sin_port; /* Port number. */ | |
144 | struct in_addr sin_addr; /* Internet address. */ | |
145 | ||
146 | /* Pad to size of `struct sockaddr'. */ | |
147 | unsigned char sin_zero[sizeof(struct sockaddr) - | |
148 | __SOCKADDR_COMMON_SIZE - | |
149 | sizeof(unsigned short int) - | |
150 | sizeof(struct in_addr)]; | |
151 | }; | |
152 | ||
153 | ||
154 | /* Options for use with `getsockopt' and `setsockopt' at the IP level. | |
155 | The first word in the comment at the right is the data type used; | |
156 | "bool" means a boolean value stored in an `int'. */ | |
157 | #define IP_TOS 1 /* int; IP type of service and precedence. */ | |
158 | #define IP_TTL 2 /* int; IP time to live. */ | |
159 | #define IP_HDRINCL 3 /* int; Header is included with data. */ | |
160 | #define IP_OPTIONS 4 /* ip_opts; IP per-packet options. */ | |
161 | #define IP_MULTICAST_IF 32 /* in_addr; set/get IP multicast i/f */ | |
162 | #define IP_MULTICAST_TTL 33 /* u_char; set/get IP multicast ttl */ | |
163 | #define IP_MULTICAST_LOOP 34 /* i_char; set/get IP multicast loopback */ | |
164 | #define IP_ADD_MEMBERSHIP 35 /* ip_mreq; add an IP group membership */ | |
165 | #define IP_DROP_MEMBERSHIP 36 /* ip_mreq; drop an IP group membership */ | |
166 | ||
167 | /* Structure used to describe IP options for IP_OPTIONS. The `ip_dst' | |
168 | field is used for the first-hop gateway when using a source route | |
169 | (this gets put into the header proper). */ | |
293e360a | 170 | struct ip_opts |
28f540f4 RM |
171 | { |
172 | struct in_addr ip_dst; /* First hop; zero without source route. */ | |
173 | char ip_opts[40]; /* Actually variable in size. */ | |
174 | }; | |
175 | ||
df4ef2ab UD |
176 | /* Structure used for IP_ADD_MEMBERSHIP and IP_DROP_MEMBERSHIP. */ |
177 | struct ip_mreq | |
178 | { | |
179 | struct in_addr imr_multiaddr; /* IP multicast address of group */ | |
180 | struct in_addr imr_interface; /* local IP address of interface */ | |
181 | }; | |
a3e59be8 | 182 | |
28f540f4 RM |
183 | /* Functions to convert between host and network byte order. */ |
184 | ||
df4ef2ab UD |
185 | extern unsigned long int ntohl __P ((unsigned long int)); |
186 | extern unsigned short int ntohs __P ((unsigned short int)); | |
187 | extern unsigned long int htonl __P ((unsigned long int)); | |
188 | extern unsigned short int htons __P ((unsigned short int)); | |
a3e59be8 | 189 | |
28f540f4 RM |
190 | #include <endian.h> |
191 | ||
192 | #if __BYTE_ORDER == __BIG_ENDIAN | |
193 | /* The host byte order is the same as network byte order, | |
194 | so these functions are all just identity. */ | |
df4ef2ab UD |
195 | #define ntohl(x) (x) |
196 | #define ntohs(x) (x) | |
197 | #define htonl(x) (x) | |
198 | #define htons(x) (x) | |
28f540f4 RM |
199 | #endif |
200 | ||
201 | #endif /* netinet/in.h */ |