xref: /csrg-svn/sys/netinet/in.h (revision 16378)
1 /*	in.h	6.2	84/04/12	*/
2 
3 /*
4  * Constants and structures defined by the internet system,
5  * Per RFC 790, September 1981.
6  */
7 
8 /*
9  * Protocols
10  */
11 #define	IPPROTO_ICMP		1		/* control message protocol */
12 #define	IPPROTO_GGP		2		/* gateway^2 (deprecated) */
13 #define	IPPROTO_TCP		6		/* tcp */
14 #define	IPPROTO_PUP		12		/* pup */
15 #define	IPPROTO_UDP		17		/* user datagram protocol */
16 #define	IPPROTO_ND		77		/* UNOFFICIAL net disk proto */
17 
18 #define	IPPROTO_RAW		255		/* raw IP packet */
19 #define	IPPROTO_MAX		256
20 
21 /*
22  * Port/socket numbers: network standard functions
23  */
24 #define	IPPORT_ECHO		7
25 #define	IPPORT_DISCARD		9
26 #define	IPPORT_SYSTAT		11
27 #define	IPPORT_DAYTIME		13
28 #define	IPPORT_NETSTAT		15
29 #define	IPPORT_FTP		21
30 #define	IPPORT_TELNET		23
31 #define	IPPORT_SMTP		25
32 #define	IPPORT_TIMESERVER	37
33 #define	IPPORT_NAMESERVER	42
34 #define	IPPORT_WHOIS		43
35 #define	IPPORT_MTP		57
36 
37 /*
38  * Port/socket numbers: host specific functions
39  */
40 #define	IPPORT_TFTP		69
41 #define	IPPORT_RJE		77
42 #define	IPPORT_FINGER		79
43 #define	IPPORT_TTYLINK		87
44 #define	IPPORT_SUPDUP		95
45 
46 /*
47  * UNIX TCP sockets
48  */
49 #define	IPPORT_EXECSERVER	512
50 #define	IPPORT_LOGINSERVER	513
51 #define	IPPORT_CMDSERVER	514
52 #define	IPPORT_EFSSERVER	520
53 
54 /*
55  * UNIX UDP sockets
56  */
57 #define	IPPORT_BIFFUDP		512
58 #define	IPPORT_WHOSERVER	513
59 #define	IPPORT_ROUTESERVER	520	/* 520+1 also used */
60 
61 /*
62  * Ports < IPPORT_RESERVED are reserved for
63  * privileged processes (e.g. root).
64  */
65 #define	IPPORT_RESERVED		1024
66 
67 /*
68  * Link numbers
69  */
70 #define	IMPLINK_IP		155
71 #define	IMPLINK_LOWEXPER	156
72 #define	IMPLINK_HIGHEXPER	158
73 
74 /*
75  * Internet address (old style... should be updated)
76  */
77 struct in_addr {
78 	union {
79 		struct { u_char s_b1,s_b2,s_b3,s_b4; } S_un_b;
80 		struct { u_short s_w1,s_w2; } S_un_w;
81 		u_long S_addr;
82 	} S_un;
83 #define	s_addr	S_un.S_addr	/* can be used for most tcp & ip code */
84 #define	s_host	S_un.S_un_b.s_b2	/* host on imp */
85 #define	s_net	S_un.S_un_b.s_b1	/* network */
86 #define	s_imp	S_un.S_un_w.s_w2	/* imp */
87 #define	s_impno	S_un.S_un_b.s_b4	/* imp # */
88 #define	s_lh	S_un.S_un_b.s_b3	/* logical host */
89 };
90 
91 /*
92  * Definitions of bits in internet address integers.
93  */
94 #define	IN_CLASSA(i)		((((long)(i))&0x80000000)==0)
95 #define	IN_CLASSA_NET		0xff000000
96 #define	IN_CLASSA_NSHIFT	24
97 #define	IN_CLASSA_HOST		0x00ffffff
98 #define	IN_CLASSA_MAX		128
99 
100 #define	IN_CLASSB(i)		((((long)(i))&0xc0000000)==0x80000000)
101 #define	IN_CLASSB_NET		0xffff0000
102 #define	IN_CLASSB_NSHIFT	16
103 #define	IN_CLASSB_HOST		0x0000ffff
104 #define	IN_CLASSB_MAX		65536
105 
106 #define	IN_CLASSC(i)		((((long)(i))&0xc0000000)==0xc0000000)
107 #define	IN_CLASSC_NET		0xffffff00
108 #define	IN_CLASSC_NSHIFT	8
109 #define	IN_CLASSC_HOST		0x000000ff
110 
111 #define	INADDR_ANY	0x00000000
112 
113 /*
114  * Macros for subnetworks.  A subnet is distinguished by
115  * 	(1) the network number is a `local' network number, and
116  *	(2) the most significant bit of the host part is set.
117  * Such addresses include one additional byte in the network number,
118  * and use one less byte in the host part (i.e., a subnet of a Class A
119  * network uses the rules for Class B net/host number extraction,
120  * a Class B subnet is dealt with as if it were a Class C net).
121  * Subnets of Class C nets are not supported.
122  */
123 #define	SUBNETSHIFT		8  /* used to get main net number from subnet */
124 
125 #define	IN_SUBNETA(i)		((((long)(i))&0x80800000)==0x00800000)
126 #define	IN_CLASSA_SUBNET	0xffff0000
127 #define	IN_CLASSA_SUBNSHIFT	(IN_CLASSA_NSHIFT - SUBNETSHIFT)
128 #define	IN_CLASSA_SUBHOST	0x0000ffff
129 
130 #define	IN_SUBNETB(i)		((((long)(i))&0xc0008000)==0x80008000)
131 #define	IN_CLASSB_SUBNET	0xffffff00
132 #define	IN_CLASSB_SUBNSHIFT	(IN_CLASSB_NSHIFT - SUBNETSHIFT)
133 #define	IN_CLASSA_SUBHOST	0x0000ffff
134 #define	IN_CLASSB_SUBHOST	0x000000ff
135 
136 /*
137  * Socket address, internet style.
138  */
139 struct sockaddr_in {
140 	short	sin_family;
141 	u_short	sin_port;
142 	struct	in_addr sin_addr;
143 	char	sin_zero[8];
144 };
145 
146 #if !defined(vax)
147 /*
148  * Macros for number representation conversion.
149  */
150 #define	ntohl(x)	(x)
151 #define	ntohs(x)	(x)
152 #define	htonl(x)	(x)
153 #define	htons(x)	(x)
154 #endif
155 
156 #ifdef KERNEL
157 extern	struct domain inetdomain;
158 extern	struct protosw inetsw[];
159 #endif
160