From 3306c0c4d4513e73e1ca1ab60922ca02dc86a870 Mon Sep 17 00:00:00 2001 From: malaterre Date: Thu, 6 Jan 2005 19:10:07 +0000 Subject: [PATCH] ENH: update test for tesing MAC adrress --- Testing/TestUtil.cxx | 7 ++++-- src/gdcmUtil.cxx | 52 ++++++++++++++++++++++++-------------------- src/gdcmUtil.h | 6 +++-- 3 files changed, 37 insertions(+), 28 deletions(-) diff --git a/Testing/TestUtil.cxx b/Testing/TestUtil.cxx index b61aa4cd..24c285d5 100644 --- a/Testing/TestUtil.cxx +++ b/Testing/TestUtil.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: TestUtil.cxx,v $ Language: C++ - Date: $Date: 2004/12/07 13:39:32 $ - Version: $Revision: 1.5 $ + Date: $Date: 2005/01/06 19:10:07 $ + Version: $Revision: 1.6 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -43,5 +43,8 @@ int TestUtil(int , char * []) if( gdcm::Util::DicomStringEqual(d,ref) ) return 1; + // MAC Adress + std::cout << "Mac Address:" << gdcm::Util::GetMACAddress() << std::endl; + return 0; } diff --git a/src/gdcmUtil.cxx b/src/gdcmUtil.cxx index 589609b0..8c980a31 100644 --- a/src/gdcmUtil.cxx +++ b/src/gdcmUtil.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmUtil.cxx,v $ Language: C++ - Date: $Date: 2005/01/06 18:53:02 $ - Version: $Revision: 1.73 $ + Date: $Date: 2005/01/06 19:10:07 $ + Version: $Revision: 1.74 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -639,28 +639,32 @@ long GetMacAddrSys ( u_char *addr) return -1; } -//std::string Util::GetMACAddress() -//{ -// // This is a rip from: http://cplus.kompf.de/macaddr.html for Linux, HPUX and AIX -// // and http://tangentsoft.net/wskfaq/examples/src/snmpmac.cpp for windows version -// long stat; -// int i; -// u_char addr[6]; -// -// stat = mac_addr_sys( addr); -// if (0 == stat) -// { -// printf( "MAC address = "); -// for (i=0; i<6; ++i) { -// printf("%2.2x", addr[i]); -// } -// printf( "\n"); -// } -// else { -// fprintf( stderr, "can't get MAC address\n"); -// exit( 1); -// } -//} +std::string Util::GetMACAddress() +{ + // This is a rip from: http://cplus.kompf.de/macaddr.html for Linux, HPUX and AIX + // and http://tangentsoft.net/wskfaq/examples/src/snmpmac.cpp for windows version + long stat; + u_char addr[6]; + std::string macaddr; + + stat = GetMacAddrSys( addr); + if (0 == stat) + { + //printf( "MAC address = "); + for (int i=0; i<6; ++i) + { + //printf("%2.2x", addr[i]); + macaddr += Format("%2.2x", addr[i]); + } + // printf( "\n"); + return macaddr; + } + else + { + //printf( "No MAC address !\n" ); + return ""; + } +} /** * \ingroup Util diff --git a/src/gdcmUtil.h b/src/gdcmUtil.h index 85013ce4..4d44df60 100644 --- a/src/gdcmUtil.h +++ b/src/gdcmUtil.h @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmUtil.h,v $ Language: C++ - Date: $Date: 2005/01/05 15:19:42 $ - Version: $Revision: 1.46 $ + Date: $Date: 2005/01/06 19:10:07 $ + Version: $Revision: 1.47 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -57,6 +57,8 @@ public: static std::string CreateUniqueUID(const std::string& root = ""); static bool IsCurrentProcessorBigEndian(); + static std::string GetMACAddress(); + private: static std::string GetIPAddress(); //Do not expose this method }; -- 2.49.0