From 0f243f28c416aad65e9ae946e1c95c8c9f474051 Mon Sep 17 00:00:00 2001 From: asv Date: Fri, 28 Jul 2006 10:15:48 +0000 Subject: [PATCH] Fix for bug SWP12997: implemented method get_adip() on Win32 and improved method get_uname(). --- src/Utils/Utils_Identity.cxx | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/src/Utils/Utils_Identity.cxx b/src/Utils/Utils_Identity.cxx index 48694e8a9..cb15d5aca 100644 --- a/src/Utils/Utils_Identity.cxx +++ b/src/Utils/Utils_Identity.cxx @@ -83,16 +83,36 @@ const char* duplicate( const char *const str ) ; const char* get_uname( void ) { - static std::string hostName(MAX_COMPUTERNAME_LENGTH + 1, 0); - static DWORD nSize = hostName.length() + 1; - static int res = GetComputerName(&hostName[0], &nSize); + static std::string hostName(256, 0); + static DWORD nSize = hostName.length(); + static int res = ::GetComputerNameEx(ComputerNameDnsFullyQualified, &hostName[0], &nSize); ASSERT( res ); return hostName.c_str(); } const char* get_adip( void ) { - return get_uname(); + //#include + //#include + //static GUID sType = SVCID_HOSTNAME; + //static CSADDR_INFO* ips = new CSADDR_INFO[8]; // in case multiple IP addresses are returned + //static DWORD nSize = 1024; + //static std::string uname = get_uname(); + //static int res = ::GetAddressByName( NS_DEFAULT, &sType, &uname[0], 0, 0, 0, ips, &nSize, 0, 0 ); + //if ( res ) + // return ips[0].LocalAddr.lpSockaddr->sa_data; + + static hostent* he = ::gethostbyname( get_uname() ); + if ( he && he->h_addr_list && he->h_length >0 ) { + static char str[16]; + unsigned i1 = (unsigned char)he->h_addr_list[0][0]; + unsigned i2 = (unsigned char)he->h_addr_list[0][1]; + unsigned i3 = (unsigned char)he->h_addr_list[0][2]; + unsigned i4 = (unsigned char)he->h_addr_list[0][3]; + sprintf ( str, "%03u.%03u.%03u.%03u", i1, i2, i3, i4 ); + return str; + } + return ""; } const char* const get_pwname( void ) -- 2.39.2