55 {
56 names.push_back (
"localhost");
57 names.push_back (
"127.0.0.1");
58
59 boost::system::error_code ec;
60 string hn = host_name (ec);
61 if (ec.value() != boost::system::errc::success) {
62 cerr <<
"unable to retrieve host name: " << ec.message() << endl;
63 }
64 else {
66 if (hn.find ('.') != string::npos) {
67 names.push_back (hn.substr (0,hn.find(
'.')));
68 }
69 }
70
71 ifaddrs *ifap = 0;
72 if (::getifaddrs (&ifap) == 0) {
73 for (ifaddrs *p_if = ifap; p_if != 0; p_if = p_if->ifa_next) {
74 if (p_if->ifa_addr != 0 &&
75 p_if->ifa_addr->sa_family == AF_INET &&
76 (p_if->ifa_flags & IFF_UP) == IFF_UP) {
77 sockaddr_in *ifaddr = reinterpret_cast<sockaddr_in *>(p_if->ifa_addr);
78 int32_t in_addr = ntohl(ifaddr->sin_addr.s_addr);
79
80 if (in_addr != 0) {
82 addrs.push_back (ifa);
83 }
84 }
85 }
86 ::freeifaddrs (ifap);
87 }
88 else {
89 cerr <<
"unable to query local ip interfaces" << endl;
91 }
92 }