Changeset 10848 for trunk/FACT++
- Timestamp:
- 05/27/11 11:39:10 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/Dim.cc
r10657 r10848 8 8 #include "Dim.h" 9 9 10 /* 10 11 #include <netdb.h> 11 12 #include <sys/types.h> 12 13 #include <sys/socket.h> 13 14 #include <arpa/inet.h> 15 */ 16 #include <boost/asio.hpp> 14 17 15 18 #include <iostream> … … 31 34 string Dim::GetLocalIp(const string &dns) 32 35 { 36 using namespace boost::asio; 37 using namespace boost::asio::ip; 38 39 cout << "Trying to resolve local IP address..." << endl; 40 41 boost::system::error_code ec; 42 43 boost::asio::io_service io_service; 44 45 udp::socket socket(io_service); 46 47 udp::resolver resolver(io_service); 48 udp::resolver::query query(dns, "0"); 49 udp::resolver::iterator iterator = resolver.resolve(query, ec); 50 if (ec) 51 { 52 cout << "WARNING - Failure in name-resolution of '" << dns << ":0': "; 53 cout << ec.message() << " (" << ec << ")" << endl; 54 return dns; 55 } 56 57 for (; iterator != udp::resolver::iterator(); ++iterator) 58 { 59 udp::endpoint endpoint = *iterator; 60 socket.connect(endpoint, ec); 61 if (ec) 62 { 63 cout << "WARNING - connect to '" << dns << ":0' failed: "; 64 cout << ec.message() << " (" << ec << ")" << endl; 65 continue; 66 } 67 68 const string addr = socket.local_endpoint().address().to_v4().to_string(); 69 cout << "Setting DIM_HOST_NODE=" << addr << endl; 70 return addr; 71 } 72 73 return dns; 74 75 /* 33 76 struct addrinfo hints, *servinfo, *p; 34 77 … … 86 129 87 130 return dns; 131 */ 88 132 } 89 133
Note:
See TracChangeset
for help on using the changeset viewer.