Changeset 5284 for source/ariba/communication/networkinfo
- Timestamp:
- Jul 24, 2009, 3:23:11 PM (15 years ago)
- Location:
- source/ariba/communication/networkinfo
- Files:
-
- 1 added
- 2 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; -
source/ariba/communication/networkinfo/AddressInformation.h
r3690 r5284 40 40 #define __ADDRESS_INFORMATION_H 41 41 42 #include <ifaddrs.h>43 42 #include <vector> 44 #include <boost/asio/ip/address.hpp> 45 #include <boost/asio/ip/address_v4.hpp> 43 46 44 #include "ariba/communication/networkinfo/NetworkInterface.h" 47 #include "ariba/communication/modules/network/ip/IPv4Locator.h" 48 49 using std::vector; 50 using ariba::communication::NetworkInterface; 51 using ariba::communication::IPv4Locator; 45 #include "ariba/utility/addressing/addressing.hpp" 52 46 53 47 namespace ariba { 54 48 namespace communication { 55 49 56 typedef vector<IPv4Locator> AddressList; // TODO: make more general, not only ipv4 50 using namespace std; 51 using namespace ariba::addressing; 52 53 /// a list of addresses 54 typedef vector<address_v*> AddressList; 57 55 58 56 class AddressInformation { … … 62 60 63 61 AddressList getAddresses(const NetworkInterface& interface); 64 65 62 }; 66 63
Note:
See TracChangeset
for help on using the changeset viewer.