| # kdecore Library API Documentation
Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Source Files

# ksockaddr.h

    00001 /*
    00002  *  This file is part of the KDE libraries
    00003  *  Copyright (C) 2000,2001 Thiago Macieira <thiagom@mail.com>
    00004  *
    00005  *  $Id: ksockaddr.h,v 1.15 2002/09/09 21:11:35 tjansen Exp $
    00006  *
    00007  *  This library is free software; you can redistribute it and/or
    00008  *  modify it under the terms of the GNU Library General Public
    00009  *  License as published by the Free Software Foundation; either
    00010  *  version 2 of the License, or (at your option) any later version.
    00011  *
    00012  *  This library is distributed in the hope that it will be useful,
    00013  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
    00014  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00015  *  Library General Public License for more details.
    00016  *
    00017  *  You should have received a copy of the GNU Library General Public License
    00018  *  along with this library; see the file COPYING.LIB.  If not, write to
    00019  *  the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    00020  *  Boston, MA 02111-1307, USA.
    00021  */
    00022 #ifndef KSOCKADDR_H
    00023 #define KSOCKADDR_H
    00024
    00025 #include <qobject.h>
    00026 #include <qcstring.h>
    00027 #include <qstring.h>
    00028
    00029 /*
    00030  * This file defines a class that envelopes most, if not all, socket addresses
    00031  */
    00032 typedef unsigned ksocklen_t;
    00033
    00034 struct sockaddr;
    00035
    00036 class KExtendedSocket;          // No need to define it fully
    00037
    00038 class KSocketAddressPrivate;
    00048 class KSocketAddress: public QObject
    00049 {
    00050   Q_OBJECT
    00051 protected:
    00055   KSocketAddress() { init(); }
    00056
    00062   KSocketAddress(const sockaddr* sa, ksocklen_t size);
    00063
    00064 public:
    00068   virtual ~KSocketAddress();
    00069
    00074   virtual QString pretty() const;
    00075
    00080   const sockaddr* address() const
    00081   { return data; }
    00082
    00087   virtual ksocklen_t size() const
    00088   { return datasize; }
    00089
    00095   operator const sockaddr*() const
    00096   { return data; }
    00097
    00102   int family() const;
    00103
    00109   inline int ianaFamily() const
    00110   { return ianaFamily(family()); }
    00111
    00117   virtual bool isEqual(const KSocketAddress& other) const;
    00118   bool isEqual(const KSocketAddress* other) const
    00119   { return isEqual(*other); }
    00120
    00125   bool operator==(const KSocketAddress& other) const
    00126   { return isEqual(other); }
    00127
    00138   bool isCoreEqual(const KSocketAddress& other) const;
    00139
    00150   bool isCoreEqual(const KSocketAddress* other) const
    00151   { return isCoreEqual(*other); }
    00152
    00160   virtual QString nodeName() const;
    00161
    00169   virtual QString serviceName() const;
    00170
    00171 protected:
    00172   sockaddr*     data;
    00173   ksocklen_t    datasize;
    00174   bool          owndata;
    00175
    00176 private:
    00177   void init();
    00178   /* No copy constructor */
    00179   KSocketAddress(KSocketAddress&);
    00180   KSocketAddress& operator=(KSocketAddress&);
    00181
    00182 public:
    00190   static KSocketAddress* newAddress(const struct sockaddr*, ksocklen_t size);
    00191
    00199   static int ianaFamily(int af);
    00200
    00205   static int fromIanaFamily(int iana);
    00206
    00207   friend class KExtendedSocket;
    00208 protected:
    00209   virtual void virtual_hook( int id, void* data );
    00210 private:
    00211   KSocketAddressPrivate* d;
    00212 };
    00213
    00214 /*
    00215  * External definitions
    00216  * We need these for KInetSocketAddress
    00217  */
    00218 struct sockaddr_in;
    00219 struct sockaddr_in6;
    00220 struct in_addr;
    00221 struct in6_addr;
    00222
    00223 class KInetSocketAddressPrivate;
    00236 class KInetSocketAddress: public KSocketAddress
    00237 {
    00238   Q_OBJECT
    00239 public:
    00243   KInetSocketAddress();
    00244
    00248   KInetSocketAddress(const KInetSocketAddress&);
    00249
    00255   KInetSocketAddress(const sockaddr_in* sin, ksocklen_t len);
    00256
    00262   KInetSocketAddress(const sockaddr_in6* sin6, ksocklen_t len);
    00263
    00269   KInetSocketAddress(const in_addr& addr, unsigned short port);
    00270
    00276   KInetSocketAddress(const in6_addr& addr, unsigned short port);
    00277
    00287   KInetSocketAddress(const QString& addr, unsigned short port, int family = -1);
    00288
    00292   virtual ~KInetSocketAddress();
    00293
    00299   bool setAddress(const KInetSocketAddress& ksa);
    00300
    00307   bool setAddress(const sockaddr_in* sin, ksocklen_t len);
    00308
    00317   bool setAddress(const sockaddr_in6* sin6, ksocklen_t len);
    00318
    00325   bool setAddress(const in_addr& addr, unsigned short port);
    00326
    00333   bool setAddress(const in6_addr& addr, unsigned short port);
    00334
    00352   bool setAddress(const QString& addr, unsigned short port, int family = -1);
    00353
    00359   bool setHost(const in_addr& addr);
    00360
    00366   bool setHost(const in6_addr& addr);
    00367
    00374   bool setHost(const QString& addr, int family = -1);
    00375
    00381   bool setPort(unsigned short port);
    00382
    00390   bool setFamily(int family);
    00391
    00397   bool setFlowinfo(Q_UINT32 flowinfo);
    00398
    00404   bool setScopeId(int scopeid);
    00405
    00410   virtual QString pretty() const;
    00411
    00416   virtual QString nodeName() const;
    00417   //  QString prettyHost() const;
    00418
    00423   virtual QString serviceName() const;
    00424
    00434   const sockaddr_in* addressV4() const;
    00435
    00440   const sockaddr_in6* addressV6() const;
    00441
    00447   in_addr hostV4() const;
    00448
    00455   in6_addr hostV6() const;
    00456
    00461   unsigned short port() const;
    00462
    00467   Q_UINT32 flowinfo() const;
    00468
    00473   int scopeId() const;
    00474
    00480   virtual ksocklen_t size() const; // should be socklen_t
    00481
    00482   /* comparation */
    00494   static bool areEqualInet(const KSocketAddress &s1, const KSocketAddress &s2, bool coreOnly);
    00495
    00507   static bool areEqualInet6(const KSocketAddress &s1, const KSocketAddress &s2, bool coreOnly);
    00508
    00509   /* operators */
    00510
    00517   operator const sockaddr_in*() const
    00518   { return addressV4(); }
    00519
    00525   operator const sockaddr_in6*() const
    00526   { return addressV6(); }
    00527
    00531   KInetSocketAddress& operator=(const KInetSocketAddress &other)
    00532   { setAddress(other); return *this; }
    00533
    00534 private:
    00535
    00536   void fromV4();
    00537   void fromV6();
    00538
    00539 public:
    00547   static QString addrToString(int family, const void *addr);
    00548
    00558   static bool stringToAddr(int family, const char *text, void *dest);
    00559
    00560   friend class KExtendedSocket;
    00561 protected:
    00562   virtual void virtual_hook( int id, void* data );
    00563 private:
    00564   KInetSocketAddressPrivate* d;
    00565 };
    00566
    00567 extern const KInetSocketAddress addressAny, addressLoopback;
    00568
    00569 /*
    00570  * External definition KUnixSocketAddress
    00571  */
    00572 struct sockaddr_un;
    00573
    00574 class KUnixSocketAddressPrivate;
    00588 class KUnixSocketAddress: public KSocketAddress
    00589 {
    00590   Q_OBJECT
    00591 public:
    00595   KUnixSocketAddress();
    00596
    00602   KUnixSocketAddress(const sockaddr_un* raw_data, ksocklen_t size);
    00603
    00608   KUnixSocketAddress(QCString pathname);
    00609
    00613   virtual ~KUnixSocketAddress();
    00614
    00621   bool setAddress(const sockaddr_un* socket_address, ksocklen_t size);
    00622
    00628   bool setAddress(QCString path);
    00629
    00635   QCString pathname() const;
    00636
    00641   virtual QString pretty() const;
    00642
    00643   /*
    00644    * Returns the path in the form of a QString.
    00645    * This can be fed into KExtendedSocket.
    00646    * @return the path (can be QString::null).
    00647    * @see pathname()
    00648    */
    00649   virtual QString serviceName() const;
    00650
    00655   const sockaddr_un* address() const;
    00656
    00662   operator const sockaddr_un*() const
    00663   { return address(); }
    00664
    00675   static bool areEqualUnix(const KSocketAddress &s1, const KSocketAddress &s2, bool coreOnly);
    00676
    00677 private:
    00678   void init();
    00679
    00680   friend class KExtendedSocket;
    00681 protected:
    00682   virtual void virtual_hook( int id, void* data );
    00683 private:
    00684   KUnixSocketAddressPrivate* d;
    00685 };
    00686
    00687 #endif // KSOCKADDR_H

This file is part of the documentation for kdelibs Version 3.1.5.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Wed Jan 28 12:46:55 2004 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001