00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 
00028 
00029 
00030 
00036 #ifndef OW_SocketADDRESS_HPP_INCLUDE_GUARD_
00037 #define OW_SocketADDRESS_HPP_INCLUDE_GUARD_
00038 #include "OW_config.h"
00039 #include "OW_Array.hpp"
00040 #include "OW_Types.hpp"
00041 #include "OW_NetworkTypes.hpp"
00042 #include "OW_String.hpp"
00043 #include "OW_Exception.hpp"
00044 
00045 namespace OW_NAMESPACE
00046 {
00047 
00048 OW_DECLARE_APIEXCEPTION(UnknownHost, OW_COMMON_API);
00049 OW_DECLARE_APIEXCEPTION(SocketAddress, OW_COMMON_API);
00050 
00051 
00052 class OW_COMMON_API SocketAddress
00053 {
00054 public:
00055    static const char* const ALL_LOCAL_ADDRESSES;
00056 
00057    enum AddressType
00058    {
00059       UNSET,
00060       INET,
00061       UDS
00062    };
00063    AddressType getType() const { return m_type; }
00073    static SocketAddress getByName(const String& host, unsigned short port = 0);
00089    static SocketAddress getAnyLocalHost(UInt16 port = 0);
00094    static SocketAddress allocEmptyAddress(AddressType type);
00099    UInt16 getPort() const;
00100    ~SocketAddress() {}
00106    const String getName() const;
00112    const String getAddress() const;
00113    const SocketAddress_t* getNativeForm() const;
00114    size_t getNativeFormSize() const;
00115 
00120    const InetSocketAddress_t* getInetAddress() const;
00121 
00122 #if !defined(OW_WIN32)
00123    
00124    
00125    static SocketAddress getUDS(const String& filename);
00126 
00131    const UnixSocketAddress_t* getUnixAddress() const;
00132 
00133    void assignFromNativeForm(const UnixSocketAddress_t* address, size_t len);
00134 #endif
00135 
00141    const String toString() const;
00142    void assignFromNativeForm(const InetSocketAddress_t* address, size_t len);
00143 
00144    SocketAddress();
00145 private:
00146    SocketAddress(const InetSocketAddress_t& nativeForm);
00147 
00148 #if !defined(OW_WIN32)
00149    SocketAddress(const UnixSocketAddress_t& nativeForm);
00150 #endif
00151 
00152    String m_name;
00153    String m_address;
00154    size_t m_nativeSize;
00155    
00156    InetSocketAddress_t m_inetNativeAddress;
00157 
00158 #if !defined(OW_WIN32)
00159    UnixSocketAddress_t m_UDSNativeAddress;
00160 #endif
00161 
00162    AddressType m_type;
00163    static SocketAddress getFromNativeForm(const InetAddress_t& nativeForm,
00164          UInt16 nativePort, const String& hostname );
00165    static SocketAddress getFromNativeForm(
00166       const InetSocketAddress_t& nativeForm);
00167 
00168 #if !defined(OW_WIN32)
00169    static SocketAddress getFromNativeForm(
00170       const UnixSocketAddress_t& nativeForm);
00171 #endif
00172 
00173 };
00174 
00175 } 
00176 
00177 #endif