xref: /csrg-svn/sys/net/if.c (revision 5104)
1 /*	if.c	4.4	81/11/29	*/
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 /*ARGSUSED*/
10 struct ifnet *
11 if_ifwithaddr(in)
12 	struct in_addr in;
13 {
14 	register struct ifnet *ifp;
15 
16 COUNT(IF_IFWITHADDR);
17 	for (ifp = ifnet; ifp; ifp = ifp->if_next)
18 		if (ifp->if_addr.s_addr == in.s_addr)
19 			break;
20 	return (ifp);
21 }
22 
23 /*ARGSUSED*/
24 struct ifnet *
25 if_ifonnetof(in)
26 	struct in_addr in;
27 {
28 	register struct ifnet *ifp;
29 	int net;
30 
31 COUNT(IF_IFONNETOF);
32 	net = in.s_net;			/* XXX */
33 	for (ifp = ifnet; ifp; ifp = ifp->if_next)
34 		if (ifp->if_net == net)
35 			break;
36 	return (ifp);
37 }
38 
39 /*ARGSUSED*/
40 struct ifnet *
41 if_gatewayfor(addr)
42 	struct in_addr addr;
43 {
44 
45 COUNT(IF_GATEWAYFOR);
46 	return (0);
47 }
48 
49 struct in_addr
50 if_makeaddr(net, host)
51 	int net, host;
52 {
53 	u_long addr;
54 
55 	if (net < 128)
56 		addr = (host << 8) | net;
57 	else if (net < 65536)
58 		addr = (host << 16) | net;
59 	else
60 		addr = (host << 24) | net;
61 	addr = htonl(addr);
62 	return (*(struct in_addr *)&addr);
63 }
64