title: Best way to do RAW socket programming involving Java
body: <p>I have some existing C code that uses ICMP raw sockets to do Ping and I need to use this code in Java as Java does not support ICMP packages. When I wrap the code in JNI and call it, the C code fails to obtain the socket when doing:</p>
  
  <p>socket(AF_INET, SOCK_RAW, 1);</p>
  
  <p>I guess that Java has dropped some privileges that disables the use of raw socket from the Java process. This I must find a solution to.</p>
  
  <p>I have observed the following:</p>
  
  <ul>
  <li>If I write a C program and call that from Java using Runtime the forked code may open the socket.</li>
  <li>If I run this native code from Eclipse it also runs nicely. I guess this comes from the fact that Eclipse has been started from eclipse.exe, and not from java.exe.</li>
  </ul>
  
  <p>This means that I could solve my problem by choosing one of these two strategies, but I like neither. Are there any other ways that I could get Java to accept that the JNI code is opening this socket? </p>
  
  <p>Edit: 
  The more I look into this problem I figure that it must be a windows 7 related issue with how Java is being started. </p>
  
  <p>It also appears that if you get windows to behave or if you are on some other platform than Windows the method InetAddress.isReachable() could be used as well.</p>