NetworkAddress.h

Go to the documentation of this file.
00001 /*
00002  *
00003  *
00004  * Distributed under the OpenDDS License.
00005  * See: http://www.opendds.org/license.html
00006  */
00007 
00008 #ifndef OPENDDS_DCPS_NETWORKADDRESS_H
00009 #define OPENDDS_DCPS_NETWORKADDRESS_H
00010 
00011 #include "dds/DCPS/dcps_export.h"
00012 #include "dds/DCPS/PoolAllocator.h"
00013 
00014 #include "tao/Basic_Types.h"
00015 
00016 #include "ace/INET_Addr.h"
00017 #include "ace/CDR_Stream.h"
00018 #include "ace/SString.h"
00019 #include "ace/SOCK_Dgram.h"
00020 
00021 namespace OpenDDS {
00022 namespace DCPS {
00023 
00024 struct HostnameInfo {
00025   size_t index_;
00026   OPENDDS_STRING hostname_;
00027 };
00028 
00029 typedef OPENDDS_VECTOR(HostnameInfo) HostnameInfoVector;
00030 
00031 /**
00032  * @struct NetworkAddress
00033  *
00034  * @brief Defines a wrapper around address info which is used for advertise.
00035  *
00036  *
00037  * This is used to send/receive an address information through transport.
00038  */
00039 struct OpenDDS_Dcps_Export NetworkAddress {
00040   NetworkAddress();
00041   explicit NetworkAddress(const ACE_INET_Addr& addr, bool use_hostname = false);
00042   explicit NetworkAddress(const OPENDDS_STRING& addr);
00043 
00044   ~NetworkAddress();
00045 
00046   void dump();
00047 
00048   /// Accessor to populate the provided ACE_INET_Addr object from the
00049   /// address string received through transport.
00050   void to_addr(ACE_INET_Addr& addr) const;
00051 
00052   /// Reserve byte for some feature supports in the future.
00053   /// e.g. version support.
00054   CORBA::Octet reserved_;
00055 
00056   /// The address in string format. e.g. ip:port, hostname:port
00057   OPENDDS_STRING addr_;
00058 };
00059 
00060 /// Helper function to get the fully qualified hostname.
00061 /// It attempts to discover the FQDN by the network interface addresses, however
00062 /// the result is impacted by the network configuration, so it returns name in the
00063 /// order whoever is found first - FQDN, short hostname, name resolved from loopback
00064 /// address. In the case using short hostname or name resolved from loopback, a
00065 /// warning is logged. If there is no any name discovered from network interfaces,
00066 /// an error is logged.
00067 /// If ACE_HAS_IPV6, will give priority to IPV6 interfaces
00068 extern OpenDDS_Dcps_Export
00069 OPENDDS_STRING get_fully_qualified_hostname(ACE_INET_Addr* addr = 0);
00070 
00071 /// Helper function to get the vector of addresses which should
00072 /// be advertised to peers
00073 extern OpenDDS_Dcps_Export
00074 void get_interface_addrs(OPENDDS_VECTOR(ACE_INET_Addr)& addrs);
00075 
00076 /// Helper function to set the ttl on a socket appropriately
00077 /// given whether it is IPV4 or IPV6
00078 extern OpenDDS_Dcps_Export
00079 bool set_socket_multicast_ttl(const ACE_SOCK_Dgram& socket, const unsigned char& ttl);
00080 
00081 /// Helper function to create dual stack socket to support IPV4 and IPV6,
00082 /// for IPV6 builds allows for setting IPV6_V6ONLY socket option to 0 before binding
00083 /// Otherwise defaults to opening a socket based on the type of local_address
00084 extern OpenDDS_Dcps_Export
00085 bool open_appropriate_socket_type(ACE_SOCK_Dgram& socket, const ACE_INET_Addr& local_address);
00086 } // namespace DCPS
00087 } // namespace OpenDDS
00088 
00089 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00090 
00091 /// Marshal into a buffer.
00092 extern OpenDDS_Dcps_Export
00093 ACE_CDR::Boolean
00094 operator<< (ACE_OutputCDR& outCdr, OpenDDS::DCPS::NetworkAddress& value);
00095 
00096 /// Demarshal from a buffer.
00097 extern OpenDDS_Dcps_Export
00098 ACE_CDR::Boolean
00099 operator>> (ACE_InputCDR& inCdr, OpenDDS::DCPS::NetworkAddress& value);
00100 
00101 ACE_END_VERSIONED_NAMESPACE_DECL
00102 
00103 #if defined (__ACE_INLINE__)
00104 # include "NetworkAddress.inl"
00105 #endif  /* __ACE_INLINE__ */
00106 
00107 #endif /* OPENDDS_DCPS_NETWORKADDRESS_H */

Generated on Fri Feb 12 20:05:24 2016 for OpenDDS by  doxygen 1.4.7