protocol change; byte swap those fields which need it; also add
[unix-history] / usr / src / sbin / routed / af.c
CommitLineData
85bbbfa4 1#ifndef lint
55d340a4 2static char sccsid[] = "@(#)af.c 4.11 (Berkeley) %G%";
85bbbfa4
SL
3#endif
4
7fe7fe74 5#include "defs.h"
ecce71aa 6
85bbbfa4
SL
7/*
8 * Address family support routines
9 */
10int null_hash(), null_netmatch(), null_output(),
a773b026
SL
11 null_portmatch(), null_portcheck(),
12 null_checkhost(), null_canon();
85bbbfa4 13int 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
25struct afswitch afswitch[AF_MAX] =
26 { NIL, NIL, INET, INET, NIL, NIL, NIL, NIL, NIL, NIL, NIL };
27
28inet_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);
7fe7fe74 34 hp->afh_hosthash = ntohl(sin->sin_addr.s_addr);
6db0b3a4 35 hp->afh_hosthash &= 0x7fffffff;
85bbbfa4
SL
36}
37
38inet_netmatch(sin1, sin2)
39 struct sockaddr_in *sin1, *sin2;
40{
41
68a24a8f 42 return (inet_netof(sin1->sin_addr) == inet_netof(sin2->sin_addr));
85bbbfa4
SL
43}
44
45/*
46 * Verify the message is from the right port.
47 */
48inet_portmatch(sin)
c8c4156e 49 register struct sockaddr_in *sin;
85bbbfa4 50{
6db0b3a4 51
7fe7fe74
SL
52#ifdef COMPAT
53 if (ntohs(sin->sin_port) == ntohs(sp->s_port) + 1)
54 return (1);
6db0b3a4 55#endif
7fe7fe74 56 return (sin->sin_port == sp->s_port);
85bbbfa4
SL
57}
58
a773b026
SL
59/*
60 * Verify the message is from a "trusted" port.
61 */
62inet_portcheck(sin)
7fe7fe74 63 struct sockaddr_in *sin;
a773b026 64{
a773b026 65
7fe7fe74 66 return (ntohs(sin->sin_port) <= IPPORT_RESERVED);
a773b026
SL
67}
68
85bbbfa4
SL
69/*
70 * Internet output routine.
71 */
7fe7fe74
SL
72inet_output(s, flags, sin, size)
73 int s, flags;
85bbbfa4
SL
74 struct sockaddr_in *sin;
75 int size;
76{
85bbbfa4
SL
77 struct sockaddr_in dst;
78
79 dst = *sin;
80 sin = &dst;
c8c4156e 81 if (sin->sin_port == 0)
7fe7fe74
SL
82 sin->sin_port = sp->s_port;
83 if (sendto(s, packet, size, flags, sin, sizeof (*sin)) < 0)
84 perror("sendto");
85bbbfa4
SL
85}
86
87/*
0ad851d4
SL
88 * Return 1 if the address is believed
89 * for an Internet host -- THIS IS A KLUDGE.
85bbbfa4
SL
90 */
91inet_checkhost(sin)
92 struct sockaddr_in *sin;
93{
7fe7fe74 94
68a24a8f 95 return (inet_lnaof(sin->sin_addr) != 0);
85bbbfa4
SL
96}
97
98inet_canon(sin)
99 struct sockaddr_in *sin;
100{
7fe7fe74 101
85bbbfa4
SL
102 sin->sin_port = 0;
103}
104
105/*ARGSUSED*/
106null_hash(addr, hp)
107 struct sockaddr *addr;
108 struct afhash *hp;
109{
110
111 hp->afh_nethash = hp->afh_hosthash = 0;
112}
113
114/*ARGSUSED*/
115null_netmatch(a1, a2)
116 struct sockaddr *a1, *a2;
117{
118
119 return (0);
120}
121
122/*ARGSUSED*/
7fe7fe74
SL
123null_output(s, f, a1, n)
124 int s, f;
85bbbfa4
SL
125 struct sockaddr *a1;
126 int n;
127{
6db0b3a4 128
85bbbfa4
SL
129 ;
130}
131
132/*ARGSUSED*/
133null_portmatch(a1)
134 struct sockaddr *a1;
135{
6db0b3a4 136
85bbbfa4
SL
137 return (0);
138}
139
a773b026
SL
140/*ARGSUSED*/
141null_portcheck(a1)
142 struct sockaddr *a1;
143{
6db0b3a4 144
a773b026
SL
145 return (0);
146}
147
85bbbfa4
SL
148/*ARGSUSED*/
149null_checkhost(a1)
150 struct sockaddr *a1;
151{
6db0b3a4 152
85bbbfa4
SL
153 return (0);
154}
155
156/*ARGSUSED*/
157null_canon(a1)
158 struct sockaddr *a1;
159{
6db0b3a4 160
85bbbfa4
SL
161 ;
162}