uint64_t system_hostid( void ) { #if FOUNDATION_PLATFORM_ANDROID //Not implemented yet, see https://code.google.com/p/libjingle/source/browse/trunk/talk/base/ifaddrs-android.cc return 0; #else struct ifaddrs* ifaddr; struct ifaddrs* ifa; uint64_t hostid = 0; #if !FOUNDATION_PLATFORM_APPLE struct ifreq buffer; int sock = socket( PF_INET, SOCK_DGRAM, 0 ); #endif if( getifaddrs( &ifaddr ) == 0 ) { for( ifa = ifaddr; ifa && !hostid; ifa = ifa->ifa_next ) { if( string_equal_substr( ifa->ifa_name, "lo", 2 ) ) continue; #if FOUNDATION_PLATFORM_APPLE #else memset( &buffer, 0, sizeof( buffer ) ); string_copy( buffer.ifr_name, ifa->ifa_name, sizeof( buffer.ifr_name ) ); hostid = _system_hostid_lookup( sock, &buffer ); #endif } freeifaddrs( ifaddr ); } #if !FOUNDATION_PLATFORM_APPLE else { memset( &buffer, 0, sizeof( buffer ) ); strcpy( buffer.ifr_name, "eth0" ); hostid = _system_hostid_lookup( sock, &buffer ); } close( sock ); #endif return hostid; #endif }
uint64_t system_hostid( void ) { struct ifaddrs* ifaddr; struct ifaddrs* ifa; uint64_t hostid = 0; #if !FOUNDATION_PLATFORM_APPLE struct ifreq buffer; int sock = socket( PF_INET, SOCK_DGRAM, 0 ); #endif if( getifaddrs( &ifaddr ) == 0 ) { for( ifa = ifaddr; ifa && !hostid; ifa = ifa->ifa_next ) { if( string_equal_substr( ifa->ifa_name, "lo", 2 ) ) continue; #if FOUNDATION_PLATFORM_APPLE #else memset( &buffer, 0, sizeof( buffer ) ); string_copy( buffer.ifr_name, ifa->ifa_name, sizeof( buffer.ifr_name ) ); hostid = _system_hostid_lookup( sock, &buffer ); #endif } freeifaddrs( ifaddr ); } #if !FOUNDATION_PLATFORM_APPLE else { memset( &buffer, 0, sizeof( buffer ) ); strcpy( buffer.ifr_name, "eth0" ); hostid = _system_hostid_lookup( sock, &buffer ); } close( sock ); #endif return hostid; }