00001 /* 00002 * File: NetInterface.h 00003 * Author: morgenro 00004 * 00005 * Created on 12. November 2009, 14:57 00006 */ 00007 00008 #ifndef IBRCOMMON_NETINTERFACE_H 00009 #define IBRCOMMON_NETINTERFACE_H 00010 00011 #include "ibrcommon/net/NetAddress.h" 00012 #include "ibrcommon/thread/Mutex.h" 00013 00014 #include <iostream> 00015 #include <netinet/in.h> 00016 #include <netlink/netlink.h> 00017 #include <netlink/attr.h> 00018 #include <list> 00019 00020 /* Move to a better place */ 00021 #include "ibrcommon/net/ieee802154.h" 00022 #include "ibrcommon/net/nl802154.h" 00023 00024 namespace ibrcommon 00025 { 00026 class NetInterface 00027 { 00028 public: 00029 NetInterface(std::string interface); 00030 virtual ~NetInterface(); 00031 00032 const std::list<NetAddress> getAddressList() const; 00033 const std::list<NetAddress> getBroadcastList() const; 00034 00035 const std::string getAddress() const; 00036 const NetAddress getAddress(const NetAddress::ADDR_TYPE type) const; 00037 const NetAddress getBroadcast(const NetAddress::ADDR_TYPE type) const; 00038 00039 void getAddress(struct in_addr *ret) const; 00040 void getAddress(struct ieee802154_addr *ret) const; 00041 00042 bool operator<(const NetInterface&) const; 00043 bool operator==(const NetInterface&) const; 00044 00045 const std::string toString() const; 00046 00047 private: 00048 class NetLinkWrapper 00049 { 00050 public: 00051 NetLinkWrapper(); 00052 ~NetLinkWrapper(); 00053 00054 const std::list<NetAddress> getAddressList(const std::string interface) const; 00055 const std::list<NetAddress> getBroadcastList(const std::string interface) const; 00056 00057 private: 00058 mutable ibrcommon::Mutex _mutex; 00059 struct nl_handle *_handle; 00060 struct nl_cache *_link_cache; 00061 struct nl_cache *_addr_cache; 00062 }; 00063 00064 static NetLinkWrapper _nlwrapper; 00065 std::string _interface; 00066 }; 00067 } 00068 00069 #endif /* _NETINTERFACE_H */ 00070
1.7.1