File:  [XINU] / xinu / sys / route.c
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs
Tue Apr 24 17:39:04 2018 UTC (8 years, 3 months ago) by root
Branches: xinu, MAIN
CVS tags: xinu-19870308, HEAD
Xinu for VAX

/* route.c - route */

#include <conf.h>
#include <kernel.h>
#include <network.h>

/*------------------------------------------------------------------------
 *  route  -  route a datagram to a given IP address
 *------------------------------------------------------------------------
 */
route(faddr, packet, totlen)
IPaddr	faddr;
struct	epacket	*packet;
int	totlen;
{
	int	result;
	int	dev;
	struct	arpent	*arpptr;
	IPaddr	mynet, destnet;

	/* If IP address is broadcast address for my network, then use	*/
	/* physical broadcast address.  Otherwise, establish a path to	*/
	/* the destination directly or through a gateway		*/

	getnet(mynet);
	netnum(destnet, faddr);
	wait(Net.nmutex);
	/* NOTE: This code uses host 0 as broadcast like 4.2bsd UNIX */
	if ( blkequ(mynet, faddr, IPLEN) ) {
		dev = ETHER;
		blkcopy(packet->ep_hdr.e_dest, EBCAST, EPADLEN);
	} else {
		if (!blkequ(destnet, mynet, IPLEN))
			faddr = Net.gateway;
		arpptr = &Arp.arptab[ getpath(faddr) ];
		if (arpptr->arp_state != AR_RSLVD) {
			arpptr->arp_state = AR_RGATE;
			arpptr = &Arp.arptab[getpath(Net.gateway)];
			if (arpptr->arp_state != AR_RSLVD) {
				panic("route - Cannot reach gateway");
				freebuf(packet);
				signal(Net.nmutex);
				return(SYSERR);
			}
		}
		dev = arpptr->arp_dev;
		blkcopy(packet->ep_hdr.e_dest, arpptr->arp_Ead, EPADLEN);
	}
	result = write(dev, packet, totlen);
	signal(Net.nmutex);
	return(result);
}

unix.superglobalmegacorp.com

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