Annotation of 43BSDReno/sbin/XNSrouted/if.c, revision 1.1

1.1     ! root        1: /*
        !             2:  * Copyright (c) 1983 The 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: (1) source distributions retain this entire copyright
        !             7:  * notice and comment, and (2) distributions including binaries display
        !             8:  * the following acknowledgement:  ``This product includes software
        !             9:  * developed by the University of California, Berkeley and its contributors''
        !            10:  * in the documentation or other materials provided with the distribution
        !            11:  * and in all advertising materials mentioning features or use of this
        !            12:  * software. Neither the name of the University nor the names of its
        !            13:  * contributors may be used to endorse or promote products derived
        !            14:  * from this software without specific prior written permission.
        !            15:  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
        !            16:  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
        !            17:  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
        !            18:  *
        !            19:  * static char sccsid[] = "@(#)if.c    5.1 (Berkeley) 6/4/85"; (routed/if.c)
        !            20:  */
        !            21: 
        !            22: #ifndef lint
        !            23: static char sccsid[] = "@(#)if.c       5.2 (Berkeley) 6/1/90";
        !            24: #endif /* not lint */
        !            25: 
        !            26: /*
        !            27:  * Routing Table Management Daemon
        !            28:  */
        !            29: #include "defs.h"
        !            30: 
        !            31: extern struct interface *ifnet;
        !            32: 
        !            33: /*
        !            34:  * Find the interface with address addr.
        !            35:  */
        !            36: struct interface *
        !            37: if_ifwithaddr(addr)
        !            38:        struct sockaddr *addr;
        !            39: {
        !            40:        register struct interface *ifp;
        !            41: 
        !            42: #define        same(a1, a2) \
        !            43:        (bcmp((caddr_t)((a1)->sa_data), (caddr_t)((a2)->sa_data), 14) == 0)
        !            44:        for (ifp = ifnet; ifp; ifp = ifp->int_next) {
        !            45:                if (ifp->int_flags & IFF_REMOTE)
        !            46:                        continue;
        !            47:                if (ifp->int_addr.sa_family != addr->sa_family)
        !            48:                        continue;
        !            49:                if (same(&ifp->int_addr, addr))
        !            50:                        break;
        !            51:                if ((ifp->int_flags & IFF_BROADCAST) &&
        !            52:                    same(&ifp->int_broadaddr, addr))
        !            53:                        break;
        !            54:        }
        !            55:        return (ifp);
        !            56: }
        !            57: 
        !            58: /*
        !            59:  * Find the point-to-point interface with destination address addr.
        !            60:  */
        !            61: struct interface *
        !            62: if_ifwithdstaddr(addr)
        !            63:        struct sockaddr *addr;
        !            64: {
        !            65:        register struct interface *ifp;
        !            66: 
        !            67:        for (ifp = ifnet; ifp; ifp = ifp->int_next) {
        !            68:                if ((ifp->int_flags & IFF_POINTOPOINT) == 0)
        !            69:                        continue;
        !            70:                if (same(&ifp->int_dstaddr, addr))
        !            71:                        break;
        !            72:        }
        !            73:        return (ifp);
        !            74: }
        !            75: 
        !            76: /*
        !            77:  * Find the interface on the network 
        !            78:  * of the specified address.
        !            79:  */
        !            80: struct interface *
        !            81: if_ifwithnet(addr)
        !            82:        register struct sockaddr *addr;
        !            83: {
        !            84:        register struct interface *ifp;
        !            85:        register int af = addr->sa_family;
        !            86:        register int (*netmatch)();
        !            87: 
        !            88:        if (af >= AF_MAX)
        !            89:                return (0);
        !            90:        netmatch = afswitch[af].af_netmatch;
        !            91:        for (ifp = ifnet; ifp; ifp = ifp->int_next) {
        !            92:                if (ifp->int_flags & IFF_REMOTE)
        !            93:                        continue;
        !            94:                if (af != ifp->int_addr.sa_family)
        !            95:                        continue;
        !            96:                if ((*netmatch)(addr, &ifp->int_addr))
        !            97:                        break;
        !            98:        }
        !            99:        return (ifp);
        !           100: }
        !           101: 
        !           102: /*
        !           103:  * Find an interface from which the specified address
        !           104:  * should have come from.  Used for figuring out which
        !           105:  * interface a packet came in on -- for tracing.
        !           106:  */
        !           107: struct interface *
        !           108: if_iflookup(addr)
        !           109:        struct sockaddr *addr;
        !           110: {
        !           111:        register struct interface *ifp, *maybe;
        !           112:        register int af = addr->sa_family;
        !           113:        register int (*netmatch)();
        !           114: 
        !           115:        if (af >= AF_MAX)
        !           116:                return (0);
        !           117:        maybe = 0;
        !           118:        netmatch = afswitch[af].af_netmatch;
        !           119:        for (ifp = ifnet; ifp; ifp = ifp->int_next) {
        !           120:                if (ifp->int_addr.sa_family != af)
        !           121:                        continue;
        !           122:                if (same(&ifp->int_addr, addr))
        !           123:                        break;
        !           124:                if ((ifp->int_flags & IFF_BROADCAST) &&
        !           125:                    same(&ifp->int_broadaddr, addr))
        !           126:                        break;
        !           127:                if (maybe == 0 && (*netmatch)(addr, &ifp->int_addr))
        !           128:                        maybe = ifp;
        !           129:        }
        !           130:        if (ifp == 0)
        !           131:                ifp = maybe;
        !           132:        return (ifp);
        !           133: }

unix.superglobalmegacorp.com

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