# kdecore Library API Documentation

Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Namespaces | Source Files

# ksockaddr.h

    00001 /*
    00002  *  This file is part of the KDE libraries
    00003  *  Copyright (C) 2000-2003 Thiago Macieira <thiago.macieira@kdemail.net>
    00004  *
    00005  *  This library is free software; you can redistribute it and/or
    00006  *  modify it under the terms of the GNU Library General Public
    00007  *  License as published by the Free Software Foundation; either
    00008  *  version 2 of the License, or (at your option) any later version.
    00009  *
    00010  *  This library is distributed in the hope that it will be useful,
    00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
    00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00013  *  Library General Public License for more details.
    00014  *
    00015  *  You should have received a copy of the GNU Library General Public License
    00016  *  along with this library; see the file COPYING.LIB.  If not, write to
    00017  *  the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    00018  *  Boston, MA 02111-1307, USA.
    00019  */
    00020 #ifndef KSOCKADDR_H
    00021 #define KSOCKADDR_H
    00022
    00023 #include <qobject.h>
    00024 #include <qcstring.h>
    00025 #include <qstring.h>
    00026 #include "kdelibs_export.h"
    00027
    00028 /*
    00029  * This file defines a class that envelopes most, if not all, socket addresses
    00030  */
    00031 typedef unsigned ksocklen_t;
    00032
    00033 struct sockaddr;
    00034
    00035 class KExtendedSocket;      // No need to define it fully
    00036
    00037 class KSocketAddressPrivate;
    00046 class KDECORE_EXPORT KSocketAddress: public QObject
    00047 {
    00048   Q_OBJECT
    00049 protected:
    00053   KSocketAddress() { init(); }
    00054
    00060   KSocketAddress(const sockaddr* sa, ksocklen_t size);
    00061
    00062 public:
    00066   virtual ~KSocketAddress();
    00067
    00072   virtual QString pretty() const;
    00073
    00078   const sockaddr* address() const
    00079   { return data; }
    00080
    00085   virtual ksocklen_t size() const
    00086   { return datasize; }
    00087
    00093   operator const sockaddr*() const
    00094   { return data; }
    00095
    00100   int family() const;
    00101
    00107   inline int ianaFamily() const
    00108   { return ianaFamily(family()); }
    00109
    00115   virtual bool isEqual(const KSocketAddress& other) const;
    00116   bool isEqual(const KSocketAddress* other) const
    00117   { return isEqual(*other); }
    00118
    00123   bool operator==(const KSocketAddress& other) const
    00124   { return isEqual(other); }
    00125
    00136   bool isCoreEqual(const KSocketAddress& other) const;
    00137
    00148   bool isCoreEqual(const KSocketAddress* other) const
    00149   { return isCoreEqual(*other); }
    00150
    00158   virtual QString nodeName() const;
    00159
    00167   virtual QString serviceName() const;
    00168
    00169 protected:
    00170   sockaddr* data;
    00171   ksocklen_t    datasize;
    00172   bool      owndata;
    00173
    00174 private:
    00175   void init();
    00176   /* No copy constructor */
    00177   KSocketAddress(KSocketAddress&);
    00178   KSocketAddress& operator=(KSocketAddress&);
    00179
    00180 public:
    00188   static KSocketAddress* newAddress(const struct sockaddr *sa, ksocklen_t size);
    00189
    00197   static int ianaFamily(int af);
    00198
    00203   static int fromIanaFamily(int iana);
    00204
    00205   friend class KExtendedSocket;
    00206 protected:
    00207   virtual void virtual_hook( int id, void* data );
    00208 private:
    00209   KSocketAddressPrivate* d;
    00210 };
    00211
    00212 /*
    00213  * External definitions
    00214  * We need these for KInetSocketAddress
    00215  */
    00216 struct sockaddr_in;
    00217 struct sockaddr_in6;
    00218 struct in_addr;
    00219 struct in6_addr;
    00220
    00221 class KInetSocketAddressPrivate;
    00233 class KDECORE_EXPORT KInetSocketAddress: public ::KSocketAddress
    00234 {
    00235   Q_OBJECT
    00236 public:
    00240   KInetSocketAddress();
    00241
    00245   KInetSocketAddress(const KInetSocketAddress&);
    00246
    00252   KInetSocketAddress(const sockaddr_in* sin, ksocklen_t len);
    00253
    00259   KInetSocketAddress(const sockaddr_in6* sin6, ksocklen_t len);
    00260
    00266   KInetSocketAddress(const in_addr& addr, unsigned short port);
    00267
    00273   KInetSocketAddress(const in6_addr& addr, unsigned short port);
    00274
    00284   KInetSocketAddress(const QString& addr, unsigned short port, int family = -1);
    00285
    00289   virtual ~KInetSocketAddress();
    00290
    00296   bool setAddress(const KInetSocketAddress& ksa);
    00297
    00304   bool setAddress(const sockaddr_in* sin, ksocklen_t len);
    00305
    00314   bool setAddress(const sockaddr_in6* sin6, ksocklen_t len);
    00315
    00322   bool setAddress(const in_addr& addr, unsigned short port);
    00323
    00330   bool setAddress(const in6_addr& addr, unsigned short port);
    00331
    00349   bool setAddress(const QString& addr, unsigned short port, int family = -1);
    00350
    00356   bool setHost(const in_addr& addr);
    00357
    00363   bool setHost(const in6_addr& addr);
    00364
    00371   bool setHost(const QString& addr, int family = -1);
    00372
    00378   bool setPort(unsigned short port);
    00379
    00387   bool setFamily(int family);
    00388
    00394   bool setFlowinfo(Q_UINT32 flowinfo);
    00395
    00401   bool setScopeId(int scopeid);
    00402
    00407   virtual QString pretty() const;
    00408
    00413   virtual QString nodeName() const;
    00414   //  QString prettyHost() const;
    00415
    00420   virtual QString serviceName() const;
    00421
    00431   const sockaddr_in* addressV4() const;
    00432
    00437   const sockaddr_in6* addressV6() const;
    00438
    00444   in_addr hostV4() const;
    00445
    00452   in6_addr hostV6() const;
    00453
    00458   unsigned short port() const;
    00459
    00464   Q_UINT32 flowinfo() const;
    00465
    00470   int scopeId() const;
    00471
    00477   virtual ksocklen_t size() const; // should be socklen_t
    00478
    00479   /* comparation */
    00491   static bool areEqualInet(const KSocketAddress &s1, const KSocketAddress &s2, bool coreOnly);
    00492
    00504   static bool areEqualInet6(const KSocketAddress &s1, const KSocketAddress &s2, bool coreOnly);
    00505
    00506   /* operators */
    00507
    00514   operator const sockaddr_in*() const
    00515   { return addressV4(); }
    00516
    00522   operator const sockaddr_in6*() const
    00523   { return addressV6(); }
    00524
    00528   KInetSocketAddress& operator=(const KInetSocketAddress &other)
    00529   { setAddress(other); return *this; }
    00530
    00531 private:
    00532
    00533   void fromV4();
    00534   void fromV6();
    00535
    00536 public:
    00544   static QString addrToString(int family, const void *addr);
    00545
    00555   static bool stringToAddr(int family, const char *text, void *dest);
    00556
    00557   friend class KExtendedSocket;
    00558 protected:
    00559   virtual void virtual_hook( int id, void* data );
    00560 private:
    00561   KInetSocketAddressPrivate* d;
    00562 };
    00563
    00564 extern const ::KInetSocketAddress addressAny, addressLoopback;
    00565
    00566 /*
    00567  * External definition KUnixSocketAddress
    00568  */
    00569 struct sockaddr_un;
    00570
    00571 class KUnixSocketAddressPrivate;
    00584 class KDECORE_EXPORT KUnixSocketAddress: public ::KSocketAddress
    00585 {
    00586   Q_OBJECT
    00587 public:
    00591   KUnixSocketAddress();
    00592
    00598   KUnixSocketAddress(const sockaddr_un* raw_data, ksocklen_t size);
    00599
    00604   KUnixSocketAddress(QCString pathname);
    00605
    00609   virtual ~KUnixSocketAddress();
    00610
    00617   bool setAddress(const sockaddr_un* socket_address, ksocklen_t size);
    00618
    00624   bool setAddress(QCString path);
    00625
    00631   QCString pathname() const;
    00632
    00637   virtual QString pretty() const;
    00638
    00639   /*
    00640    * Returns the path in the form of a QString.
    00641    * This can be fed into KExtendedSocket.
    00642    * @return the path (can be QString::null).
    00643    * @see pathname()
    00644    */
    00645   virtual QString serviceName() const;
    00646
    00651   const sockaddr_un* address() const;
    00652
    00658   operator const sockaddr_un*() const
    00659   { return address(); }
    00660
    00671   static bool areEqualUnix(const KSocketAddress &s1, const KSocketAddress &s2, bool coreOnly);
    00672
    00673 private:
    00674   void init();
    00675
    00676   friend class KExtendedSocket;
    00677 protected:
    00678   virtual void virtual_hook( int id, void* data );
    00679 private:
    00680   KUnixSocketAddressPrivate* d;
    00681 };
    00682
    00683 #endif // KSOCKADDR_H

This file is part of the documentation for kdecore Library Version 3.4.1.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat Jun 11 20:18:10 2005 by doxygen 1.4.1 written by Dimitri van Heesch, © 1997-2003