19 #ifndef INCLUDE_UTIL_GETLOCALIPS_HPP
20 #define INCLUDE_UTIL_GETLOCALIPS_HPP
26 #include <RCF/Exception.hpp>
27 #include <RCF/util/Platform/OS/BsdSockets.hpp>
31 std::pair<std::string, std::vector<std::string> > getLocalIps()
33 std::vector<char> hostname(80);
34 int ret = gethostname(&hostname[0], hostname.size());
35 int err = Platform::OS::BsdSockets::GetLastError();
38 RCF::Exception(0, err, RCF::RcfSubsystem_Os))(ret)(err);
39 hostent *phe = gethostbyname(&hostname[0]);
40 err = Platform::OS::BsdSockets::GetLastError();
43 RCF::Exception(0, err, RCF::RcfSubsystem_Os))(err);
44 std::vector<std::string> ips;
45 for (
int i = 0; phe->h_addr_list[i] != 0; ++i) {
47 memcpy(&addr, phe->h_addr_list[i],
sizeof( in_addr));
48 ips.push_back(inet_ntoa(addr));
50 return std::make_pair( std::string(&hostname[0]), ips);