Commit | Line | Data |
---|---|---|
85bbbfa4 SL |
1 | #ifndef lint |
2 | static char sccsid[] = "@(#)af.c 4.1 %G%"; | |
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(), | |
16 | null_portmatch(), null_checkhost(), null_canon(); | |
17 | int inet_hash(), inet_netmatch(), inet_output(), | |
18 | inet_portmatch(), inet_checkhost(), inet_canon(); | |
19 | #define NIL \ | |
20 | { null_hash, null_netmatch, null_output, \ | |
21 | null_portmatch, null_checkhost, null_canon } | |
22 | #define INET \ | |
23 | { inet_hash, inet_netmatch, inet_output, \ | |
24 | inet_portmatch, inet_checkhost, inet_canon } | |
25 | ||
26 | struct afswitch afswitch[AF_MAX] = | |
27 | { NIL, NIL, INET, INET, NIL, NIL, NIL, NIL, NIL, NIL, NIL }; | |
28 | ||
29 | inet_hash(sin, hp) | |
30 | register struct sockaddr_in *sin; | |
31 | struct afhash *hp; | |
32 | { | |
33 | ||
34 | hp->afh_nethash = sin->sin_addr.s_net; | |
35 | hp->afh_hosthash = ntohl(sin->sin_addr.s_addr); | |
36 | } | |
37 | ||
38 | inet_netmatch(sin1, sin2) | |
39 | struct sockaddr_in *sin1, *sin2; | |
40 | { | |
41 | ||
42 | return (sin1->sin_addr.s_net == sin2->sin_addr.s_net); | |
43 | } | |
44 | ||
45 | /* | |
46 | * Verify the message is from the right port. | |
47 | */ | |
48 | inet_portmatch(sin) | |
49 | struct sockaddr_in *sin; | |
50 | { | |
51 | int port = ntohs(sin->sin_port); | |
52 | ||
53 | return (port == IPPORT_ROUTESERVER); | |
54 | } | |
55 | ||
56 | /* | |
57 | * Internet output routine. | |
58 | */ | |
59 | inet_output(sin, size) | |
60 | struct sockaddr_in *sin; | |
61 | int size; | |
62 | { | |
63 | extern int s; | |
64 | extern char packet[MAXPACKETSIZE]; | |
65 | struct sockaddr_in dst; | |
66 | ||
67 | dst = *sin; | |
68 | sin = &dst; | |
69 | if (sin->sin_port == 0) | |
70 | sin->sin_port = htons(IPPORT_ROUTESERVER); | |
71 | if (send(s, sin, packet, size) < 0) | |
72 | perror("send"); | |
73 | } | |
74 | ||
75 | /* | |
76 | * Return 1 if the address is for an Internet host, | |
77 | * otherwise assume it's a network address (broadcast). | |
78 | */ | |
79 | inet_checkhost(sin) | |
80 | struct sockaddr_in *sin; | |
81 | { | |
82 | extern struct in_addr if_makeaddr(); | |
83 | struct in_addr netaddr; | |
84 | ||
85 | netaddr = if_makeaddr((int)sin->sin_addr.s_net, INADDR_ANY); | |
86 | return (netaddr.s_addr != sin->sin_addr.s_addr); | |
87 | } | |
88 | ||
89 | inet_canon(sin) | |
90 | struct sockaddr_in *sin; | |
91 | { | |
92 | sin->sin_port = 0; | |
93 | } | |
94 | ||
95 | /*ARGSUSED*/ | |
96 | null_hash(addr, hp) | |
97 | struct sockaddr *addr; | |
98 | struct afhash *hp; | |
99 | { | |
100 | ||
101 | hp->afh_nethash = hp->afh_hosthash = 0; | |
102 | } | |
103 | ||
104 | /*ARGSUSED*/ | |
105 | null_netmatch(a1, a2) | |
106 | struct sockaddr *a1, *a2; | |
107 | { | |
108 | ||
109 | return (0); | |
110 | } | |
111 | ||
112 | /*ARGSUSED*/ | |
113 | null_output(a1, n) | |
114 | struct sockaddr *a1; | |
115 | int n; | |
116 | { | |
117 | ; | |
118 | } | |
119 | ||
120 | /*ARGSUSED*/ | |
121 | null_portmatch(a1) | |
122 | struct sockaddr *a1; | |
123 | { | |
124 | return (0); | |
125 | } | |
126 | ||
127 | /*ARGSUSED*/ | |
128 | null_checkhost(a1) | |
129 | struct sockaddr *a1; | |
130 | { | |
131 | return (0); | |
132 | } | |
133 | ||
134 | /*ARGSUSED*/ | |
135 | null_canon(a1) | |
136 | struct sockaddr *a1; | |
137 | { | |
138 | ; | |
139 | } |