RTP Audio System  2.0.0
socketaddress.h
Go to the documentation of this file.
00001 /*
00002  *  $Id: socketaddress.h 1259 2011-12-17 13:26:09Z dreibh $
00003  *
00004  * SocketAPI implementation for the sctplib.
00005  * Copyright (C) 1999-2012 by Thomas Dreibholz
00006  *
00007  * Realized in co-operation between
00008  * - Siemens AG
00009  * - University of Essen, Institute of Computer Networking Technology
00010  * - University of Applied Sciences, Muenster
00011  *
00012  * Acknowledgement
00013  * This work was partially funded by the Bundesministerium fuer Bildung und
00014  * Forschung (BMBF) of the Federal Republic of Germany (Foerderkennzeichen 01AK045).
00015  * The authors alone are responsible for the contents.
00016  *
00017  * This program is free software: you can redistribute it and/or modify
00018  * it under the terms of the GNU General Public License as published by
00019  * the Free Software Foundation, either version 3 of the License, or
00020  * (at your option) any later version.
00021 
00022  * This program is distributed in the hope that it will be useful,
00023  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00024  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00025  * GNU General Public License for more details.
00026  *
00027  * You should have received a copy of the GNU General Public License
00028  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00029  *
00030  * Contact: discussion@sctp.de
00031  *          dreibh@iem.uni-due.de
00032  *          tuexen@fh-muenster.de
00033  *
00034  * Purpose: Socket Adress
00035  *
00036  */
00037 
00038 
00039 #ifndef SOCKETADDRESS_H
00040 #define SOCKETADDRESS_H
00041 
00042 
00043 #include "tdsystem.h"
00044 #include "tdstrings.h"
00045 
00046 
00047 #include <sys/socket.h>
00048 #include <sys/un.h>
00049 
00050 
00051 
00059 class SocketAddress
00060 {
00061    // ====== Destructor =====================================================
00062    public:
00066    virtual ~SocketAddress();
00067 
00068 
00069    // ====== Duplication ====================================================
00075    virtual SocketAddress* duplicate() const = 0;
00076 
00077 
00078    // ====== Reset ==========================================================
00082    virtual void reset() = 0;
00083 
00084 
00085    // ====== Check, if address is valid =====================================
00091    virtual bool isValid() const = 0;
00092 
00093 
00094    // ====== Print format ===================================================
00098    enum PrintFormat {
00102       PF_Address  = (1 << 0),
00103 
00107       PF_Hostname = (1 << 1),
00108 
00112       PF_Full = (PF_Address | PF_Hostname),
00113 
00117       PF_HidePort = (1 << 15),
00118 
00123       PF_Legacy = (1 << 16),
00124 
00128       PF_Default = (PF_Address | PF_Legacy)
00129    };
00130 
00131 
00137    inline cardinal getPrintFormat() const;
00138 
00144    inline void setPrintFormat(const cardinal format);
00145 
00146 
00147    // ====== Address management =============================================
00153    virtual card16 getPort() const = 0;
00154 
00158    virtual void setPort(const card16 port) = 0;
00159 
00165    virtual integer getFamily() const = 0;
00166 
00167 
00168    // ====== Get local address for a connection =============================
00181    static SocketAddress* getLocalAddress(const SocketAddress& peer);
00182 
00183 
00184    // ====== Get address string =============================================
00190    virtual String getAddressString(const cardinal format = PF_Default) const = 0;
00191 
00192 
00193    // ====== SocketAddress creation =========================================
00200    static SocketAddress* createSocketAddress(const integer family);
00201 
00209    static SocketAddress* createSocketAddress(const cardinal flags, const String& name);
00210 
00219    static SocketAddress* createSocketAddress(const cardinal flags,
00220                                              const String&  name,
00221                                              const card16   port);
00222 
00231    static SocketAddress* createSocketAddress(const cardinal  flags,
00232                                              sockaddr*       address,
00233                                              const socklen_t length);
00234 
00235 
00236    // ====== Get/set system sockaddr structure ==============================
00245    virtual cardinal getSystemAddress(sockaddr*       buffer,
00246                                      const socklen_t length,
00247                                      const cardinal  type = AF_UNSPEC) const = 0;
00248 
00255    virtual bool setSystemAddress(const sockaddr* address, const socklen_t length) = 0;
00256 
00257 
00258    // ====== SocketAddress lists ============================================
00265    static SocketAddress** newAddressList(const cardinal entries);
00266 
00275    static void deleteAddressList(SocketAddress**& addressArray);
00276 
00277 
00278    // ====== Constants ======================================================
00282    static const cardinal MaxSockLen =
00283       (sizeof(sockaddr_un) > sizeof(sockaddr_storage)) ? sizeof(sockaddr_un) : sizeof(sockaddr_storage);
00284 
00285 
00286    // ====== Protected data =================================================
00287    protected:
00291    cardinal Format;
00292 
00293 
00294    friend inline std::ostream& operator<<(std::ostream& os, const SocketAddress& sa);
00295 };
00296 
00297 
00301 inline std::ostream& operator<<(std::ostream& os, const SocketAddress& sa);
00302 
00303 
00304 #include "socketaddress.icc"
00305 
00306 
00307 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines