Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 2 Mar 2011 11:34:52 GMT
From:      Alex Hayward <xelah-freebsd-pr@xelah.com>
To:        freebsd-gnats-submit@FreeBSD.org
Subject:   misc/155186: False exception throw by NetworkInterface.isUp() (and probably others)
Message-ID:  <201103021134.p22BYqFL079922@red.freebsd.org>
Resent-Message-ID: <201103021140.p22BeBv9074090@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         155186
>Category:       misc
>Synopsis:       False exception throw by NetworkInterface.isUp() (and probably others)
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Mar 02 11:40:11 UTC 2011
>Closed-Date:
>Last-Modified:
>Originator:     Alex Hayward
>Release:        8.2-PRERELEASE
>Organization:
Ticketable Ltd
>Environment:
FreeBSD magnus.xelah.com 8.2-PRERELEASE FreeBSD 8.2-PRERELEASE #38: Thu Jan 27 12:11:49 GMT 2011     alex@magnus.xelah.com:/usr/obj/usr/src/sys/MAGNUS  amd64

>Description:
NetworkInterface.isUp() can throw a SocketException when there was in fact no error. This breaks, for example, JGroups.

getFlags in /usr/ports/java/openjdk7/work/openjdk/jdk/src/solaris/native/java/net/NetworkInterface.c returns if2.ifr_flags where if2 is a struct ifreq. Callers expect a negative (int) result on error, a positive one otherwise. ifr_flags is a short and the top bit can be set of multi-cast capable interfaces. This remains negative when cast to an int and the caller believes an error occurred. An exception is thrown based on whatever errno happens to be.

My JDK port version is openjdk-7.0.122
>How-To-Repeat:
Run this (from JGroups):

import java.net.*;
import java.util.*;

public class test {
    public static void main(String[] argv) throws SocketException {
        InetAddress address=null ;

        try {
            Enumeration intfs=NetworkInterface.getNetworkInterfaces();
            while(intfs.hasMoreElements()) {
                NetworkInterface intf=(NetworkInterface)intfs.nextElement();
                if(intf.isUp()) {
                    //address=getAddress(intf, AddressScope.NON_LOOPBACK) ;
                    //System.err.println(address);
                }
            }
        } catch (SocketException e) {
            e.printStackTrace();
        }
    }
}


>Fix:
Change the last statement of getFlags to 'return ((int) if2.ifr_flags) & 0xffff;'

>Release-Note:
>Audit-Trail:
>Unformatted:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201103021134.p22BYqFL079922>