Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S262232AbVERO1A (ORCPT ); Wed, 18 May 2005 10:27:00 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S262230AbVEROKc (ORCPT ); Wed, 18 May 2005 10:10:32 -0400 Received: from alog0288.analogic.com ([208.224.222.64]:64898 "EHLO chaos.analogic.com") by vger.kernel.org with ESMTP id S262207AbVERN6W (ORCPT ); Wed, 18 May 2005 09:58:22 -0400 Date: Wed, 18 May 2005 09:57:33 -0400 (EDT) From: "Richard B. Johnson" Reply-To: linux-os@analogic.com To: Vaibhav Nivargi cc: Martin Zwickel , Filipe Abrantes , linux-kernel@vger.kernel.org Subject: Re: Detecting link up In-Reply-To: Message-ID: References: <428B1A60.6030505@inescporto.pt> <20050518134031.53a3243a@phoebee> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed Sender: linux-kernel-owner@vger.kernel.org X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2305 Lines: 91 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 wrote: >> On Wed, 18 May 2005 11:35:12 +0100 >> Filipe Abrantes 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 >> Research & Development >> >> TechnoTrend AG Cut from some working project........ #include #include #include #include #include #include #include #include #include #include #include typedef uint32_t u32; typedef uint16_t u16; typedef uint8_t u8; #include #include // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= // // 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.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 majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/