Annotation of 43BSDTahoe/etc/routed/if.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  * Copyright (c) 1983 Regents of the University of California.
                      3:  * All rights reserved.
                      4:  *
                      5:  * Redistribution and use in source and binary forms are permitted
                      6:  * provided that this notice is preserved and that due credit is given
                      7:  * to the University of California at Berkeley. The name of the University
                      8:  * may not be used to endorse or promote products derived from this
                      9:  * software without specific prior written permission. This software
                     10:  * is provided ``as is'' without express or implied warranty.
                     11:  */
                     12: 
                     13: #ifndef lint
                     14: static char sccsid[] = "@(#)if.c       5.4 (Berkeley) 2/16/88";
                     15: #endif /* not lint */
                     16: 
                     17: /*
                     18:  * Routing Table Management Daemon
                     19:  */
                     20: #include "defs.h"
                     21: 
                     22: extern struct interface *ifnet;
                     23: 
                     24: /*
                     25:  * Find the interface with address addr.
                     26:  */
                     27: struct interface *
                     28: if_ifwithaddr(addr)
                     29:        struct sockaddr *addr;
                     30: {
                     31:        register struct interface *ifp;
                     32: 
                     33: #define        same(a1, a2) \
                     34:        (bcmp((caddr_t)((a1)->sa_data), (caddr_t)((a2)->sa_data), 14) == 0)
                     35:        for (ifp = ifnet; ifp; ifp = ifp->int_next) {
                     36:                if (ifp->int_flags & IFF_REMOTE)
                     37:                        continue;
                     38:                if (ifp->int_addr.sa_family != addr->sa_family)
                     39:                        continue;
                     40:                if (same(&ifp->int_addr, addr))
                     41:                        break;
                     42:                if ((ifp->int_flags & IFF_BROADCAST) &&
                     43:                    same(&ifp->int_broadaddr, addr))
                     44:                        break;
                     45:        }
                     46:        return (ifp);
                     47: }
                     48: 
                     49: /*
                     50:  * Find the point-to-point interface with destination address addr.
                     51:  */
                     52: struct interface *
                     53: if_ifwithdstaddr(addr)
                     54:        struct sockaddr *addr;
                     55: {
                     56:        register struct interface *ifp;
                     57: 
                     58:        for (ifp = ifnet; ifp; ifp = ifp->int_next) {
                     59:                if ((ifp->int_flags & IFF_POINTOPOINT) == 0)
                     60:                        continue;
                     61:                if (same(&ifp->int_dstaddr, addr))
                     62:                        break;
                     63:        }
                     64:        return (ifp);
                     65: }
                     66: 
                     67: /*
                     68:  * Find the interface on the network 
                     69:  * of the specified address.
                     70:  */
                     71: struct interface *
                     72: if_ifwithnet(addr)
                     73:        register struct sockaddr *addr;
                     74: {
                     75:        register struct interface *ifp;
                     76:        register int af = addr->sa_family;
                     77:        register int (*netmatch)();
                     78: 
                     79:        if (af >= af_max)
                     80:                return (0);
                     81:        netmatch = afswitch[af].af_netmatch;
                     82:        for (ifp = ifnet; ifp; ifp = ifp->int_next) {
                     83:                if (ifp->int_flags & IFF_REMOTE)
                     84:                        continue;
                     85:                if (af != ifp->int_addr.sa_family)
                     86:                        continue;
                     87:                if ((*netmatch)(addr, &ifp->int_addr))
                     88:                        break;
                     89:        }
                     90:        return (ifp);
                     91: }
                     92: 
                     93: /*
                     94:  * Find an interface from which the specified address
                     95:  * should have come from.  Used for figuring out which
                     96:  * interface a packet came in on -- for tracing.
                     97:  */
                     98: struct interface *
                     99: if_iflookup(addr)
                    100:        struct sockaddr *addr;
                    101: {
                    102:        register struct interface *ifp, *maybe;
                    103:        register int af = addr->sa_family;
                    104:        register int (*netmatch)();
                    105: 
                    106:        if (af >= af_max)
                    107:                return (0);
                    108:        maybe = 0;
                    109:        netmatch = afswitch[af].af_netmatch;
                    110:        for (ifp = ifnet; ifp; ifp = ifp->int_next) {
                    111:                if (ifp->int_addr.sa_family != af)
                    112:                        continue;
                    113:                if (same(&ifp->int_addr, addr))
                    114:                        break;
                    115:                if ((ifp->int_flags & IFF_BROADCAST) &&
                    116:                    same(&ifp->int_broadaddr, addr))
                    117:                        break;
                    118:                if ((ifp->int_flags & IFF_POINTOPOINT) &&
                    119:                    same(&ifp->int_dstaddr, addr))
                    120:                        break;
                    121:                if (maybe == 0 && (*netmatch)(addr, &ifp->int_addr))
                    122:                        maybe = ifp;
                    123:        }
                    124:        if (ifp == 0)
                    125:                ifp = maybe;
                    126:        return (ifp);
                    127: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.