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