axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sa...@apache.org
Subject svn commit: r551513 - /webservices/axis2/trunk/c/util/src/platforms/unix/uuid_gen_unix.c
Date Thu, 28 Jun 2007 09:22:21 GMT
Author: sahan
Date: Thu Jun 28 02:22:21 2007
New Revision: 551513

URL: http://svn.apache.org/viewvc?view=rev&rev=551513
Log:
Fixing a bug in get_mac_addr logic ("eth0" was hardcoded)

Modified:
    webservices/axis2/trunk/c/util/src/platforms/unix/uuid_gen_unix.c

Modified: webservices/axis2/trunk/c/util/src/platforms/unix/uuid_gen_unix.c
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/util/src/platforms/unix/uuid_gen_unix.c?view=diff&rev=551513&r1=551512&r2=551513
==============================================================================
--- webservices/axis2/trunk/c/util/src/platforms/unix/uuid_gen_unix.c (original)
+++ webservices/axis2/trunk/c/util/src/platforms/unix/uuid_gen_unix.c Thu Jun 28 02:22:21
2007
@@ -212,25 +212,50 @@
 axutil_uuid_get_mac_addr()
 {
     struct ifreq ifr;
+    struct ifreq *IFR;
+    struct ifconf ifc;
     struct sockaddr *sa;
     int s = 0;
     int i = 0;
     char *buffer = NULL;
+    char buf[1024];
+    int ok = AXIS2_FALSE;
 
 
     if ((s = socket(PF_INET, SOCK_DGRAM, 0)) < 0)
         return NULL;
-    sprintf(ifr.ifr_name, "eth0");
-    if (ioctl(s, SIOCGIFHWADDR, &ifr) < 0)
+
+    ifc.ifc_len = sizeof(buf);
+    ifc.ifc_buf = buf;
+    ioctl(s, SIOCGIFCONF, &ifc);
+
+    IFR = ifc.ifc_req;
+
+    for(i = ifc.ifc_len/sizeof(struct ifreq); --i >=0; IFR++)
     {
-        close(s);
-        return NULL;
+        strcpy(ifr.ifr_name, IFR->ifr_name);
+    
+        /*sprintf(ifr.ifr_name, "eth0");*/
+        if (ioctl(s, SIOCGIFFLAGS, &ifr) == 0)
+        {
+            if(!(ifr.ifr_flags & IFF_LOOPBACK))
+            {
+                
+                if (ioctl(s, SIOCGIFHWADDR, &ifr) == 0)
+                {
+                    ok = AXIS2_TRUE;
+                    break;
+                }
+            }
+        }
+    }
+    if(ok)
+    {
+        buffer = (char*)malloc(6 * sizeof(char));
+        sa = (struct sockaddr *) & ifr.ifr_addr;
+        for (i = 0; i < 6; i++)
+            buffer[i] = (unsigned char)(sa->sa_data[i] & 0xff);
     }
-    buffer = (char*)malloc(6 * sizeof(char));
-
-    sa = (struct sockaddr *) & ifr.ifr_addr;
-    for (i = 0; i < 6; i++)
-        buffer[i] = (unsigned char)(sa->sa_data[i] & 0xff);
     close(s);
     return buffer;
 }
@@ -304,8 +329,8 @@
 char * AXIS2_CALL
 axutil_uuid_get_mac_addr()
 {
-	char hostname[MAXHOSTNAMELEN];
-	char *data_ptr;
+    char hostname[MAXHOSTNAMELEN];
+    char *data_ptr;
     struct hostent *he;
     struct arpreq ar;
     struct sockaddr_in *sa;



---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org


Mime
View raw message