xref: /csrg-svn/sys/netinet/in.h (revision 23176)
1 /*
2  * Copyright (c) 1982 Regents of the University of California.
3  * All rights reserved.  The Berkeley software License Agreement
4  * specifies the terms and conditions for redistribution.
5  *
6  *	@(#)in.h	6.5 (Berkeley) 06/08/85
7  */
8 
9 /*
10  * Constants and structures defined by the internet system,
11  * Per RFC 790, September 1981.
12  */
13 
14 /*
15  * Protocols
16  */
17 #define	IPPROTO_ICMP		1		/* control message protocol */
18 #define	IPPROTO_GGP		2		/* gateway^2 (deprecated) */
19 #define	IPPROTO_TCP		6		/* tcp */
20 #define	IPPROTO_EGP		8		/* exterior gateway protocol */
21 #define	IPPROTO_PUP		12		/* pup */
22 #define	IPPROTO_UDP		17		/* user datagram protocol */
23 
24 #define	IPPROTO_RAW		255		/* raw IP packet */
25 #define	IPPROTO_MAX		256
26 
27 
28 /*
29  * Ports < IPPORT_RESERVED are reserved for
30  * privileged processes (e.g. root).
31  */
32 #define	IPPORT_RESERVED		1024
33 
34 /*
35  * Link numbers
36  */
37 #define	IMPLINK_IP		155
38 #define	IMPLINK_LOWEXPER	156
39 #define	IMPLINK_HIGHEXPER	158
40 
41 /*
42  * Internet address (a structure for historical reasons)
43  */
44 struct in_addr {
45 	u_long s_addr;
46 };
47 
48 /*
49  * Definitions of bits in internet address integers.
50  */
51 #define	IN_CLASSA(i)		((((long)(i))&0x80000000)==0)
52 #define	IN_CLASSA_NET		0xff000000
53 #define	IN_CLASSA_NSHIFT	24
54 #define	IN_CLASSA_HOST		0x00ffffff
55 #define	IN_CLASSA_MAX		128
56 
57 #define	IN_CLASSB(i)		((((long)(i))&0xc0000000)==0x80000000)
58 #define	IN_CLASSB_NET		0xffff0000
59 #define	IN_CLASSB_NSHIFT	16
60 #define	IN_CLASSB_HOST		0x0000ffff
61 #define	IN_CLASSB_MAX		65536
62 
63 #define	IN_CLASSC(i)		((((long)(i))&0xc0000000)==0xc0000000)
64 #define	IN_CLASSC_NET		0xffffff00
65 #define	IN_CLASSC_NSHIFT	8
66 #define	IN_CLASSC_HOST		0x000000ff
67 
68 #define	INADDR_ANY		0x00000000
69 #define	INADDR_BROADCAST	0xffffffff
70 
71 /*
72  * Macros for subnetworks.  A subnet is distinguished by
73  * 	(1) the network number is a `local' network number, and
74  *	(2) the most significant bit of the host part is set.
75  * Such addresses include one additional byte in the network number,
76  * and use one less byte in the host part (i.e., a subnet of a Class A
77  * network uses the rules for Class B net/host number extraction,
78  * a Class B subnet is dealt with as if it were a Class C net).
79  * Subnets of Class C nets are not supported.
80  */
81 #define	SUBNETSHIFT		8  /* used to get main net number from subnet */
82 
83 #define	IN_SUBNETA(i)		((((long)(i))&0x80800000)==0x00800000)
84 #define	IN_CLASSA_SUBNET	0xffff0000
85 #define	IN_CLASSA_SUBNSHIFT	(IN_CLASSA_NSHIFT - SUBNETSHIFT)
86 #define	IN_CLASSA_SUBHOST	0x0000ffff
87 
88 #define	IN_SUBNETB(i)		((((long)(i))&0xc0008000)==0x80008000)
89 #define	IN_CLASSB_SUBNET	0xffffff00
90 #define	IN_CLASSB_SUBNSHIFT	(IN_CLASSB_NSHIFT - SUBNETSHIFT)
91 #define	IN_CLASSA_SUBHOST	0x0000ffff
92 #define	IN_CLASSB_SUBHOST	0x000000ff
93 
94 /*
95  * Socket address, internet style.
96  */
97 struct sockaddr_in {
98 	short	sin_family;
99 	u_short	sin_port;
100 	struct	in_addr sin_addr;
101 	char	sin_zero[8];
102 };
103 
104 #if !defined(vax)
105 /*
106  * Macros for number representation conversion.
107  */
108 #define	ntohl(x)	(x)
109 #define	ntohs(x)	(x)
110 #define	htonl(x)	(x)
111 #define	htons(x)	(x)
112 #endif
113 
114 #ifdef KERNEL
115 extern	struct domain inetdomain;
116 extern	struct protosw inetsw[];
117 struct	in_addr in_makeaddr();
118 #endif
119