1 // ***************************************************************************
2 // HostAddress_p.h (c) 2011 Derek Barnett
3 // Marth Lab, Department of Biology, Boston College
4 // ---------------------------------------------------------------------------
5 // Last modified: 10 November 2011 (DB)
6 // ---------------------------------------------------------------------------
7 // Provides a generic IP address container
8 // ***************************************************************************
10 #ifndef HOSTADDRESS_P_H
11 #define HOSTADDRESS_P_H
17 // This file is not part of the BamTools API. It exists purely as an
18 // implementation detail. This header file may change from version to version
19 // without notice, or even be removed.
23 #include "api/api_global.h"
33 inline IPv6Address(void) { memset(&data, 0, sizeof(uint8_t)*16); }
35 // data access (no bounds checking)
36 inline uint8_t& operator[](size_t index) { return data[index]; }
37 inline uint8_t operator[](size_t index) const { return data[index]; }
47 enum NetworkProtocol { UnknownNetworkProtocol = -1
55 explicit HostAddress(const uint32_t ip4Address);
56 explicit HostAddress(const uint8_t* ip6Address);
57 explicit HostAddress(const IPv6Address& ip6Address);
58 explicit HostAddress(const std::string& address);
59 HostAddress(const HostAddress& other);
62 // HostAddress interface
65 bool HasIPAddress(void) const; // returns whether string address could be converted to IP address
66 bool IsNull(void) const;
68 uint32_t GetIPv4Address(void) const;
69 IPv6Address GetIPv6Address(void) const;
70 std::string GetIPString(void) const;
71 HostAddress::NetworkProtocol GetProtocol(void) const;
73 void SetAddress(const uint32_t ip4Address);
74 void SetAddress(const uint8_t* ip6Address);
75 void SetAddress(const IPv6Address& ip6Address);
76 void SetAddress(const std::string& address);
78 // HostAddress comparison operators
80 bool operator==(const HostAddress& other) const;
81 bool operator!=(const HostAddress& other) const { return !( operator==(other) ); }
82 bool operator<(const HostAddress& other) const;
86 bool ParseAddress(void);
90 HostAddress::NetworkProtocol m_protocol;
91 uint32_t m_ip4Address;
92 IPv6Address m_ip6Address;
93 std::string m_ipString;
94 bool m_hasIpAddress; // true until string passed in, then signifies whether string was an IP
97 } // namespace Internal
98 } // namespace BamTools
100 #endif // HOSTADDRESS_P_H