Re: Detecting link up

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, 18 May 2005, Vaibhav Nivargi wrote:

try looking at the ioctls which mii-tool / ethtool make

regards,
Vaibhav

On 5/18/05, Martin Zwickel <[email protected]> wrote:
On Wed, 18 May 2005 11:35:12 +0100
Filipe Abrantes <[email protected]> bubbled:

Hi all,

I need to detect when an interface (wired ethernet) has link up/down.
Is  there a system signal which is sent when this happens? What is the
best  way to this programatically?

mii-tool?

--
MyExcuse:
Not enough interrupts


Martin Zwickel <[email protected]>
Research & Development

TechnoTrend AG <http://www.technotrend.de>



Cut from some working project........


#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <signal.h>
#include <errno.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <stdint.h>
#include <net/if.h>
#include <netinet/in.h>

typedef uint32_t u32;
typedef uint16_t u16;
typedef uint8_t  u8;

#include <linux/sockios.h>
#include <linux/ethtool.h>

// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= //
//  Get the link status. This returns TRUE if the link is up and FALSE
//  otherwise.
//
int32_t link_stat()
{
    int s;
    struct ifreq ifr;
    struct ethtool_value eth;
    if((s = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP)) == FAIL)
        ERRORS(Socket);
    bzero(&ifr, sizeof(ifr));
    strcpy(ifr.ifr_name, Eth0);
    ifr.ifr_data = (caddr_t) &eth;
    eth.cmd      = ETHTOOL_GLINK;
    if(ioctl(s, SIOCETHTOOL, &ifr) == FAIL)
        ERRORS(Ioctl);
    (void)close(s);
    return (eth.data) ? TRUE:FALSE;
}


ERRORS, TRUE, FALSE, Eth0, FAIL are macros that you should be able
to figure out for yourself. Maybe you don't have bzero() you
can use memset(x, 0x00, n).


Cheers,
Dick Johnson
Penguin : Linux version 2.6.11.9 on an i686 machine (5537.79 BogoMips).
 Notice : All mail here is now cached for review by Dictator Bush.
                 98.36% of all statistics are fiction.
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[Index of Archives]     [Kernel Newbies]     [Netfilter]     [Bugtraq]     [Photo]     [Stuff]     [Gimp]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Video 4 Linux]     [Linux for the blind]     [Linux Resources]
  Powered by Linux