From owner-freebsd-questions@FreeBSD.ORG Tue Jul 15 08:48:25 2003 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id BF7FE37B448 for ; Tue, 15 Jul 2003 08:48:25 -0700 (PDT) Received: from mailhub01.unibe.ch (mailhub01.unibe.ch [130.92.9.52]) by mx1.FreeBSD.org (Postfix) with ESMTP id 7A6C043FFB for ; Tue, 15 Jul 2003 08:48:24 -0700 (PDT) (envelope-from roth@iam.unibe.ch) Received: from localhost (localhost [127.0.0.1]) by mailhub01.unibe.ch (Postfix) with ESMTP id 3139925BA02 for ; Tue, 15 Jul 2003 17:48:23 +0200 (MEST) Received: from mailhub01.unibe.ch ([127.0.0.1]) by localhost (mailhub01 [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 16309-01-78 for ; Tue, 15 Jul 2003 17:48:22 +0200 (MEST) Received: from asterix.unibe.ch (asterix.unibe.ch [130.92.64.4]) by mailhub01.unibe.ch (Postfix) with ESMTP id 5881A25BA10 for ; Tue, 15 Jul 2003 17:48:22 +0200 (MEST) Received: from speedy.unibe.ch (speedy [130.92.64.35]) by asterix.unibe.ch (8.11.6+Sun/8.11.6) with ESMTP id h6FFmMK22658 for ; Tue, 15 Jul 2003 17:48:22 +0200 (MET DST) Received: (from roth@localhost) by speedy.unibe.ch (8.11.6+Sun/8.10.2) id h6FFmLf10236 for freebsd-questions@freebsd.org; Tue, 15 Jul 2003 17:48:21 +0200 (MEST) Date: Tue, 15 Jul 2003 17:48:21 +0200 From: Tobias Roth To: freebsd-questions@freebsd.org Message-ID: <20030715154821.GB10201@speedy.unibe.ch> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.4i X-Operating-System: SunOS speedy 5.8 Generic_108528-16 sun4u sparc SUNW,Ultra-80 X-Virus-checked: by University of Berne Subject: getting arp cache entry reliably X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 15 Jul 2003 15:48:26 -0000 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.