Subject: ifconfig -s when interface is down?
To: None <tech-userlevel@netbsd.org>
From: =?iso-8859-1?q?Gr=E9goire_Sutre?= <gregoire.sutre@labri.fr>
List: tech-userlevel
Date: 11/24/2004 20:59:47
Hello,

I have a question regarding the behavior of `ifconfig -s' which seems
to have changed (on my system) between 1.6.2 and 2.0_RC4.

I was using, under NetBSD 1.6.2, `ifconfig -s ex0' to test whether a
network cable is plugged in before trying to get an IP address by DHCP.

Unfortunately, this does not work anymore under my NetBSD 2.0_RC4 box
(i386) since whenever the interface is down, `ifconfig -s ex0' returns
the same status (true) regardless of the presence of a network cable.

My test is the following:

# ifconfig ex0 down
# if ifconfig -s ex0 ; then echo "coucou" ; fi     // cable plugged
coucou
# if ifconfig -s ex0 ; then echo "coucou" ; fi     // cable unplugged
coucou
# ifconfig ex0 up
# if ifconfig -s ex0 ; then echo "coucou" ; fi     // cable plugged
coucou
# if ifconfig -s ex0 ; then echo "coucou" ; fi     // cable unplugged
#

I cannot check anymore, but I'm almost sure that this was not the case
with 1.6.2 (i.e. `ifconfig -s ex0' returned true if and only if a
network cable was there, even if the interface was down).

So, which one is the normal behavior for `ifconfig -s'?

Is there a better solution to avoid DHCP when no cable is plugged (this
is for a laptop) ?

Many thanks for your help,

Gregoire.