Date: Tue, 15 Jul 2003 17:48:21 +0200 From: Tobias Roth <roth@iam.unibe.ch> To: freebsd-questions@freebsd.org Subject: getting arp cache entry reliably Message-ID: <20030715154821.GB10201@speedy.unibe.ch>
next in thread | raw e-mail | index | archive | help
Hi i have the following task to do: i need to get the mac adress of my first upstream router (i.e my default router). there are a number of constraints, however: 1) detection has to be as fast as possible, but 100% reliable 2) i can only use tools from /bin and /sbin, nothing from under /usr. 3) it has to be done from a shell script without any external c hacks. 4) all information i have at this point is the fixed IP adress of the router. right know i am doing this: i configure my interface with an arbitrary ip (any IP from within the RFC 1918 adress space, notably NOT within the same subnet as the router). i cannot just use an ip within the same subnet as the router is because i do not want to disturb the network. next i set my default route to my interface then i ping the router after that, i have an entry in my arp cache which i read with the route command and parse with the sh builtin expr. this looks at follows (my router is 192.168.1.1): ifconfig fxp0 10.11.12.13 ifconfig fxp0 up route add default -interface fxp0 ping -c 5 -t 5 -m 1 -n -q 192.168.1.1 route=` route -n -v get 192.168.1.1 ` macaddr=`expr "//${route}" : ".* 192.168.1.1 \(.*\) fxp0.*10.11.12.13$" ` my problem with the above sequence is: sometimes i get an arp cache entry, sometimes i don't. i've tried varying the -c and -t flags of ping with little success. as there a better way of doing this, or are some other flags to ping more promising? thanks in advance, t.
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20030715154821.GB10201>