OpenDDS  Snapshot(2023/04/28-20:55)
NetworkAddress.h
Go to the documentation of this file.
1 /*
2  *
3  *
4  * Distributed under the OpenDDS License.
5  * See: http://www.opendds.org/license.html
6  */
7 
8 #ifndef OPENDDS_DCPS_NETWORK_ADDRESS_H
9 #define OPENDDS_DCPS_NETWORK_ADDRESS_H
10 
11 #include "dcps_export.h"
12 
13 #ifndef ACE_LACKS_PRAGMA_ONCE
14 # pragma once
15 #endif /* ACE_LACKS_PRAGMA_ONCE */
16 
17 #include "Definitions.h"
18 #include "PoolAllocator.h"
19 #include "Hash.h"
20 
21 #include "ace/INET_Addr.h"
22 
24 
25 namespace OpenDDS {
26 namespace DCPS {
27 
29 public:
31  NetworkAddress(const NetworkAddress& addr);
32 
33  explicit NetworkAddress(const char*);
34  NetworkAddress(ACE_UINT16 port, const char*);
35 
36 #if defined (ACE_HAS_WCHAR)
37  explicit NetworkAddress(const wchar_t*);
38  NetworkAddress(ACE_UINT16 port, const wchar_t*);
39 #endif
40 
41  explicit NetworkAddress(const ACE_INET_Addr& addr);
42 
43  NetworkAddress& operator=(const NetworkAddress& rhs);
44  NetworkAddress& operator=(const ACE_INET_Addr& rhs);
45 
46  operator bool() const;
47  bool operator!() const;
48 
49  bool operator==(const NetworkAddress& rhs) const;
50  bool operator!=(const NetworkAddress& rhs) const;
51 
52  bool operator<(const NetworkAddress& rhs) const;
53 
54 #if defined ACE_HAS_CPP11
55  size_t hash(size_t result) const;
56 #endif
57 
58  bool addr_bytes_equal(const NetworkAddress& rhs) const;
59 
60  ACE_INET_Addr to_addr() const;
61  void to_addr(ACE_INET_Addr&) const;
62 
63  ACE_INT16 get_type() const;
64  void set_type(ACE_INT16 type);
65 
66  ACE_UINT16 get_port_number() const;
67  void set_port_number(ACE_UINT16 port);
68 
69  bool is_any() const;
70  bool is_loopback() const;
71  bool is_multicast() const;
72 
73  bool is_private() const; // IPv4 only
74 
75  bool is_linklocal() const; // IPv6 only (can't be routed)
76  bool is_uniquelocal() const; // IPv6 only (only one routing domain)
77  bool is_sitelocal() const; // IPv6 only (deprecated)
78 
79 private:
80  union ip46
81  {
82  sockaddr_in in4_;
83 #if defined (ACE_HAS_IPV6)
84  sockaddr_in6 in6_;
85 #endif /* ACE_HAS_IPV6 */
86  } inet_addr_;
87 };
88 
89 typedef OPENDDS_SET(NetworkAddress) AddrSet;
90 
91 #if defined ACE_HAS_CPP11
93 size_t calculate_hash(const AddrSet& addrs, size_t start_hash = 0);
94 #endif
95 
97 bool is_more_local(const NetworkAddress& current, const NetworkAddress& incoming);
98 
99 } // namespace DCPS
100 } // namespace OpenDDS
101 
103 
104 #if defined ACE_HAS_CPP11
105 OPENDDS_OOAT_STD_HASH(OpenDDS::DCPS::NetworkAddress, OpenDDS_Dcps_Export);
106 #endif
107 
108 #endif /*OPENDDS_DCPS_NETWORK_ADDRESS_H*/
ACE_INLINE OpenDDS_Dcps_Export bool operator!(const DDS::Time_t &t)
Definition: Time_Helper.inl:77
int hash(const std::vector< const DDS::OctetSeq *> &src, DDS::OctetSeq &dst)
#define OpenDDS_Dcps_Export
Definition: dcps_export.h:24
bool is_more_local(const NetworkAddress &current, const NetworkAddress &incoming)
bool operator==(const DisjointSequence::OrderedRanges< T > &a, const DisjointSequence::OrderedRanges< T > &b)
bool operator!=(const GUID_t &lhs, const GUID_t &rhs)
Definition: GuidUtils.h:125
#define OPENDDS_END_VERSIONED_NAMESPACE_DECL
The Internal API and Implementation of OpenDDS.
Definition: AddressCache.h:28
bool operator<(const GUID_t &lhs, const GUID_t &rhs)
Definition: GuidUtils.h:80
typedef OPENDDS_SET(NetworkAddress) AddrSet