libutil++  1.9.3
 All Classes Functions Variables
Interface.h
1 /*
2 ** libutil++
3 ** $Id: Interface.h 1653 2016-02-28 19:54:59Z sella $
4 ** Copyright (c) 2011-2016 Digital Genesis, LLC. All Rights Reserved.
5 ** Released under the LGPL Version 2.1 License.
6 ** http://www.digitalgenesis.com
7 */
8 
9 #ifndef __libutilxx__sella__util__Interface_H__
10 #define __libutilxx__sella__util__Interface_H__
11 
12 #include "../../common.h"
13 #include "InterfaceException.h"
14 #include "../net/IPAddress.h"
15 
16 #include <net/if.h>
17 #include <sys/ioctl.h>
18 #include <netinet/in.h>
19 
20 #include <list>
21 #include <string>
22 
23 namespace sella {
24  namespace util {
25  class Interface;
26  }
27 }
28 
30  public:
31  /* See SIOCGIFFLAGS in man inetdevice for settings. */
32  static const unsigned int ifrFlagMatchDefault = (IFF_UP);
33  static const unsigned int ifrFlagRejectDefault = (IFF_LOOPBACK);
34 
35  static void setPromiscous(const std::string &interface, bool on = true) throw (InterfaceException);
36 
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);
44 
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);
48 
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);
51 
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);
54 
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);
57 
58  static bool isEthernet(const std::string &interface) throw (InterfaceException);
59 
60 #if 0
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);
67 
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);
72 #endif
73 };
74 
75 #endif
76 
77 /*
78 ** vim: noet ts=3 sw=3
79 */