]> Creatis software - gdcm.git/blobdiff - src/gdcmUtil.cxx
in order to be able to use fearlessly copy-paste group-elem are now called
[gdcm.git] / src / gdcmUtil.cxx
index dee613e57bf53ca2684c370ace1c49586e2944f7..0f121c26635a1f948b7e92ff4a8b3b7c4abc7cee 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmUtil.cxx,v $
   Language:  C++
-  Date:      $Date: 2005/01/17 13:55:26 $
-  Version:   $Revision: 1.100 $
+  Date:      $Date: 2005/01/17 17:26:55 $
+  Version:   $Revision: 1.106 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
 
 // For GetMACAddress
 #ifdef _WIN32
-#include <snmp.h>
-#include <conio.h>
+   #include <snmp.h>
+   #include <conio.h>
 #else
-#include <unistd.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/types.h>
+   #include <unistd.h>
+   #include <stdlib.h>
+   #include <string.h>
+   #include <sys/types.h>
 #endif
 
 // How do I do that in CMake ?
 #ifdef __APPLE__
-#define HAVE_SA_LEN
-#define CMAKE_HAVE_NET_IF_DL_H
-#define CMAKE_HAVE_NETINET_IN_H
-#define CMAKE_HAVE_NET_IF_H
+   #define HAVE_SA_LEN
 #endif //APPLE
 
 #ifdef CMAKE_HAVE_SYS_IOCTL_H
-#include <sys/ioctl.h>  // For SIOCGIFCONF on Linux
+   #include <sys/ioctl.h>  // For SIOCGIFCONF on Linux
 #endif
 #ifdef CMAKE_HAVE_SYS_SOCKET_H
-#include <sys/socket.h>
+   #include <sys/socket.h>
 #endif
 #ifdef CMAKE_HAVE_SYS_SOCKIO_H
-#include <sys/sockio.h>  // For SIOCGIFCONF on SunOS
+   #include <sys/sockio.h>  // For SIOCGIFCONF on SunOS
 #endif
 #ifdef CMAKE_HAVE_NET_IF_H
-#include <net/if.h>
+   #include <net/if.h>
 #endif
 #ifdef CMAKE_HAVE_NETINET_IN_H
-#include <netinet/in.h>   //For IPPROTO_IP
+   #include <netinet/in.h>   //For IPPROTO_IP
 #endif
 #ifdef CMAKE_HAVE_NET_IF_DL_H
-#include <net/if_dl.h>
+   #include <net/if_dl.h>
 #endif
-#ifdef __sun
-//#if defined(CMAKE_HAVE_NET_IF_ARP_H) && defined(__sun)
-// This is absolutely necesseray on SunOS
-#include <net/if_arp.h>
+#if defined(CMAKE_HAVE_NET_IF_ARP_H) && defined(__sun)
+   // This is absolutely necesseray on SunOS
+   #include <net/if_arp.h>
 #endif
 
 namespace gdcm 
@@ -438,7 +434,8 @@ int GetMacAddrSys ( unsigned char *addr )
    ret = m_Query(ASN_RFC1157_GETNEXTREQUEST, &varBindList, &errorStatus,
                  &errorIndex);
 //   printf("# of adapters in this system : %i\n",
-//          varBind[0].value.asnValue.number); varBindList.len = 2;
+//          varBind[0].value.asnValue.number);
+   varBindList.len = 2;
 
    // Copy in the OID of ifType, the type of interface
    SNMP_oidcpy(&varBind[0].name, &MIB_ifEntryType);
@@ -477,13 +474,6 @@ int GetMacAddrSys ( unsigned char *addr )
                                MIB_ifMACEntAddr.idLength);
             if ( !ret && varBind[1].value.asnValue.address.stream != NULL )
             {
-               if ( varBind[1].value.asnType != ASN_RFC1155_IPADDRESS )
-               {
-                   // Ignore all dial-up networking adapters
-                   std::cerr << "Interface #" << j << " is not an IP adress\n";
-                   continue;
-               }
-                  
                if ( (varBind[1].value.asnValue.address.stream[0] == 0x44)
                  && (varBind[1].value.asnValue.address.stream[1] == 0x45)
                  && (varBind[1].value.asnValue.address.stream[2] == 0x53)
@@ -506,7 +496,6 @@ int GetMacAddrSys ( unsigned char *addr )
                   std::cerr << "Interface #" << j << " is a NULL address\n";
                   continue;
                }
-
                memcpy( addr, varBind[1].value.asnValue.address.stream, 6);
             }
          }
@@ -648,6 +637,9 @@ int GetMacAddrSys ( unsigned char *addr )
    }
    close(sd);
 #endif
+   /* Not implemented platforms */
+   perror("There was a configuration problem on your plateform");
+   memset(addr,0,6);
    return -1;
 #endif //__sun
 }
@@ -660,17 +652,16 @@ std::string Util::GetMACAddress()
    // http://groups-beta.google.com/group/comp.unix.solaris/msg/ad36929d783d63be
    // http://bdn.borland.com/article/0,1410,26040,00.html
    unsigned char addr[6];
+   std::string macaddr;
    int stat = GetMacAddrSys(addr);
-
    if (0 == stat)
    {
-      std::string macaddr = "";
       for (int i=0; i<6; ++i) 
       {
-         //macaddr += Format("%2.2x", addr[i]);
-         if(i)
-            macaddr += ".";
-         macaddr += Format("%i", (int)addr[i]);
+         macaddr += Format("%2.2x", addr[i]);
+         //if(i) macaddr += ".";
+         //macaddr += Format("%i", (int)addr[i]);
       }
       return macaddr;
    }