CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Feb 2012
    Posts
    4

    Java & Windows (7): Reliably getting IPv4 netmask?

    I've run into a known bug with Java 6 on Windows. My understanding is that the normal way to get the netmask is to look up the network prefix length and do some bit shifts. The problem is that on Windows the prefix length is often returned incorrectly, so we get a 128 when we should get a 24 or 20.

    At http://stackoverflow.com/questions/1...ask-using-java, it is suggested to put -Djava.net.preferIPv4Stack=true on the Java command line. Unfortunately, on Windows 7, adding that as either a VM parameter or on the Java command line seems to have no effect.

    (a) Does anyone know any OTHER work-arounds for this problem that might still work on Windows 7?

    (b) Alternatively, is there an entirely different way to get the netmask that is reliable?

    Thanks!

  2. #2
    Join Date
    May 2006
    Location
    UK
    Posts
    4,473

    Re: Java & Windows (7): Reliably getting IPv4 netmask?

    Cross posted here
    Posting code? Use code tags like this: [code]...Your code here...[/code]
    Click here for examples of Java Code

  3. #3
    Join Date
    Feb 2012
    Posts
    4

    Re: Java & Windows (7): Reliably getting IPv4 netmask?

    Quote Originally Posted by keang View Post
    Cross posted here
    Yeah, sorry about that. I didn't before know the rule about cross-posting. Here's the complete list:
    http://stackoverflow.com/questions/9...g-ipv4-netmask
    http://www.codeguru.com/forum/showthread.php?t=521196
    https://forums.oracle.com/forums/thr...47643&tstart=0
    http://www.coderanch.com/t/567601/so...ly-getting-IPv

    I think this is a hard question, so I'm trying to increase my odds of getting ANY answer. I'm worried that there may be no solution to this problem, because I'm running into a bug in Java itself.

  4. #4
    Join Date
    Feb 2012
    Posts
    4

    Re: Java & Windows (7): Reliably getting IPv4 netmask?

    Oops. Can't figure out how to edit a post, so here's a correction to one of the URLs:
    http://stackoverflow.com/questions/9...g-ipv4-netmask

  5. #5
    Join Date
    Feb 2012
    Posts
    4

    Re: Java & Windows (7): Reliably getting IPv4 netmask?

    This answer worked. I needed to put this line of code first in my main method:

    System.setProperty("java.net.preferIPv4Stack","true");

    I don't know why putting it on the command line didn't take, but this worked.

  6. #6
    Join Date
    May 2006
    Location
    UK
    Posts
    4,473

    Re: Java & Windows (7): Reliably getting IPv4 netmask?

    Thanks for posting the answer.
    Posting code? Use code tags like this: [code]...Your code here...[/code]
    Click here for examples of Java Code

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured