libfluid
The ONF OpenFlow driver
ipaddr.hh
1 #ifndef __IPADDRESS_H__
2 #define __IPADDRESS_H__
3 
4 #include <stdint.h>
5 #include <string.h>
6 #include <net/if.h>
7 #include <arpa/inet.h>
8 #include <sstream>
9 #include <string>
10 
11 namespace fluid_msg{
12 
13 enum {NONE = 0, IPV4 = 4, IPV6 = 6 };
14 
15 class IPAddress {
16  public:
17  IPAddress();
18  IPAddress(const char* address);
19  IPAddress(const std::string &address);
20  IPAddress(const IPAddress &other);
21  IPAddress(const uint32_t ip_addr);
22  IPAddress(const uint8_t ip_addr[16]);
23  IPAddress(const struct in_addr& ip_addr);
24  IPAddress(const struct in6_addr& ip_addr);
25  ~IPAddress(){};
26 
27  IPAddress& operator=(const IPAddress& other);
28  bool operator==(const IPAddress& other) const;
29  int get_version() const;
30  void setIPv4(uint32_t address);
31  void setIPv6(uint8_t address[16]);
32  uint32_t getIPv4();
33  uint8_t * getIPv6();
34  static uint32_t IPv4from_string(const std::string &address);
35  static struct in6_addr IPv6from_string(const std::string &address);
36 
37  private:
38  int version;
39  union {
40  uint32_t ipv4;
41  uint8_t ipv6[16];
42  };
43 };
44 }
45 #endif /* __IPADDRESS_H__ */