xref: /original-bsd/sys/netns/ns.h (revision 1ff91bf0)
1 /*
2  * Copyright (c) 1984, 1985, 1986, 1987 Regents of the University of California.
3  * All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  *
7  *	@(#)ns.h	7.8 (Berkeley) 02/22/91
8  */
9 
10 /*
11  * Constants and Structures defined by the Xerox Network Software
12  * per "Internet Transport Protocols", XSIS 028112, December 1981
13  */
14 
15 /*
16  * Protocols
17  */
18 #define NSPROTO_RI	1		/* Routing Information */
19 #define NSPROTO_ECHO	2		/* Echo Protocol */
20 #define NSPROTO_ERROR	3		/* Error Protocol */
21 #define NSPROTO_PE	4		/* Packet Exchange */
22 #define NSPROTO_SPP	5		/* Sequenced Packet */
23 #define NSPROTO_RAW	255		/* Placemarker*/
24 #define NSPROTO_MAX	256		/* Placemarker*/
25 
26 
27 /*
28  * Port/Socket numbers: network standard functions
29  */
30 
31 #define NSPORT_RI	1		/* Routing Information */
32 #define NSPORT_ECHO	2		/* Echo */
33 #define NSPORT_RE	3		/* Router Error */
34 
35 /*
36  * Ports < NSPORT_RESERVED are reserved for priveleged
37  * processes (e.g. root).
38  */
39 #define NSPORT_RESERVED		3000
40 
41 /* flags passed to ns_output as last parameter */
42 
43 #define	NS_FORWARDING		0x1	/* most of idp header exists */
44 #define	NS_ROUTETOIF		0x10	/* same as SO_DONTROUTE */
45 #define	NS_ALLOWBROADCAST	SO_BROADCAST	/* can send broadcast packets */
46 
47 #define NS_MAXHOPS		15
48 
49 /* flags passed to get/set socket option */
50 #define	SO_HEADERS_ON_INPUT	1
51 #define	SO_HEADERS_ON_OUTPUT	2
52 #define	SO_DEFAULT_HEADERS	3
53 #define	SO_LAST_HEADER		4
54 #define	SO_NSIP_ROUTE		5
55 #define SO_SEQNO		6
56 #define	SO_ALL_PACKETS		7
57 #define SO_MTU			8
58 
59 
60 /*
61  * NS addressing
62  */
63 union ns_host {
64 	u_char	c_host[6];
65 	u_short	s_host[3];
66 };
67 
68 union ns_net {
69 	u_char	c_net[4];
70 	u_short	s_net[2];
71 };
72 
73 union ns_net_u {
74 	union ns_net	net_e;
75 	u_long		long_e;
76 };
77 
78 struct ns_addr {
79 	union ns_net	x_net;
80 	union ns_host	x_host;
81 	u_short	x_port;
82 };
83 
84 /*
85  * Socket address, Xerox style
86  */
87 struct sockaddr_ns {
88 	u_char		sns_len;
89 	u_char		sns_family;
90 	struct ns_addr	sns_addr;
91 	char		sns_zero[2];
92 };
93 #define sns_port sns_addr.x_port
94 
95 #ifdef vax
96 #define ns_netof(a) (*(long *) & ((a).x_net)) /* XXX - not needed */
97 #endif
98 #define ns_neteqnn(a,b) (((a).s_net[0]==(b).s_net[0]) && \
99 					((a).s_net[1]==(b).s_net[1]))
100 #define ns_neteq(a,b) ns_neteqnn((a).x_net, (b).x_net)
101 #define satons_addr(sa)	(((struct sockaddr_ns *)&(sa))->sns_addr)
102 #define ns_hosteqnh(s,t) ((s).s_host[0] == (t).s_host[0] && \
103 	(s).s_host[1] == (t).s_host[1] && (s).s_host[2] == (t).s_host[2])
104 #define ns_hosteq(s,t) (ns_hosteqnh((s).x_host,(t).x_host))
105 #define ns_nullhost(x) (((x).x_host.s_host[0]==0) && \
106 	((x).x_host.s_host[1]==0) && ((x).x_host.s_host[2]==0))
107 
108 #ifdef KERNEL
109 extern struct domain nsdomain;
110 union ns_host ns_thishost;
111 union ns_host ns_zerohost;
112 union ns_host ns_broadhost;
113 union ns_net ns_zeronet;
114 union ns_net ns_broadnet;
115 u_short ns_cksum();
116 #else
117 
118 #include <sys/cdefs.h>
119 
120 __BEGIN_DECLS
121 extern struct ns_addr ns_addr __P((const char *));
122 extern char *ns_ntoa __P((struct ns_addr));
123 __END_DECLS
124 
125 #endif
126