xref: /original-bsd/sbin/routed/af.c (revision 62734ea8)
1 #ifndef lint
2 static char sccsid[] = "@(#)af.c	4.9 11/02/82";
3 #endif
4 
5 #include "router.h"
6 
7 /*
8  * Address family support routines
9  */
10 int	null_hash(), null_netmatch(), null_output(),
11 	null_portmatch(), null_portcheck(),
12 	null_checkhost(), null_canon();
13 int	inet_hash(), inet_netmatch(), inet_output(),
14 	inet_portmatch(), inet_portcheck(),
15 	inet_checkhost(), inet_canon();
16 #define NIL \
17 	{ null_hash,		null_netmatch,		null_output, \
18 	  null_portmatch,	null_portcheck,		null_checkhost, \
19 	  null_canon }
20 #define	INET \
21 	{ inet_hash,		inet_netmatch,		inet_output, \
22 	  inet_portmatch,	inet_portcheck,		inet_checkhost, \
23 	  inet_canon }
24 
25 struct afswitch afswitch[AF_MAX] =
26 	{ NIL, NIL, INET, INET, NIL, NIL, NIL, NIL, NIL, NIL, NIL };
27 
28 inet_hash(sin, hp)
29 	register struct sockaddr_in *sin;
30 	struct afhash *hp;
31 {
32 
33 	hp->afh_nethash = inet_netof(sin->sin_addr);
34 	hp->afh_hosthash = sin->sin_addr.s_addr;
35 #if vax || pdp11
36 	hp->afh_hosthash = ntohl(hp->afh_hosthash);
37 #endif
38 	hp->afh_hosthash &= 0x7fffffff;
39 }
40 
41 inet_netmatch(sin1, sin2)
42 	struct sockaddr_in *sin1, *sin2;
43 {
44 
45 	return (inet_netof(sin1->sin_addr) == inet_netof(sin2->sin_addr));
46 }
47 
48 /*
49  * Verify the message is from the right port.
50  */
51 inet_portmatch(sin)
52 	register struct sockaddr_in *sin;
53 {
54 
55 #if vax || pdp11
56 	sin->sin_port = ntohs(sin->sin_port);
57 #endif
58 	return (sin->sin_port == sp->s_port || sin->sin_port == sp->s_port+1);
59 }
60 
61 /*
62  * Verify the message is from a "trusted" port.
63  */
64 inet_portcheck(sin)
65 	register struct sockaddr_in *sin;
66 {
67 
68 #if vax || pdp11
69 	sin->sin_port = ntohs(sin->sin_port);
70 #endif
71 	return (sin->sin_port <= IPPORT_RESERVED);
72 }
73 
74 /*
75  * Internet output routine.
76  */
77 inet_output(s, sin, size)
78 	int s;
79 	struct sockaddr_in *sin;
80 	int size;
81 {
82 	struct sockaddr_in dst;
83 
84 	dst = *sin;
85 	sin = &dst;
86 	if (sin->sin_port == 0)
87 		sin->sin_port = htons(sp->s_port);
88 	if (send(s, sin, packet, size) < 0)
89 		perror("send");
90 }
91 
92 /*
93  * Return 1 if the address is believed
94  * for an Internet host -- THIS IS A KLUDGE.
95  */
96 inet_checkhost(sin)
97 	struct sockaddr_in *sin;
98 {
99 	return (inet_lnaof(sin->sin_addr) != 0);
100 }
101 
102 inet_canon(sin)
103 	struct sockaddr_in *sin;
104 {
105 	sin->sin_port = 0;
106 }
107 
108 /*ARGSUSED*/
109 null_hash(addr, hp)
110 	struct sockaddr *addr;
111 	struct afhash *hp;
112 {
113 
114 	hp->afh_nethash = hp->afh_hosthash = 0;
115 }
116 
117 /*ARGSUSED*/
118 null_netmatch(a1, a2)
119 	struct sockaddr *a1, *a2;
120 {
121 
122 	return (0);
123 }
124 
125 /*ARGSUSED*/
126 null_output(s, a1, n)
127 	int s;
128 	struct sockaddr *a1;
129 	int n;
130 {
131 
132 	;
133 }
134 
135 /*ARGSUSED*/
136 null_portmatch(a1)
137 	struct sockaddr *a1;
138 {
139 
140 	return (0);
141 }
142 
143 /*ARGSUSED*/
144 null_portcheck(a1)
145 	struct sockaddr *a1;
146 {
147 
148 	return (0);
149 }
150 
151 /*ARGSUSED*/
152 null_checkhost(a1)
153 	struct sockaddr *a1;
154 {
155 
156 	return (0);
157 }
158 
159 /*ARGSUSED*/
160 null_canon(a1)
161 	struct sockaddr *a1;
162 {
163 
164 	;
165 }
166