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