xref: /titanic_52/usr/src/lib/libbc/inc/include/netinet/in.h (revision 275c9da86e89f8abf71135cf63d9fc23671b2e60)
1 /*
2  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
3  * Use is subject to license terms.
4  *
5  * Copyright (c) 1982, 1986 Regents of the University of California.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms are permitted
9  * provided that this notice is preserved and that due credit is given
10  * to the University of California at Berkeley. The name of the University
11  * may not be used to endorse or promote products derived from this
12  * software without specific prior written permission. This software
13  * is provided ``as is'' without express or implied warranty.
14  */
15 
16 /*
17  * Constants and structures defined by the internet system,
18  * Per RFC 790, September 1981.
19  */
20 
21 #ifndef _netinet_in_h
22 #define	_netinet_in_h
23 
24 #pragma ident	"%Z%%M%	%I%	%E% SMI"
25 
26 /*
27  * Protocols
28  */
29 #define	IPPROTO_IP		0		/* dummy for IP */
30 #define	IPPROTO_ICMP		1		/* control message protocol */
31 #define IPPROTO_IGMP		2		/* group control protocol */
32 #define	IPPROTO_GGP		3		/* gateway^2 (deprecated) */
33 #define	IPPROTO_TCP		6		/* tcp */
34 #define	IPPROTO_EGP		8		/* exterior gateway protocol */
35 #define	IPPROTO_PUP		12		/* pup */
36 #define	IPPROTO_UDP		17		/* user datagram protocol */
37 #define	IPPROTO_IDP		22		/* xns idp */
38 #define IPPROTO_HELLO		63		/* "hello" routing protocol */
39 #define	IPPROTO_ND		77		/* UNOFFICIAL net disk proto */
40 
41 #define	IPPROTO_RAW		255		/* raw IP packet */
42 #define	IPPROTO_MAX		256
43 
44 /*
45  * Port/socket numbers: network standard functions
46  */
47 #define	IPPORT_ECHO		7
48 #define	IPPORT_DISCARD		9
49 #define	IPPORT_SYSTAT		11
50 #define	IPPORT_DAYTIME		13
51 #define	IPPORT_NETSTAT		15
52 #define	IPPORT_FTP		21
53 #define	IPPORT_TELNET		23
54 #define	IPPORT_SMTP		25
55 #define	IPPORT_TIMESERVER	37
56 #define	IPPORT_NAMESERVER	42
57 #define	IPPORT_WHOIS		43
58 #define	IPPORT_MTP		57
59 
60 /*
61  * Port/socket numbers: host specific functions
62  */
63 #define	IPPORT_TFTP		69
64 #define	IPPORT_RJE		77
65 #define	IPPORT_FINGER		79
66 #define	IPPORT_TTYLINK		87
67 #define	IPPORT_SUPDUP		95
68 
69 /*
70  * UNIX TCP sockets
71  */
72 #define	IPPORT_EXECSERVER	512
73 #define	IPPORT_LOGINSERVER	513
74 #define	IPPORT_CMDSERVER	514
75 #define	IPPORT_EFSSERVER	520
76 
77 /*
78  * UNIX UDP sockets
79  */
80 #define	IPPORT_BIFFUDP		512
81 #define	IPPORT_WHOSERVER	513
82 #define	IPPORT_ROUTESERVER	520	/* 520+1 also used */
83 
84 /*
85  * Ports < IPPORT_RESERVED are reserved for
86  * privileged processes (e.g. root).
87  * Ports > IPPORT_USERRESERVED are reserved
88  * for servers, not necessarily privileged.
89  */
90 #define	IPPORT_RESERVED		1024
91 #define	IPPORT_USERRESERVED	5000
92 
93 /*
94  * Link numbers
95  */
96 #define	IMPLINK_IP		155
97 #define	IMPLINK_LOWEXPER	156
98 #define	IMPLINK_HIGHEXPER	158
99 
100 /*
101  * Internet address
102  *	This definition contains obsolete fields for compatibility
103  *	with SunOS 3.x and 4.2bsd.  The presence of subnets renders
104  *	divisions into fixed fields misleading at best.  New code
105  *	should use only the s_addr field.
106  */
107 struct in_addr {
108 	union {
109 		struct { u_char s_b1,s_b2,s_b3,s_b4; } S_un_b;
110 		struct { u_short s_w1,s_w2; } S_un_w;
111 		u_long S_addr;
112 	} S_un;
113 #define	s_addr	S_un.S_addr		/* should be used for all code */
114 #define	s_host	S_un.S_un_b.s_b2	/* OBSOLETE: host on imp */
115 #define	s_net	S_un.S_un_b.s_b1	/* OBSOLETE: network */
116 #define	s_imp	S_un.S_un_w.s_w2	/* OBSOLETE: imp */
117 #define	s_impno	S_un.S_un_b.s_b4	/* OBSOLETE: imp # */
118 #define	s_lh	S_un.S_un_b.s_b3	/* OBSOLETE: logical host */
119 };
120 
121 /*
122  * Definitions of bits in internet address integers.
123  * On subnets, the decomposition of addresses to host and net parts
124  * is done according to subnet mask, not the masks here.
125  *
126  * Note that with the introduction of CIDR, IN_CLASSA, IN_CLASSB,
127  * IN_CLASSC, IN_CLASSD and IN_CLASSE macros have become "de-facto obsolete".
128  * IN_MULTICAST macro should be used to test if a address is a
129  * multicast address.
130  */
131 #define	IN_CLASSA(i)		(((long)(i) & 0x80000000) == 0)
132 #define	IN_CLASSA_NET		0xff000000
133 #define	IN_CLASSA_NSHIFT	24
134 #define	IN_CLASSA_HOST		0x00ffffff
135 #define	IN_CLASSA_MAX		128
136 
137 #define	IN_CLASSB(i)		(((long)(i) & 0xc0000000) == 0x80000000)
138 #define	IN_CLASSB_NET		0xffff0000
139 #define	IN_CLASSB_NSHIFT	16
140 #define	IN_CLASSB_HOST		0x0000ffff
141 #define	IN_CLASSB_MAX		65536
142 
143 #define	IN_CLASSC(i)		(((long)(i) & 0xe0000000) == 0xc0000000)
144 #define	IN_CLASSC_NET		0xffffff00
145 #define	IN_CLASSC_NSHIFT	8
146 #define	IN_CLASSC_HOST		0x000000ff
147 
148 #define	IN_CLASSD(i)		(((long)(i) & 0xf0000000) == 0xe0000000)
149 #define	IN_MULTICAST(i)		IN_CLASSD(i)
150 
151 #define	IN_CLASSE(i)		(((long)(i) & 0xf0000000) == 0xf0000000)
152 
153 #define	IN_CLASSE_NET		0xffffffff
154 
155 /*
156  * We have removed CLASS E checks from the kernel
157  * But we preserve these defines for userland  in order
158  * to avoid compile  breakage of some 3rd party piece of software
159  */
160 #ifndef	KERNEL
161 #define	IN_EXPERIMENTAL(i)	(((long)(i) & 0xe0000000) == 0xe0000000)
162 #define	IN_BADCLASS(i)		(((long)(i) & 0xf0000000) == 0xf0000000)
163 #endif
164 
165 #define	INADDR_ANY		(u_long)0x00000000
166 #define	INADDR_LOOPBACK		(u_long)0x7F000001
167 #define	INADDR_BROADCAST	(u_long)0xffffffff	/* must be masked */
168 
169 #define	IN_LOOPBACKNET		127			/* official! */
170 
171 /*
172  * Define a macro to stuff the loopback address into an Internet address
173  */
174 #define IN_SET_LOOPBACK_ADDR(a)	{(a)->sin_addr.s_addr  = htonl(INADDR_LOOPBACK); \
175 	(a)->sin_family = AF_INET;}
176 
177 /*
178  * Socket address, internet style.
179  */
180 struct sockaddr_in {
181 	short	sin_family;
182 	u_short	sin_port;
183 	struct	in_addr sin_addr;
184 	char	sin_zero[8];
185 };
186 
187 /*
188  * Options for use with [gs]etsockopt at the IP level.
189  */
190 #define	IP_OPTIONS	1		/* set/get IP per-packet options */
191 
192 #if !defined(vax) && !defined(ntohl) && !defined(lint) && !defined(i386)
193 /*
194  * Macros for number representation conversion.
195  */
196 #define	ntohl(x)	(x)
197 #define	ntohs(x)	(x)
198 #define	htonl(x)	(x)
199 #define	htons(x)	(x)
200 #endif
201 
202 #if !defined(ntohl) && (defined(vax) || defined(lint) || defined(i386))
203 u_short	ntohs(), htons();
204 u_long	ntohl(), htonl();
205 #endif
206 
207 #ifdef KERNEL
208 extern	struct domain inetdomain;
209 extern	struct protosw inetsw[];
210 struct	in_addr in_makeaddr();
211 u_long	in_netof(), in_lnaof();
212 #endif
213 
214 #endif /* !_netinet_in_h */
215