version 1.12.2.1, 2005/01/20 14:10:12
|
version 1.12.2.2, 2005/01/27 13:08:56
|
|
|
*/ | */ |
String _getHostAddress(String hostName) | String _getHostAddress(String hostName) |
{ | { |
String ipAddress; |
// set default address |
|
String ipAddress("127.0.0.1"); |
| |
if (hostName == String::EMPTY) | if (hostName == String::EMPTY) |
hostName = System::getHostName(); | hostName = System::getHostName(); |
| |
if ((ipAddress = System::getHostIP(hostName)) == String::EMPTY) |
struct hostent * phostent; |
|
struct in_addr inaddr; |
|
|
|
if ((phostent = ::gethostbyname((const char *)hostName.getCString())) != NULL) |
{ | { |
// set default address if everything else failed |
::memcpy( &inaddr, phostent->h_addr,4); |
ipAddress = String("127.0.0.1"); |
ipAddress = ::inet_ntoa( inaddr ); |
} | } |
return ipAddress; | return ipAddress; |
} | } |