OW_SocketAddress.hpp

Go to the documentation of this file.
00001 /*******************************************************************************
00002 * Copyright (C) 2001-2004 Vintela, Inc. All rights reserved.
00003 *
00004 * Redistribution and use in source and binary forms, with or without
00005 * modification, are permitted provided that the following conditions are met:
00006 *
00007 *  - Redistributions of source code must retain the above copyright notice,
00008 *    this list of conditions and the following disclaimer.
00009 *
00010 *  - Redistributions in binary form must reproduce the above copyright notice,
00011 *    this list of conditions and the following disclaimer in the documentation
00012 *    and/or other materials provided with the distribution.
00013 *
00014 *  - Neither the name of Vintela, Inc. nor the names of its
00015 *    contributors may be used to endorse or promote products derived from this
00016 *    software without specific prior written permission.
00017 *
00018 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
00019 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00020 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00021 * ARE DISCLAIMED. IN NO EVENT SHALL Vintela, Inc. OR THE CONTRIBUTORS
00022 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00023 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00024 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00025 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00026 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00027 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00028 * POSSIBILITY OF SUCH DAMAGE.
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 // TODO: This class needs to be rewritten to take into account the fact that a given hostname may have multiple 
00051 // ip addresses, and a given ip address may have multiple hostnames & aliases..
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    //static Array<SocketAddress> getAllByName(const String& hostName,
00124    //    unsigned short port = 0);
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 } // end namespace OW_NAMESPACE
00176 
00177 #endif

Generated on Thu Feb 9 08:48:11 2006 for openwbem by  doxygen 1.4.6