|
|
1.1 root 1: /* getpath.c - getpath */
2:
3: #include <conf.h>
4: #include <kernel.h>
5: #include <proc.h>
6: #include <network.h>
7:
8: /*------------------------------------------------------------------------
9: * getpath - find a path (route table entry) for a given IP address
10: *------------------------------------------------------------------------
11: */
12: getpath(faddr)
13: IPaddr faddr;
14: {
15: int i;
16: int arindex; /* route table entry index */
17: int mypid; /* local copy of my process id */
18: IPaddr myaddr; /* my IP address */
19: PStype ps;
20: register struct arpent *arpptr;
21: register struct arppak *apacptr;
22: struct epacket *packet, *mkarp();
23:
24: wait(Arp.arpsem);
25: arpptr = &Arp.arptab[ arindex = arpfind(faddr) ];
26: if (arpptr->arp_state != AR_ALLOC) {
27: signal(Arp.arpsem);
28: return(arindex);
29: }
30:
31: /* Use ARP to obtain and record IP-to-Ether binding */
32:
33: getaddr(myaddr);
34: mypid = getpid();
35: for (i=0 ; i < AR_RTRY ; i++) {
36: packet = mkarp(EP_ARP, AR_REQ, myaddr, faddr);
37: blkcopy(Arp.arpwant, faddr, AR_PLEN);
38: disable(ps);
39: Arp.arppid = mypid;
40: recvclr();
41: write(ETHER, packet, EMINPAK);
42: restore(ps);
43: if (recvtim(AR_TIME) == OK)
44: break;
45: }
46: Arp.arppid = BADPID;
47: signal(Arp.arpsem);
48: return(arindex);
49: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.