You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by hi...@apache.org on 2009/02/18 16:46:01 UTC

svn commit: r745544 - /harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/luni/shared/netif.c

Author: hindessm
Date: Wed Feb 18 15:46:01 2009
New Revision: 745544

URL: http://svn.apache.org/viewvc?rev=745544&view=rev
Log:
Minor fixes to make these functions work on unix when IPv6 is not available.
This code really needs quite a bit of work - there is lots of platform
specific code that probably should be moved to the platform specific
directories or even to portlib.

Modified:
    harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/luni/shared/netif.c

Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/luni/shared/netif.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/luni/shared/netif.c?rev=745544&r1=745543&r2=745544&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/luni/shared/netif.c (original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/luni/shared/netif.c Wed Feb 18 15:46:01 2009
@@ -819,12 +819,15 @@
      32 interfaces.  If this turns out not to be big enough then we expand the buffer to be able to support another
      32 interfaces and try again.  We do this until the result indicates that the result fit into the buffer provided */
   /* we need  socket to do the ioctl so create one */
-  socketP =
-    socket (AF_INET6, SOCK_DGRAM, 0);
+  socketP = socket (preferIPv4Stack(env) ? AF_INET : AF_INET6, SOCK_DGRAM, 0);
   if (socketP < 0)
     {
-      throwJavaNetSocketException (env, HYPORT_ERROR_SOCKET_NORECOVERY);
-	   return NULL;
+      socketP = socket (AF_INET, SOCK_DGRAM, 0);
+      if (socketP < 0)
+        {
+          throwJavaNetSocketException (env, HYPORT_ERROR_SOCKET_NORECOVERY);
+          return NULL;
+        }
     }
 
   for (;;)
@@ -992,14 +995,15 @@
                       break;
                     }
                 }
-				ipv6 = fopen("/proc/net/if_inet6", "r");
-              while(fscanf(ipv6, "%4x%4x%4x%4x%4x%4x%4x%4x %x %x %x %x %s\n", &oct6[0], &oct6[1], &oct6[2], &oct6[3], &oct6[4], &oct6[5], &oct6[6], &oct6[7],
-              		&index6, &other, &scope, &other, ifname6) != EOF) {
-              		if(strncmp(ifc.ifc_req[counter].ifr_name, ifname6, IFNAMSIZ) == 0) {
-              				numAddresses++;
-              			}
-               }
-				fclose(ipv6);
+	      if ((ipv6 = fopen("/proc/net/if_inet6", "r"))) {
+                while(fscanf(ipv6, "%4x%4x%4x%4x%4x%4x%4x%4x %x %x %x %x %s\n", &oct6[0], &oct6[1], &oct6[2], &oct6[3], &oct6[4], &oct6[5], &oct6[6], &oct6[7],
+                             &index6, &other, &scope, &other, ifname6) != EOF) {
+                  if(strncmp(ifc.ifc_req[counter].ifr_name, ifname6, IFNAMSIZ) == 0) {
+                    numAddresses++;
+                  }
+                }
+                fclose(ipv6);
+              }
 
               /* allocate space for the addresses */
               interfaces[currentAdapterIndex].numberAddresses = numAddresses;
@@ -1058,21 +1062,22 @@
                       currentIPAddressIndex++;
                     }
 
-              ipv6 = fopen("/proc/net/if_inet6", "r");
-              while(fscanf(ipv6, "%4x%4x%4x%4x%4x%4x%4x%4x %x %x %x %x %s\n", &oct6[0], &oct6[1], &oct6[2], &oct6[3], &oct6[4], &oct6[5], &oct6[6], &oct6[7],
-              	&index6, &other, &scope, &other, ifname6) != EOF) {
-              	if(strncmp(ifc.ifc_req[counter].ifr_name, ifname6, IFNAMSIZ) == 0) {
-              		sprintf(addr6, "%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x", oct6[0], oct6[1], oct6[2], oct6[3], oct6[4], oct6[5], oct6[6], oct6[7]);
-              		inet_pton(AF_INET6, addr6, 
-              			(void *)(&interfaces[currentAdapterIndex].addresses[currentIPAddressIndex].addr.in6Addr));
-
-    	              interfaces[currentAdapterIndex].
-       	             addresses[currentIPAddressIndex].length = sizeof (struct in6_addr);
-                       interfaces[currentAdapterIndex].addresses[currentIPAddressIndex].scope = scope;
-   				         currentIPAddressIndex++;
-              			}
-               }
-			fclose(ipv6);
+	      if ((ipv6 = fopen("/proc/net/if_inet6", "r"))) {
+                while(fscanf(ipv6, "%4x%4x%4x%4x%4x%4x%4x%4x %x %x %x %x %s\n", &oct6[0], &oct6[1], &oct6[2], &oct6[3], &oct6[4], &oct6[5], &oct6[6], &oct6[7],
+                             &index6, &other, &scope, &other, ifname6) != EOF) {
+                  if(strncmp(ifc.ifc_req[counter].ifr_name, ifname6, IFNAMSIZ) == 0) {
+                    sprintf(addr6, "%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x", oct6[0], oct6[1], oct6[2], oct6[3], oct6[4], oct6[5], oct6[6], oct6[7]);
+                    inet_pton(AF_INET6, addr6, 
+                              (void *)(&interfaces[currentAdapterIndex].addresses[currentIPAddressIndex].addr.in6Addr));
+
+                    interfaces[currentAdapterIndex].
+                      addresses[currentIPAddressIndex].length = sizeof (struct in6_addr);
+                    interfaces[currentAdapterIndex].addresses[currentIPAddressIndex].scope = scope;
+                    currentIPAddressIndex++;
+                  }
+                }
+                fclose(ipv6);
+              }
 
 #endif
 /* we mean to increment the outside counter here as we want to skip the next entry as it is for the same interface