Commit | Line | Data |
---|---|---|
85bbbfa4 | 1 | #ifndef lint |
a773b026 | 2 | static char sccsid[] = "@(#)af.c 4.2 %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; | |
39 | hp->afh_hosthash = ntohl(sin->sin_addr.s_addr); | |
40 | } | |
41 | ||
42 | inet_netmatch(sin1, sin2) | |
43 | struct sockaddr_in *sin1, *sin2; | |
44 | { | |
45 | ||
46 | return (sin1->sin_addr.s_net == sin2->sin_addr.s_net); | |
47 | } | |
48 | ||
49 | /* | |
50 | * Verify the message is from the right port. | |
51 | */ | |
52 | inet_portmatch(sin) | |
53 | struct sockaddr_in *sin; | |
54 | { | |
55 | int port = ntohs(sin->sin_port); | |
56 | ||
57 | return (port == IPPORT_ROUTESERVER); | |
58 | } | |
59 | ||
a773b026 SL |
60 | /* |
61 | * Verify the message is from a "trusted" port. | |
62 | */ | |
63 | inet_portcheck(sin) | |
64 | struct sockaddr_in *sin; | |
65 | { | |
66 | int port = ntohs(sin->sin_port); | |
67 | ||
68 | return (port <= IPPORT_RESERVED); | |
69 | } | |
70 | ||
85bbbfa4 SL |
71 | /* |
72 | * Internet output routine. | |
73 | */ | |
74 | inet_output(sin, size) | |
75 | struct sockaddr_in *sin; | |
76 | int size; | |
77 | { | |
78 | extern int s; | |
79 | extern char packet[MAXPACKETSIZE]; | |
80 | struct sockaddr_in dst; | |
81 | ||
82 | dst = *sin; | |
83 | sin = &dst; | |
84 | if (sin->sin_port == 0) | |
85 | sin->sin_port = htons(IPPORT_ROUTESERVER); | |
86 | if (send(s, sin, packet, size) < 0) | |
87 | perror("send"); | |
88 | } | |
89 | ||
90 | /* | |
91 | * Return 1 if the address is for an Internet host, | |
92 | * otherwise assume it's a network address (broadcast). | |
93 | */ | |
94 | inet_checkhost(sin) | |
95 | struct sockaddr_in *sin; | |
96 | { | |
97 | extern struct in_addr if_makeaddr(); | |
98 | struct in_addr netaddr; | |
99 | ||
100 | netaddr = if_makeaddr((int)sin->sin_addr.s_net, INADDR_ANY); | |
101 | return (netaddr.s_addr != sin->sin_addr.s_addr); | |
102 | } | |
103 | ||
104 | inet_canon(sin) | |
105 | struct sockaddr_in *sin; | |
106 | { | |
107 | sin->sin_port = 0; | |
108 | } | |
109 | ||
110 | /*ARGSUSED*/ | |
111 | null_hash(addr, hp) | |
112 | struct sockaddr *addr; | |
113 | struct afhash *hp; | |
114 | { | |
115 | ||
116 | hp->afh_nethash = hp->afh_hosthash = 0; | |
117 | } | |
118 | ||
119 | /*ARGSUSED*/ | |
120 | null_netmatch(a1, a2) | |
121 | struct sockaddr *a1, *a2; | |
122 | { | |
123 | ||
124 | return (0); | |
125 | } | |
126 | ||
127 | /*ARGSUSED*/ | |
128 | null_output(a1, n) | |
129 | struct sockaddr *a1; | |
130 | int n; | |
131 | { | |
132 | ; | |
133 | } | |
134 | ||
135 | /*ARGSUSED*/ | |
136 | null_portmatch(a1) | |
137 | struct sockaddr *a1; | |
138 | { | |
139 | return (0); | |
140 | } | |
141 | ||
a773b026 SL |
142 | /*ARGSUSED*/ |
143 | null_portcheck(a1) | |
144 | struct sockaddr *a1; | |
145 | { | |
146 | return (0); | |
147 | } | |
148 | ||
85bbbfa4 SL |
149 | /*ARGSUSED*/ |
150 | null_checkhost(a1) | |
151 | struct sockaddr *a1; | |
152 | { | |
153 | return (0); | |
154 | } | |
155 | ||
156 | /*ARGSUSED*/ | |
157 | null_canon(a1) | |
158 | struct sockaddr *a1; | |
159 | { | |
160 | ; | |
161 | } |