Annotation of xinu/sys/route.c, revision 1.1

1.1     ! root        1: /* route.c - route */
        !             2: 
        !             3: #include <conf.h>
        !             4: #include <kernel.h>
        !             5: #include <network.h>
        !             6: 
        !             7: /*------------------------------------------------------------------------
        !             8:  *  route  -  route a datagram to a given IP address
        !             9:  *------------------------------------------------------------------------
        !            10:  */
        !            11: route(faddr, packet, totlen)
        !            12: IPaddr faddr;
        !            13: struct epacket *packet;
        !            14: int    totlen;
        !            15: {
        !            16:        int     result;
        !            17:        int     dev;
        !            18:        struct  arpent  *arpptr;
        !            19:        IPaddr  mynet, destnet;
        !            20: 
        !            21:        /* If IP address is broadcast address for my network, then use  */
        !            22:        /* physical broadcast address.  Otherwise, establish a path to  */
        !            23:        /* the destination directly or through a gateway                */
        !            24: 
        !            25:        getnet(mynet);
        !            26:        netnum(destnet, faddr);
        !            27:        wait(Net.nmutex);
        !            28:        /* NOTE: This code uses host 0 as broadcast like 4.2bsd UNIX */
        !            29:        if ( blkequ(mynet, faddr, IPLEN) ) {
        !            30:                dev = ETHER;
        !            31:                blkcopy(packet->ep_hdr.e_dest, EBCAST, EPADLEN);
        !            32:        } else {
        !            33:                if (!blkequ(destnet, mynet, IPLEN))
        !            34:                        faddr = Net.gateway;
        !            35:                arpptr = &Arp.arptab[ getpath(faddr) ];
        !            36:                if (arpptr->arp_state != AR_RSLVD) {
        !            37:                        arpptr->arp_state = AR_RGATE;
        !            38:                        arpptr = &Arp.arptab[getpath(Net.gateway)];
        !            39:                        if (arpptr->arp_state != AR_RSLVD) {
        !            40:                                panic("route - Cannot reach gateway");
        !            41:                                freebuf(packet);
        !            42:                                signal(Net.nmutex);
        !            43:                                return(SYSERR);
        !            44:                        }
        !            45:                }
        !            46:                dev = arpptr->arp_dev;
        !            47:                blkcopy(packet->ep_hdr.e_dest, arpptr->arp_Ead, EPADLEN);
        !            48:        }
        !            49:        result = write(dev, packet, totlen);
        !            50:        signal(Net.nmutex);
        !            51:        return(result);
        !            52: }

unix.superglobalmegacorp.com

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