| 1 | /* if.c 4.6 81/12/07 */ |
| 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 | |
| 32 | COUNT(IF_ATTACH); |
| 33 | ifp->if_next = ifnet; |
| 34 | ifnet = ifp; |
| 35 | } |
| 36 | |
| 37 | /*ARGSUSED*/ |
| 38 | struct ifnet * |
| 39 | if_ifwithaddr(in) |
| 40 | struct in_addr in; |
| 41 | { |
| 42 | register struct ifnet *ifp; |
| 43 | |
| 44 | COUNT(IF_IFWITHADDR); |
| 45 | for (ifp = ifnet; ifp; ifp = ifp->if_next) |
| 46 | if (ifp->if_addr.s_addr == in.s_addr) |
| 47 | break; |
| 48 | return (ifp); |
| 49 | } |
| 50 | |
| 51 | /*ARGSUSED*/ |
| 52 | struct ifnet * |
| 53 | if_ifonnetof(in) |
| 54 | struct in_addr in; |
| 55 | { |
| 56 | register struct ifnet *ifp; |
| 57 | int net; |
| 58 | |
| 59 | COUNT(IF_IFONNETOF); |
| 60 | net = in.s_net; /* XXX */ |
| 61 | for (ifp = ifnet; ifp; ifp = ifp->if_next) |
| 62 | if (ifp->if_net == net) |
| 63 | break; |
| 64 | return (ifp); |
| 65 | } |
| 66 | |
| 67 | /*ARGSUSED*/ |
| 68 | struct ifnet * |
| 69 | if_gatewayfor(addr) |
| 70 | struct in_addr addr; |
| 71 | { |
| 72 | |
| 73 | COUNT(IF_GATEWAYFOR); |
| 74 | return (0); |
| 75 | } |
| 76 | |
| 77 | struct in_addr |
| 78 | if_makeaddr(net, host) |
| 79 | int net, host; |
| 80 | { |
| 81 | u_long addr; |
| 82 | |
| 83 | if (net < 128) |
| 84 | addr = (net << 24) | host; |
| 85 | else if (net < 65536) |
| 86 | addr = (net << 16) | host; |
| 87 | else |
| 88 | addr = (net << 8) | host; |
| 89 | addr = htonl(addr); |
| 90 | return (*(struct in_addr *)&addr); |
| 91 | } |