1.获取本机IP地址列表
int ACE::get_ip_interfaces (size_t &count, ACE_INET_Addr *&addr_array)
ACE_INET_Addr* addr_array; size_t count = 0; if (ACE::get_ip_interfaces(count, addr_array) != 0) return; char address[INET6_ADDRSTRLEN];//可以装下IPv6地址(46),IPv4为INET_ADDRSTRLEN(16) ACE_INET_Addr* addr_array2 = addr_array; while (count--) { addr_array2->addr_to_string(address, sizeof (address)); ACE_OS::printf("%s/n", address); ++addr_array2; } delete[] addr_array;//记得要delete[] addr_array;
2.获取本机主机名称
int ACE_OS::hostname (char name[], size_t maxnamelen)
int ACE_OS::hostname (wchar_t name[], size_t maxnamelen)
char host_name[MAXHOSTNAMELEN];//MAXHOSTNAMELEN(256) ACE_OS::hostname(host_name, sizeof (host_name));