>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     a...@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:
_______________________________________________
freebsd-bugs@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-bugs
To unsubscribe, send any mail to "freebsd-bugs-unsubscr...@freebsd.org"

Reply via email to