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.
Asked
Active
Viewed 1,668 times
2 Answers
2
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).

Khaled
- 36,533
- 8
- 72
- 99
-
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 ? – enzo1959 Dec 03 '10 at 06: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 03 '10 at 07:39
0
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]$

MadHatter
- 79,770
- 20
- 184
- 232