xref: /csrg-svn/sys/net/if.c (revision 5698)
1 /*	if.c	4.8	82/02/03	*/
2 
3 #include "../h/param.h"
4 #include "../h/systm.h"
5 #include "../net/in.h"
6 #include "../net/in_systm.h"
7 #include "../net/if.h"
8 
9 ifinit()
10 {
11 	register struct ifnet *ifp;
12 
13 	for (ifp = ifnet; ifp; ifp = ifp->if_next)
14 		if (ifp->if_init)
15 			(*ifp->if_init)();
16 }
17 
18 ifubareset(uban)
19 	int uban;
20 {
21 	register struct ifnet *ifp;
22 
23 	for (ifp = ifnet; ifp; ifp = ifp->if_next)
24 		if (ifp->if_ubareset)
25 			(*ifp->if_ubareset)(uban);
26 }
27 
28 if_attach(ifp)
29 	struct ifnet *ifp;
30 {
31 	register struct ifnet **p = &ifnet;
32 
33 COUNT(IF_ATTACH);
34 	while (*p)
35 		p = &((*p)->if_next);
36 	*p = ifp;
37 }
38 
39 /*ARGSUSED*/
40 struct ifnet *
41 if_ifwithaddr(in)
42 	struct in_addr in;
43 {
44 	register struct ifnet *ifp;
45 
46 COUNT(IF_IFWITHADDR);
47 	for (ifp = ifnet; ifp; ifp = ifp->if_next)
48 		if (ifp->if_addr.s_addr == in.s_addr)
49 			break;
50 	return (ifp);
51 }
52 
53 /*ARGSUSED*/
54 struct ifnet *
55 if_ifonnetof(in)
56 	struct in_addr in;
57 {
58 	register struct ifnet *ifp;
59 	int net;
60 
61 COUNT(IF_IFONNETOF);
62 	net = in.s_net;			/* XXX */
63 	for (ifp = ifnet; ifp; ifp = ifp->if_next)
64 		if (ifp->if_net == net)
65 			break;
66 	return (ifp);
67 }
68 
69 /*ARGSUSED*/
70 struct ifnet *
71 if_gatewayfor(addr)
72 	struct in_addr addr;
73 {
74 
75 COUNT(IF_GATEWAYFOR);
76 	return (0);
77 }
78 
79 struct in_addr
80 if_makeaddr(net, host)
81 	int net, host;
82 {
83 	u_long addr;
84 
85 	if (net < 128)
86 		addr = (net << 24) | host;
87 	else if (net < 65536)
88 		addr = (net << 16) | host;
89 	else
90 		addr = (net << 8) | host;
91 #ifdef vax
92 	addr = htonl(addr);
93 #endif
94 	return (*(struct in_addr *)&addr);
95 }
96