00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifndef __libutilxx__sella__util__Interface_H__
00010 #define __libutilxx__sella__util__Interface_H__
00011
00012 #include "../../common.h"
00013 #include "InterfaceException.h"
00014 #include "../net/IPAddress.h"
00015
00016 #include <net/if.h>
00017 #include <sys/ioctl.h>
00018 #include <netinet/in.h>
00019
00020 #include <list>
00021 #include <string>
00022
00023 namespace sella {
00024 namespace util {
00025 class Interface;
00026 }
00027 }
00028
00029 class sella::util::Interface {
00030 public:
00031
00032 static const unsigned int ifrFlagMatchDefault = (IFF_UP);
00033 static const unsigned int ifrFlagRejectDefault = (IFF_LOOPBACK);
00034
00035 static void setPromiscous(const std::string &interface, bool on = true) throw (InterfaceException);
00036
00037 static sella::net::IPAddress::shared_list getIPAddresses(const std::string &interface = "", unsigned int ifrFlagMatch = ifrFlagMatchDefault, unsigned int ifrFlagReject = ifrFlagRejectDefault) throw (InterfaceException);
00038 static sella::net::IPAddress getIPAddress(const std::string &interface, int family = AF_INET) throw (InterfaceException);
00039 static std::list<std::string> getNames(unsigned int ifrFlagMatch = ifrFlagMatchDefault, unsigned int ifrFlagReject = ifrFlagRejectDefault) throw (InterfaceException);
00040 static std::list<std::string> getEthernetNames(const unsigned int ifrFlagMatch = ifrFlagMatchDefault, const unsigned int ifrFlagReject = ifrFlagRejectDefault) throw (InterfaceException);
00041 static std::string getMAC(const std::string &interface) throw (InterfaceException);
00042 static std::list<std::string> getMACs(unsigned int ifrFlagMatch = ifrFlagMatchDefault, unsigned int ifrFlagReject = ifrFlagRejectDefault) throw (InterfaceException);
00043
00044 static struct in_addr* getAddr(const std::string &interface, struct in_addr *ip) throw (InterfaceException);
00045 static unsigned int getIndex(const std::string &interface) throw (InterfaceException);
00046 static std::string getName(unsigned int index) throw (InterfaceException);
00047
00048 static unsigned char* convertMAC(unsigned char dst[6], const std::string &mac) throw (InterfaceException);
00049 static std::string& convertMAC(std::string &dst, const unsigned char mac[6], char delim = ':') throw (InterfaceException);
00050
00051 static unsigned char* convertMAC(unsigned char dst[6], const uint64_t mac) throw (InterfaceException);
00052 static uint64_t& convertMAC(uint64_t &dst, const unsigned char mac[6]) throw (InterfaceException);
00053
00054 static std::string& convertMAC(std::string &dst, const uint64_t mac) throw (InterfaceException);
00055 static uint64_t& convertMAC(uint64_t &dst, const std::string &mac) throw (InterfaceException);
00056
00057 static bool isEthernet(const std::string &interface) throw (InterfaceException);
00058
00059 LIBUTIL_API_DEPRECATED static unsigned char* parseMAC(const std::string &mac, unsigned char addr[6]) throw (InterfaceException);
00060 LIBUTIL_API_DEPRECATED static sella::net::IPAddress::shared_list getInterfaceIPAddresses(const std::string &interface = "", unsigned int ifrFlagMatch = ifrFlagMatchDefault, unsigned int ifrFlagReject = ifrFlagRejectDefault) throw (InterfaceException);
00061 LIBUTIL_API_DEPRECATED static std::list<std::string> getInterfaceNames(unsigned int ifrFlagMatch = ifrFlagMatchDefault, unsigned int ifrFlagReject = ifrFlagRejectDefault) throw (InterfaceException);
00062 LIBUTIL_API_DEPRECATED static std::string getInterfaceMAC(const std::string &interface) throw (InterfaceException);
00063 LIBUTIL_API_DEPRECATED static std::list<std::string> getInterfaceMACs(unsigned int ifrFlagMatch = ifrFlagMatchDefault, unsigned int ifrFlagReject = ifrFlagRejectDefault) throw (InterfaceException);
00064 LIBUTIL_API_DEPRECATED static void getInterfaceAddr(const std::string &interface, struct in_addr *ip) throw (InterfaceException);
00065
00066 LIBUTIL_API_DEPRECATED static sella::net::IPAddress::shared_list interfaceIPAddressList(const std::string &interface = std::string(), const unsigned int ifrFlagMatch = ifrFlagMatchDefault, const unsigned int ifrFlagReject = ifrFlagRejectDefault) throw (InterfaceException);
00067 LIBUTIL_API_DEPRECATED static std::list<std::string> interfaceNameList(const unsigned int ifrFlagMatch = ifrFlagMatchDefault, const unsigned int ifrFlagReject = ifrFlagRejectDefault) throw (InterfaceException);
00068 LIBUTIL_API_DEPRECATED static std::list<std::string> interfaceMACList(const unsigned int ifrFlagMatch = ifrFlagMatchDefault, const unsigned int ifrFlagReject = ifrFlagRejectDefault) throw (InterfaceException);
00069 LIBUTIL_API_DEPRECATED static void source_ip(char *interface, struct in_addr *ip) throw (InterfaceException);
00070 };
00071
00072 #endif
00073
00074
00075
00076