Commit | Line | Data |
---|---|---|
85bbbfa4 | 1 | #ifndef lint |
e2f67b08 | 2 | static char sccsid[] = "@(#)af.c 4.15 (Berkeley) %G%"; |
85bbbfa4 SL |
3 | #endif |
4 | ||
7fe7fe74 | 5 | #include "defs.h" |
ecce71aa | 6 | |
85bbbfa4 SL |
7 | /* |
8 | * Address family support routines | |
9 | */ | |
10 | int null_hash(), null_netmatch(), null_output(), | |
a773b026 | 11 | null_portmatch(), null_portcheck(), |
d5568f13 | 12 | null_checkhost(), null_ishost(), null_canon(); |
85bbbfa4 | 13 | int inet_hash(), inet_netmatch(), inet_output(), |
a773b026 | 14 | inet_portmatch(), inet_portcheck(), |
d5568f13 | 15 | inet_checkhost(), inet_ishost(), inet_canon(); |
85bbbfa4 SL |
16 | #define NIL \ |
17 | { null_hash, null_netmatch, null_output, \ | |
a773b026 | 18 | null_portmatch, null_portcheck, null_checkhost, \ |
d5568f13 | 19 | null_ishost, null_canon } |
85bbbfa4 SL |
20 | #define INET \ |
21 | { inet_hash, inet_netmatch, inet_output, \ | |
a773b026 | 22 | inet_portmatch, inet_portcheck, inet_checkhost, \ |
d5568f13 | 23 | inet_ishost, inet_canon } |
85bbbfa4 SL |
24 | |
25 | struct afswitch afswitch[AF_MAX] = | |
26 | { NIL, NIL, INET, INET, NIL, NIL, NIL, NIL, NIL, NIL, NIL }; | |
27 | ||
5562f0a3 MK |
28 | struct sockaddr_in inet_default = { AF_INET, INADDR_ANY }; |
29 | ||
85bbbfa4 SL |
30 | inet_hash(sin, hp) |
31 | register struct sockaddr_in *sin; | |
32 | struct afhash *hp; | |
33 | { | |
34 | ||
68a24a8f | 35 | hp->afh_nethash = inet_netof(sin->sin_addr); |
7fe7fe74 | 36 | hp->afh_hosthash = ntohl(sin->sin_addr.s_addr); |
6db0b3a4 | 37 | hp->afh_hosthash &= 0x7fffffff; |
85bbbfa4 SL |
38 | } |
39 | ||
40 | inet_netmatch(sin1, sin2) | |
41 | struct sockaddr_in *sin1, *sin2; | |
42 | { | |
43 | ||
68a24a8f | 44 | return (inet_netof(sin1->sin_addr) == inet_netof(sin2->sin_addr)); |
85bbbfa4 SL |
45 | } |
46 | ||
47 | /* | |
48 | * Verify the message is from the right port. | |
49 | */ | |
50 | inet_portmatch(sin) | |
c8c4156e | 51 | register struct sockaddr_in *sin; |
85bbbfa4 | 52 | { |
6db0b3a4 | 53 | |
7fe7fe74 SL |
54 | #ifdef COMPAT |
55 | if (ntohs(sin->sin_port) == ntohs(sp->s_port) + 1) | |
56 | return (1); | |
6db0b3a4 | 57 | #endif |
7fe7fe74 | 58 | return (sin->sin_port == sp->s_port); |
85bbbfa4 SL |
59 | } |
60 | ||
a773b026 SL |
61 | /* |
62 | * Verify the message is from a "trusted" port. | |
63 | */ | |
64 | inet_portcheck(sin) | |
7fe7fe74 | 65 | struct sockaddr_in *sin; |
a773b026 | 66 | { |
a773b026 | 67 | |
7fe7fe74 | 68 | return (ntohs(sin->sin_port) <= IPPORT_RESERVED); |
a773b026 SL |
69 | } |
70 | ||
85bbbfa4 SL |
71 | /* |
72 | * Internet output routine. | |
73 | */ | |
7fe7fe74 SL |
74 | inet_output(s, flags, sin, size) |
75 | int s, flags; | |
85bbbfa4 SL |
76 | struct sockaddr_in *sin; |
77 | int size; | |
78 | { | |
85bbbfa4 SL |
79 | struct sockaddr_in dst; |
80 | ||
81 | dst = *sin; | |
82 | sin = &dst; | |
c8c4156e | 83 | if (sin->sin_port == 0) |
7fe7fe74 SL |
84 | sin->sin_port = sp->s_port; |
85 | if (sendto(s, packet, size, flags, sin, sizeof (*sin)) < 0) | |
86 | perror("sendto"); | |
85bbbfa4 SL |
87 | } |
88 | ||
89 | /* | |
0ad851d4 SL |
90 | * Return 1 if the address is believed |
91 | * for an Internet host -- THIS IS A KLUDGE. | |
85bbbfa4 SL |
92 | */ |
93 | inet_checkhost(sin) | |
94 | struct sockaddr_in *sin; | |
95 | { | |
e2f67b08 | 96 | u_long i = ntohl(sin->sin_addr.s_addr); |
49139b80 | 97 | |
d5568f13 MK |
98 | #define IN_BADCLASS(i) (((long) (i) & 0xe0000000) == 0xe0000000) |
99 | ||
49139b80 | 100 | if (IN_BADCLASS(i)) |
5562f0a3 | 101 | return (0); |
49139b80 | 102 | if (i != 0 && (i & 0xff000000) == 0) |
5562f0a3 MK |
103 | return (0); |
104 | return (1); | |
d5568f13 MK |
105 | } |
106 | ||
107 | /* | |
108 | * Return 1 if the address is | |
109 | * for an Internet host, 0 for a network. | |
110 | */ | |
111 | inet_ishost(sin) | |
112 | struct sockaddr_in *sin; | |
113 | { | |
7fe7fe74 | 114 | |
68a24a8f | 115 | return (inet_lnaof(sin->sin_addr) != 0); |
85bbbfa4 SL |
116 | } |
117 | ||
118 | inet_canon(sin) | |
119 | struct sockaddr_in *sin; | |
120 | { | |
7fe7fe74 | 121 | |
85bbbfa4 SL |
122 | sin->sin_port = 0; |
123 | } | |
124 | ||
125 | /*ARGSUSED*/ | |
126 | null_hash(addr, hp) | |
127 | struct sockaddr *addr; | |
128 | struct afhash *hp; | |
129 | { | |
130 | ||
131 | hp->afh_nethash = hp->afh_hosthash = 0; | |
132 | } | |
133 | ||
134 | /*ARGSUSED*/ | |
135 | null_netmatch(a1, a2) | |
136 | struct sockaddr *a1, *a2; | |
137 | { | |
138 | ||
139 | return (0); | |
140 | } | |
141 | ||
142 | /*ARGSUSED*/ | |
7fe7fe74 SL |
143 | null_output(s, f, a1, n) |
144 | int s, f; | |
85bbbfa4 SL |
145 | struct sockaddr *a1; |
146 | int n; | |
147 | { | |
6db0b3a4 | 148 | |
85bbbfa4 SL |
149 | ; |
150 | } | |
151 | ||
152 | /*ARGSUSED*/ | |
153 | null_portmatch(a1) | |
154 | struct sockaddr *a1; | |
155 | { | |
6db0b3a4 | 156 | |
85bbbfa4 SL |
157 | return (0); |
158 | } | |
159 | ||
a773b026 SL |
160 | /*ARGSUSED*/ |
161 | null_portcheck(a1) | |
162 | struct sockaddr *a1; | |
163 | { | |
6db0b3a4 | 164 | |
a773b026 SL |
165 | return (0); |
166 | } | |
167 | ||
d5568f13 MK |
168 | /*ARGSUSED*/ |
169 | null_ishost(a1) | |
170 | struct sockaddr *a1; | |
171 | { | |
172 | ||
173 | return (0); | |
174 | } | |
175 | ||
85bbbfa4 SL |
176 | /*ARGSUSED*/ |
177 | null_checkhost(a1) | |
178 | struct sockaddr *a1; | |
179 | { | |
6db0b3a4 | 180 | |
85bbbfa4 SL |
181 | return (0); |
182 | } | |
183 | ||
184 | /*ARGSUSED*/ | |
185 | null_canon(a1) | |
186 | struct sockaddr *a1; | |
187 | { | |
6db0b3a4 | 188 | |
85bbbfa4 SL |
189 | ; |
190 | } |