Commit | Line | Data |
---|---|---|
85bbbfa4 | 1 | #ifndef lint |
c8c4156e | 2 | static char sccsid[] = "@(#)af.c 4.9 %G%"; |
85bbbfa4 SL |
3 | #endif |
4 | ||
85bbbfa4 | 5 | #include "router.h" |
ecce71aa | 6 | |
85bbbfa4 SL |
7 | /* |
8 | * Address family support routines | |
9 | */ | |
10 | int null_hash(), null_netmatch(), null_output(), | |
a773b026 SL |
11 | null_portmatch(), null_portcheck(), |
12 | null_checkhost(), null_canon(); | |
85bbbfa4 | 13 | int inet_hash(), inet_netmatch(), inet_output(), |
a773b026 SL |
14 | inet_portmatch(), inet_portcheck(), |
15 | inet_checkhost(), inet_canon(); | |
85bbbfa4 SL |
16 | #define NIL \ |
17 | { null_hash, null_netmatch, null_output, \ | |
a773b026 SL |
18 | null_portmatch, null_portcheck, null_checkhost, \ |
19 | null_canon } | |
85bbbfa4 SL |
20 | #define INET \ |
21 | { inet_hash, inet_netmatch, inet_output, \ | |
a773b026 SL |
22 | inet_portmatch, inet_portcheck, inet_checkhost, \ |
23 | inet_canon } | |
85bbbfa4 SL |
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 | ||
68a24a8f | 33 | hp->afh_nethash = inet_netof(sin->sin_addr); |
6db0b3a4 BJ |
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; | |
85bbbfa4 SL |
39 | } |
40 | ||
41 | inet_netmatch(sin1, sin2) | |
42 | struct sockaddr_in *sin1, *sin2; | |
43 | { | |
44 | ||
68a24a8f | 45 | return (inet_netof(sin1->sin_addr) == inet_netof(sin2->sin_addr)); |
85bbbfa4 SL |
46 | } |
47 | ||
48 | /* | |
49 | * Verify the message is from the right port. | |
50 | */ | |
51 | inet_portmatch(sin) | |
c8c4156e | 52 | register struct sockaddr_in *sin; |
85bbbfa4 | 53 | { |
6db0b3a4 BJ |
54 | |
55 | #if vax || pdp11 | |
c8c4156e | 56 | sin->sin_port = ntohs(sin->sin_port); |
6db0b3a4 | 57 | #endif |
c8c4156e | 58 | return (sin->sin_port == sp->s_port || sin->sin_port == sp->s_port+1); |
85bbbfa4 SL |
59 | } |
60 | ||
a773b026 SL |
61 | /* |
62 | * Verify the message is from a "trusted" port. | |
63 | */ | |
64 | inet_portcheck(sin) | |
c8c4156e | 65 | register struct sockaddr_in *sin; |
a773b026 | 66 | { |
a773b026 | 67 | |
6db0b3a4 | 68 | #if vax || pdp11 |
c8c4156e | 69 | sin->sin_port = ntohs(sin->sin_port); |
6db0b3a4 | 70 | #endif |
c8c4156e | 71 | return (sin->sin_port <= IPPORT_RESERVED); |
a773b026 SL |
72 | } |
73 | ||
85bbbfa4 SL |
74 | /* |
75 | * Internet output routine. | |
76 | */ | |
6db0b3a4 BJ |
77 | inet_output(s, sin, size) |
78 | int s; | |
85bbbfa4 SL |
79 | struct sockaddr_in *sin; |
80 | int size; | |
81 | { | |
85bbbfa4 SL |
82 | struct sockaddr_in dst; |
83 | ||
84 | dst = *sin; | |
85 | sin = &dst; | |
c8c4156e SL |
86 | if (sin->sin_port == 0) |
87 | sin->sin_port = htons(sp->s_port); | |
85bbbfa4 | 88 | if (send(s, sin, packet, size) < 0) |
c8c4156e | 89 | perror("send"); |
85bbbfa4 SL |
90 | } |
91 | ||
92 | /* | |
0ad851d4 SL |
93 | * Return 1 if the address is believed |
94 | * for an Internet host -- THIS IS A KLUDGE. | |
85bbbfa4 SL |
95 | */ |
96 | inet_checkhost(sin) | |
97 | struct sockaddr_in *sin; | |
98 | { | |
68a24a8f | 99 | return (inet_lnaof(sin->sin_addr) != 0); |
85bbbfa4 SL |
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*/ | |
6db0b3a4 BJ |
126 | null_output(s, a1, n) |
127 | int s; | |
85bbbfa4 SL |
128 | struct sockaddr *a1; |
129 | int n; | |
130 | { | |
6db0b3a4 | 131 | |
85bbbfa4 SL |
132 | ; |
133 | } | |
134 | ||
135 | /*ARGSUSED*/ | |
136 | null_portmatch(a1) | |
137 | struct sockaddr *a1; | |
138 | { | |
6db0b3a4 | 139 | |
85bbbfa4 SL |
140 | return (0); |
141 | } | |
142 | ||
a773b026 SL |
143 | /*ARGSUSED*/ |
144 | null_portcheck(a1) | |
145 | struct sockaddr *a1; | |
146 | { | |
6db0b3a4 | 147 | |
a773b026 SL |
148 | return (0); |
149 | } | |
150 | ||
85bbbfa4 SL |
151 | /*ARGSUSED*/ |
152 | null_checkhost(a1) | |
153 | struct sockaddr *a1; | |
154 | { | |
6db0b3a4 | 155 | |
85bbbfa4 SL |
156 | return (0); |
157 | } | |
158 | ||
159 | /*ARGSUSED*/ | |
160 | null_canon(a1) | |
161 | struct sockaddr *a1; | |
162 | { | |
6db0b3a4 | 163 | |
85bbbfa4 SL |
164 | ; |
165 | } |