SocketAddress.hpp

Go to the documentation of this file.
00001 /*******************************************************************************
00002 * Copyright (C) 2004 Vintela, Inc. All rights reserved.
00003 * Copyright (C) 2005 Novell, Inc. All rights reserved.
00004 *
00005 * Redistribution and use in source and binary forms, with or without
00006 * modification, are permitted provided that the following conditions are met:
00007 *
00008 *  - Redistributions of source code must retain the above copyright notice,
00009 *    this list of conditions and the following disclaimer.
00010 *
00011 *  - Redistributions in binary form must reproduce the above copyright notice,
00012 *    this list of conditions and the following disclaimer in the documentation
00013 *    and/or other materials provided with the distribution.
00014 *
00015 *  - Neither the name of Vintela, Inc., Novell, Inc., nor the names of its
00016 *    contributors may be used to endorse or promote products derived from this
00017 *    software without specific prior written permission.
00018 *
00019 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
00020 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00021 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00022 * ARE DISCLAIMED. IN NO EVENT SHALL Vintela, Inc., Novell, Inc., OR THE 
00023 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
00024 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 
00025 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 
00026 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
00027 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 
00028 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 
00029 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00030 *******************************************************************************/
00031 
00032 
00038 #ifndef BLOCXX_SocketADDRESS_HPP_INCLUDE_GUARD_
00039 #define BLOCXX_SocketADDRESS_HPP_INCLUDE_GUARD_
00040 #include "blocxx/BLOCXX_config.h"
00041 #include "blocxx/Array.hpp"
00042 #include "blocxx/Types.hpp"
00043 #include "blocxx/NetworkTypes.hpp"
00044 #include "blocxx/String.hpp"
00045 #include "blocxx/Exception.hpp"
00046 
00047 namespace BLOCXX_NAMESPACE
00048 {
00049 
00050 BLOCXX_DECLARE_APIEXCEPTION(UnknownHost, BLOCXX_COMMON_API);
00051 BLOCXX_DECLARE_APIEXCEPTION(SocketAddress, BLOCXX_COMMON_API);
00052 // TODO: This class needs to be rewritten to take into account the fact that a given hostname may have multiple 
00053 // ip addresses, and a given ip address may have multiple hostnames & aliases..
00054 class BLOCXX_COMMON_API SocketAddress
00055 {
00056 public:
00057    static const char* const ALL_LOCAL_ADDRESSES;
00058 
00059    enum AddressType
00060    {
00061       UNSET,
00062       INET,
00063       UDS
00064    };
00065    AddressType getType() const { return m_type; }
00075    static SocketAddress getByName(const String& host, unsigned short port = 0);
00091    static SocketAddress getAnyLocalHost(UInt16 port = 0);
00096    static SocketAddress allocEmptyAddress(AddressType type);
00101    UInt16 getPort() const;
00102    ~SocketAddress() {}
00108    const String getName() const;
00114    const String getAddress() const;
00115    const SocketAddress_t* getNativeForm() const;
00116    size_t getNativeFormSize() const;
00117 
00122    const InetSocketAddress_t* getInetAddress() const;
00123 
00124 #if !defined(BLOCXX_WIN32)
00125    //static Array<SocketAddress> getAllByName(const String& hostName,
00126    //    unsigned short port = 0);
00127    static SocketAddress getUDS(const String& filename);
00128 
00133    const UnixSocketAddress_t* getUnixAddress() const;
00134 
00135    void assignFromNativeForm(const UnixSocketAddress_t* address, size_t len);
00136 #endif
00137 
00143    const String toString() const;
00144    void assignFromNativeForm(const InetSocketAddress_t* address, size_t len);
00145 
00146    SocketAddress();
00147 private:
00148    SocketAddress(const InetSocketAddress_t& nativeForm);
00149 
00150 #if !defined(BLOCXX_WIN32)
00151    SocketAddress(const UnixSocketAddress_t& nativeForm);
00152 #endif
00153 
00154    String m_name;
00155    String m_address;
00156    size_t m_nativeSize;
00157    
00158    InetSocketAddress_t m_inetNativeAddress;
00159 
00160 #if !defined(BLOCXX_WIN32)
00161    UnixSocketAddress_t m_UDSNativeAddress;
00162 #endif
00163 
00164    AddressType m_type;
00165    static SocketAddress getFromNativeForm(const InetAddress_t& nativeForm,
00166          UInt16 nativePort, const String& hostname );
00167    static SocketAddress getFromNativeForm(
00168       const InetSocketAddress_t& nativeForm);
00169 
00170 #if !defined(BLOCXX_WIN32)
00171    static SocketAddress getFromNativeForm(
00172       const UnixSocketAddress_t& nativeForm);
00173 #endif
00174 
00175 };
00176 
00177 } // end namespace BLOCXX_NAMESPACE
00178 
00179 #endif

Generated on Fri Jun 16 15:39:09 2006 for blocxx by  doxygen 1.4.6