2008-11-09 20:31:59     How to detect if eth0 is down or up?

Document created by Aaronwu Employee on Aug 8, 2013
Version 1Show Document
  • View in full screen mode

2008-11-09 20:31:59     How to detect if eth0 is down or up?

Sai Yan Wang (CHINA)

Message: 64891   

 

Hi all,

 

    I have search all , and cann't find any useful information about this question.May be someone else ask before.

 

     I  am using RTL with blackfin 537 ,and the uClinux version is Linux-2.6.19.3-ADI-2007R1.1-svn.

 

    I want to detect if the wire is connected to network card. And below code doesn't work:

 

---------------------------------------------------------------------------------------------------------------------

 

        struct ifreq  ifr;

        struct ethtool_value edata;

 

       if((skfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0)

           goto ERROUT2;

 

       memset(&ifr, 0, sizeof(ifr));

       edata.cmd = ETHTOOL_GLINK;

       strncpy(ifr.ifr_name, "eth0", sizeof(ifr.ifr_name)-1);

       ifr.ifr_data = (char *) &edata;

 

       if(ioctl(skfd, SIOCETHTOOL, &ifr) == -1)

       {

             printf("error\n");

             goto ERROUT1;

       }

      if(edata.data)

      {

               .................

      }

-------------------------------------------------------------------------------------------------------------------------------

 

This code prints "error" all the time.Is there something should configure in kernel to make it work?

 

and if there are another ways to detect it?

 

All your reply  will be appreciated!

QuoteReplyEditDelete

 

 

2008-11-09 23:06:36     Re: How to detect if eth0 is down or up?

Mike Frysinger (UNITED STATES)

Message: 64896   

 

ethtool isnt supported in 2007R1

 

you can try parsing /proc/net/route

QuoteReplyEditDelete

 

 

2008-11-09 23:24:04     Re: How to detect if eth0 is down or up?

Aaron Zhong (CHINA)

Message: 64898   

 

Try this:

 

http://www.myfaq.com.cn/2005September/2005-09-13/201141.html

QuoteReplyEditDelete

 

 

2008-11-10 03:00:29     Re: How to detect if eth0 is down or up?

Sai Yan Wang (CHINA)

Message: 64907   

 

Frysinger, i cat /proc/net/route,but there seems no difference.

 

when line up

 

root:~> cat /proc/net/route

Iface    Destination    Gateway             Flags        RefCnt    Use  Metric   Mask          MTU  Window   IRTT

eth0    0001A8C0      00000000         0001           0             0          0         00FFFFFF    0        0              0

 

when line down

 

root:~> cat /proc/net/route

Iface      Destination    Gateway           Flags         RefCnt    Use   Metric   Mask          MTU  Window  IRTT

eth0      0001A8C0      00000000       0001            0             0          0         00FFFFFF  0         0               0

QuoteReplyEditDelete

 

 

2008-11-10 03:11:32     Re: How to detect if eth0 is down or up?

Sai Yan Wang (CHINA)

Message: 64909   

 

Try this:

 

http://www.myfaq.com.cn/2005September/2005-09-13/201141.html

 

---

 

Aaron,thank you for your reply.  I also test  these codes the passage mentioned, but do not work too.

 

root:~> ./test2

ETHTOOL_GLINK failed: Operation not supported

SIOCGMIIPHY on eth0 failed: Operation not supported

Could not determine status

root:~> ./test3 eth0

linktest: Operation not supported

QuoteReplyEditDelete

 

 

2008-11-10 03:14:41     Re: How to detect if eth0 is down or up?

Sai Yan Wang (CHINA)

Message: 64910   

 

is there any other way? or i have to build ethtool into 2007R1?

QuoteReplyEditDelete

 

 

2008-11-10 09:15:25     Re: How to detect if eth0 is down or up?

Mike Frysinger (UNITED STATES)

Message: 64932   

 

are you sure it's actually down ?

 

you can look at the ifconfig.c code to figure out how that program does it

QuoteReplyEditDelete

 

 

2008-11-10 09:15:55     Re: How to detect if eth0 is down or up?

Mike Frysinger (UNITED STATES)

Message: 64933   

 

backporting any code from a newer release to an older release is not supported.  you'd be on your own.

Attachments

    Outcomes