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