From owner-freebsd-questions@FreeBSD.ORG Thu Apr 1 18:56:06 2010 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id B6E171065670 for ; Thu, 1 Apr 2010 18:56:06 +0000 (UTC) (envelope-from korvus@comcast.net) Received: from mx04.pub.collaborativefusion.com (mx04.pub.collaborativefusion.com [206.210.72.84]) by mx1.freebsd.org (Postfix) with ESMTP id 824AA8FC16 for ; Thu, 1 Apr 2010 18:56:06 +0000 (UTC) Received: from [192.168.2.164] ([206.210.89.202]) by mx04.pub.collaborativefusion.com (StrongMail Enterprise 4.1.1.4(4.1.1.4-47689)); Thu, 01 Apr 2010 15:09:09 -0400 X-VirtualServerGroup: Default X-MailingID: 00000::00000::00000::00000::::33 X-SMHeaderMap: mid="X-MailingID" X-Destination-ID: freebsd-questions@freebsd.org X-SMFBL: ZnJlZWJzZC1xdWVzdGlvbnNAZnJlZWJzZC5vcmc= Message-ID: <4BB4EC44.2070804@comcast.net> Date: Thu, 01 Apr 2010 14:56:04 -0400 From: Steve Polyack User-Agent: Mozilla/5.0 (X11; U; FreeBSD amd64; en-US; rv:1.9.1.7) Gecko/20100311 Thunderbird/3.0.1 MIME-Version: 1.0 To: Peter Steele References: <7B9397B189EB6E46A5EE7B4C8A4BB7CB3B65FC5D@MBX03.exg5.exghost.com> In-Reply-To: <7B9397B189EB6E46A5EE7B4C8A4BB7CB3B65FC5D@MBX03.exg5.exghost.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: "freebsd-questions@freebsd.org" Subject: Re: Testing ethernet interface status X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 01 Apr 2010 18:56:06 -0000 On 04/01/10 14:21, Peter Steele wrote: > What's the best what to test the status of an Ethernet interface programmatically? We've been using this code similar to this: > > struct ifmediareq ifmr; > memset(&ifmr, 0, sizeof(ifmr)); > strcpy(ifmr.ifm_name, "nfe0"); > ioctl(sockfd, SIOCGIFMEDIA, (caddr_t)&ifmr) > > and then checking the value of ifmr.ifm_status& IFM_ACTIVE. We've found that every once in a while this code will return a false positive, indicating that the interface has gone offline when in fact it has not. > > So, is there a more reliable call to test if an Ethernet interface has gone offline? > I was going to suggest that you look at the ifconfig(8) source code, but then I did so myself - it looks like you're doing it pretty much exactly how they are. I've never noticed ifconfig(8) returning an incorrect value, not to say it's not possible. Are you sure that nothing is causing interface state resets? i.e. mismatched duplex/speed settings between the FreeBSD machine and the switch? Have you checked dmesg(8) for logs of interface state changes? You can also check the output of 'netstat -i' to check for interface errors.