I need to check the change in the status of eth connection ( link up and link down ) by program ( using c or perl ). Now I using the keepalive way, but i sometime loose the notification. Inside the messages files I see the kernel notification of 'eth0 link down' and this note are always correct so I looking for a way, maybe a syscall, to check for the eth status.

link|improve this question
feedback

3 Answers

If you want to check the link status (carrier), you can check the file:

$ cat /sys/class/net/eth0/carrier

This will show 1 (link is up) or 0 (link is down).

link|improve this answer
thanks Khaled, I check your note on feodra 8, fedora 10 and redhat 7.3 your answer is ok for the kernel 2.6, but on redhat 7.3 , when I got the kernel 2.4 there isn't the directory /sys. On thi last distro, I look for similar files named carrier but i didn't found it. So my new question became, when to detect the line status on distro using kernel 2.4 ? – enzo2 Dec 3 '10 at 6:58
I don't have any system with a 2.4 kernel. Anyway, I will try to find another way for such systems. – Khaled Dec 3 '10 at 7:39
feedback

Just as a workaround for RH73 (please don't ask me why I have a bunch of RH73 boxes to hand, in 2010):

[madhatta@ms01 madhatta]$ cat /etc/redhat-release 
Red Hat Linux release 7.3 (Valhalla)
[madhatta@ms01 madhatta]$ uname -a
Linux ms01.company.com 2.4.20-30.7.legacysmp #1 SMP Fri Feb 20 10:12:55 PST 2004 i686 unknown
[madhatta@ms01 madhatta]$ sudo mii-tool eth0
eth0: negotiated 100baseTx-FD, link ok
[madhatta@ms01 madhatta]$ 
link|improve this answer
feedback

Thanks MadHatter

I have still considered the use of mii-tool utility, bu unlikely I found one limit, it works only on real device.

mii-tool utility give not valid status for virtual devices , like tun, as required by openvpn.

And this limt also limit it's usage, so I can't use it as a solution wich should works well both with real and virtual devices.

BTW: I'm am enzo2 , tough now I'm connected with a different username.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.