- Timestamp:
- Jul 24, 2009, 3:23:11 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
source/ariba/communication/networkinfo/AddressInformation.cpp
r3690 r5284 39 39 #include "AddressInformation.h" 40 40 41 #include <ifaddrs.h> 42 43 #include <boost/asio/ip/address.hpp> 44 #include <boost/asio/ip/address_v4.hpp> 45 41 46 namespace ariba { 42 47 namespace communication { 48 49 using namespace ariba::addressing; 43 50 44 51 AddressInformation::AddressInformation(){ … … 52 59 AddressList retlist; 53 60 54 //55 61 // gather transport addresses 56 //57 58 62 struct ifaddrs* ifap; 59 63 getifaddrs( &ifap ); 60 64 61 65 for( struct ifaddrs* p = ifap; p != NULL; p=p->ifa_next ){ 66 67 // no name set? ->continue 62 68 if( interface.name.compare(string(p->ifa_name)) != 0 ) continue; 63 69 64 // TODO: currently only handle IPv470 // handle IPv4 entry 65 71 struct sockaddr* addr = p->ifa_addr; 66 if( addr->sa_family != AF_INET ) continue; 72 if( addr->sa_family == AF_INET ) { 73 // get address 74 const struct sockaddr_in& ipv4 = (const struct sockaddr_in&)*addr; 75 boost::asio::ip::address_v4::bytes_type bytes; 76 for( int i=0; i<4; i++ ) 77 bytes[i] = (ipv4.sin_addr.s_addr >> (24-i*8)) & 0xff; 67 78 68 const struct sockaddr_in& ipv4 = (const struct sockaddr_in&)*addr; 69 boost::asio::ip::address_v4::bytes_type bytes; 70 for( int i=0; i<4; i++ ) 71 bytes[i] = (ipv4.sin_addr.s_addr >> (24-i*8)) & 0xff; 72 73 boost::asio::ip::address boost_addr = boost::asio::ip::address_v4( bytes ); 74 retlist.push_back( IPv4Locator::fromString(boost_addr.to_string()) ); 79 // add ipv4 address 80 boost::asio::ip::address boost_addr = boost::asio::ip::address_v4( bytes ); 81 retlist.push_back( vcapsule<address_v>( ip_address(boost_addr) ) ); 82 } 75 83 } 76 84 77 85 freeifaddrs( ifap ); 78 79 //80 // TODO: gather further addresses like MAC etc.81 //82 86 83 87 return retlist;
Note:
See TracChangeset
for help on using the changeset viewer.