Commit | Line | Data |
---|---|---|
ac76a23d | 1 | /* in.c 4.8 82/10/20 */ |
8473bbab SL |
2 | |
3 | #include "../h/param.h" | |
4 | #include "../h/mbuf.h" | |
5 | #include "../h/protosw.h" | |
6 | #include "../h/socket.h" | |
7 | #include "../h/socketvar.h" | |
fcfe450e BJ |
8 | #include "../netinet/in.h" |
9 | #include "../netinet/in_systm.h" | |
6187f8f4 SL |
10 | #include "../net/if.h" |
11 | #include "../net/route.h" | |
8473bbab SL |
12 | #include "../net/af.h" |
13 | ||
14 | #ifdef INET | |
15 | inet_hash(sin, hp) | |
16 | register struct sockaddr_in *sin; | |
17 | struct afhash *hp; | |
18 | { | |
a8d3bf7f | 19 | |
8473bbab | 20 | hp->afh_nethash = in_netof(sin->sin_addr); |
6e7edb25 BJ |
21 | hp->afh_hosthash = sin->sin_addr.s_addr; |
22 | #if vax || pdp11 || ns16032 | |
23 | hp->afh_hosthash = ntohl((u_long)hp->afh_hosthash); | |
24 | #else | |
8473bbab SL |
25 | } |
26 | ||
27 | inet_netmatch(sin1, sin2) | |
28 | struct sockaddr_in *sin1, *sin2; | |
29 | { | |
a8d3bf7f | 30 | |
8473bbab SL |
31 | return (sin1->sin_addr.s_net == sin2->sin_addr.s_net); |
32 | } | |
33 | ||
34 | /* | |
35 | * Formulate an Internet address from network + host. Used in | |
36 | * building addresses stored in the ifnet structure. | |
37 | */ | |
38 | struct in_addr | |
39 | if_makeaddr(net, host) | |
40 | int net, host; | |
41 | { | |
42 | u_long addr; | |
43 | ||
8473bbab | 44 | if (net < 128) |
6e7edb25 | 45 | addr = (net << IN_CLASSA_NSHIFT) | host; |
8473bbab | 46 | else if (net < 65536) |
6e7edb25 | 47 | addr = (net << IN_CLASSB_NSHIFT) | host; |
8473bbab | 48 | else |
6e7edb25 | 49 | addr = (net << IN_CLASSC_NSHIFT) | host; |
a8d3bf7f | 50 | #ifdef vax || pdp11 || ns16032 |
8473bbab SL |
51 | addr = htonl(addr); |
52 | #endif | |
53 | return (*(struct in_addr *)&addr); | |
54 | } | |
55 | ||
56 | /* | |
a8d3bf7f | 57 | * Return the network number from an internet address. |
8473bbab SL |
58 | */ |
59 | in_netof(in) | |
60 | struct in_addr in; | |
61 | { | |
6e7edb25 | 62 | register u_long i = in.s_addr; |
8473bbab | 63 | |
a8d3bf7f BJ |
64 | #ifdef vax || pdp11 || ns16032 |
65 | i = ntohl(i); | |
66 | #endif | |
67 | if (IN_CLASSA(i)) | |
6e7edb25 | 68 | return (((i)&IN_CLASSA_NET) >> IN_CLASSA_NSHIFT); |
a8d3bf7f | 69 | else if (IN_CLASSB(i)) |
6e7edb25 | 70 | return (((i)&IN_CLASSB_NET) >> IN_CLASSB_NSHIFT); |
a8d3bf7f | 71 | else |
6e7edb25 | 72 | return (((i)&IN_CLASSC_NET) >> IN_CLASSC_NSHIFT); |
8473bbab SL |
73 | } |
74 | ||
ac76a23d | 75 | #ifndef notdef |
8473bbab | 76 | /* |
a8d3bf7f | 77 | * Return the host portion of an internet address. |
8473bbab SL |
78 | */ |
79 | in_lnaof(in) | |
80 | struct in_addr in; | |
81 | { | |
6e7edb25 | 82 | register u_long i = in.s_addr; |
8473bbab | 83 | |
a8d3bf7f BJ |
84 | #ifdef vax || pdp11 || ns16032 |
85 | i = ntohl(i); | |
86 | #endif | |
87 | if (IN_CLASSA(i)) | |
6e7edb25 | 88 | return ((i)&IN_CLASSA_HOST); |
a8d3bf7f | 89 | else if (IN_CLASSB(i)) |
6e7edb25 | 90 | return ((i)&IN_CLASSB_HOST); |
a8d3bf7f | 91 | else |
6e7edb25 | 92 | return ((i)&IN_CLASSC_HOST); |
8473bbab | 93 | } |
ac76a23d | 94 | #endif |
8473bbab SL |
95 | |
96 | /* | |
97 | * Initialize an interface's routing | |
98 | * table entry according to the network. | |
99 | * INTERNET SPECIFIC. | |
100 | */ | |
101 | if_rtinit(ifp, flags) | |
102 | register struct ifnet *ifp; | |
103 | int flags; | |
104 | { | |
105 | struct sockaddr_in sin; | |
106 | ||
8473bbab SL |
107 | if (ifp->if_flags & IFF_ROUTE) |
108 | return; | |
109 | bzero((caddr_t)&sin, sizeof (sin)); | |
110 | sin.sin_family = AF_INET; | |
111 | sin.sin_addr = if_makeaddr(ifp->if_net, 0); | |
a1edc12b | 112 | rtinit((struct sockaddr *)&sin, &ifp->if_addr, flags); |
8473bbab SL |
113 | } |
114 | #endif |