9 #ifndef __libutilxx__sella__util__Interface_H__
10 #define __libutilxx__sella__util__Interface_H__
12 #include "../../common.h"
13 #include "InterfaceException.h"
14 #include "../net/IPAddress.h"
17 #include <sys/ioctl.h>
18 #include <netinet/in.h>
32 static const unsigned int ifrFlagMatchDefault = (IFF_UP);
33 static const unsigned int ifrFlagRejectDefault = (IFF_LOOPBACK);
35 static void setPromiscous(
const std::string &interface,
bool on =
true)
throw (InterfaceException);
37 static std::string getInterface(
const sella::net::IPAddress &ipAddress,
unsigned int ifrFlagMatch = ifrFlagMatchDefault,
unsigned int ifrFlagReject = ifrFlagRejectDefault)
throw (InterfaceException);
38 static sella::net::IPAddress::shared_list getIPAddresses(
const std::string &interface =
"",
unsigned int ifrFlagMatch = ifrFlagMatchDefault,
unsigned int ifrFlagReject = ifrFlagRejectDefault)
throw (InterfaceException);
39 static sella::net::IPAddress getIPAddress(
const std::string &interface,
int family = AF_INET)
throw (InterfaceException);
40 static std::list<std::string> getNames(
unsigned int ifrFlagMatch = ifrFlagMatchDefault,
unsigned int ifrFlagReject = ifrFlagRejectDefault)
throw (InterfaceException);
41 static std::list<std::string> getEthernetNames(
const unsigned int ifrFlagMatch = ifrFlagMatchDefault,
const unsigned int ifrFlagReject = ifrFlagRejectDefault)
throw (InterfaceException);
42 static std::string getMAC(
const std::string &interface)
throw (InterfaceException);
43 static std::list<std::string> getMACs(
unsigned int ifrFlagMatch = ifrFlagMatchDefault,
unsigned int ifrFlagReject = ifrFlagRejectDefault)
throw (InterfaceException);
45 static struct in_addr* getAddr(
const std::string &interface,
struct in_addr *ip)
throw (InterfaceException);
46 static unsigned int getIndex(
const std::string &interface)
throw (InterfaceException);
47 static std::string getName(
unsigned int index)
throw (InterfaceException);
49 static unsigned char* convertMAC(
unsigned char dst[6],
const std::string &mac)
throw (InterfaceException);
50 static std::string& convertMAC(std::string &dst,
const unsigned char mac[6],
char delim =
':')
throw (InterfaceException);
52 static unsigned char* convertMAC(
unsigned char dst[6],
const uint64_t mac)
throw (InterfaceException);
53 static uint64_t& convertMAC(uint64_t &dst,
const unsigned char mac[6])
throw (InterfaceException);
55 static std::string& convertMAC(std::string &dst,
const uint64_t mac)
throw (InterfaceException);
56 static uint64_t& convertMAC(uint64_t &dst,
const std::string &mac)
throw (InterfaceException);
58 static bool isEthernet(
const std::string &interface)
throw (InterfaceException);
61 LIBUTIL_API_DEPRECATED
static unsigned char* parseMAC(
const std::string &mac,
unsigned char addr[6])
throw (InterfaceException);
62 LIBUTIL_API_DEPRECATED
static sella::net::IPAddress::shared_list getInterfaceIPAddresses(
const std::string &interface =
"",
unsigned int ifrFlagMatch = ifrFlagMatchDefault,
unsigned int ifrFlagReject = ifrFlagRejectDefault)
throw (InterfaceException);
63 LIBUTIL_API_DEPRECATED
static std::list<std::string> getInterfaceNames(
unsigned int ifrFlagMatch = ifrFlagMatchDefault,
unsigned int ifrFlagReject = ifrFlagRejectDefault)
throw (InterfaceException);
64 LIBUTIL_API_DEPRECATED
static std::string getInterfaceMAC(
const std::string &interface)
throw (InterfaceException);
65 LIBUTIL_API_DEPRECATED
static std::list<std::string> getInterfaceMACs(
unsigned int ifrFlagMatch = ifrFlagMatchDefault,
unsigned int ifrFlagReject = ifrFlagRejectDefault)
throw (InterfaceException);
66 LIBUTIL_API_DEPRECATED
static void getInterfaceAddr(
const std::string &interface,
struct in_addr *ip)
throw (InterfaceException);
68 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);
69 LIBUTIL_API_DEPRECATED
static std::list<std::string> interfaceNameList(
const unsigned int ifrFlagMatch = ifrFlagMatchDefault,
const unsigned int ifrFlagReject = ifrFlagRejectDefault)
throw (InterfaceException);
70 LIBUTIL_API_DEPRECATED
static std::list<std::string> interfaceMACList(
const unsigned int ifrFlagMatch = ifrFlagMatchDefault,
const unsigned int ifrFlagReject = ifrFlagRejectDefault)
throw (InterfaceException);
71 LIBUTIL_API_DEPRECATED
static void source_ip(
char *interface,
struct in_addr *ip)
throw (InterfaceException);