| 1 | /* if.c 4.9 82/03/09 */ |
| 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 (in.s_addr == ifp->if_addr.s_addr || |
| 49 | (ifp->if_broadaddr.s_addr != 0 && |
| 50 | in.s_addr == ifp->if_broadaddr.s_addr)) |
| 51 | break; |
| 52 | return (ifp); |
| 53 | } |
| 54 | |
| 55 | /*ARGSUSED*/ |
| 56 | struct ifnet * |
| 57 | if_ifonnetof(in) |
| 58 | struct in_addr in; |
| 59 | { |
| 60 | register struct ifnet *ifp; |
| 61 | int net; |
| 62 | |
| 63 | COUNT(IF_IFONNETOF); |
| 64 | net = in.s_net; /* XXX */ |
| 65 | for (ifp = ifnet; ifp; ifp = ifp->if_next) |
| 66 | if (ifp->if_net == net) |
| 67 | break; |
| 68 | return (ifp); |
| 69 | } |
| 70 | |
| 71 | /*ARGSUSED*/ |
| 72 | struct ifnet * |
| 73 | if_gatewayfor(addr) |
| 74 | struct in_addr addr; |
| 75 | { |
| 76 | |
| 77 | COUNT(IF_GATEWAYFOR); |
| 78 | return (0); |
| 79 | } |
| 80 | |
| 81 | struct in_addr |
| 82 | if_makeaddr(net, host) |
| 83 | int net, host; |
| 84 | { |
| 85 | u_long addr; |
| 86 | |
| 87 | if (net < 128) |
| 88 | addr = (net << 24) | host; |
| 89 | else if (net < 65536) |
| 90 | addr = (net << 16) | host; |
| 91 | else |
| 92 | addr = (net << 8) | host; |
| 93 | #ifdef vax |
| 94 | addr = htonl(addr); |
| 95 | #endif |
| 96 | return (*(struct in_addr *)&addr); |
| 97 | } |