kdecore Library API Documentation

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 00027 /* 00028 * This file defines a class that envelopes most, if not all, socket addresses 00029 */ 00030 typedef unsigned ksocklen_t; 00031 00032 struct sockaddr; 00033 00034 class KExtendedSocket; // No need to define it fully 00035 00036 class KSocketAddressPrivate; 00045 class KSocketAddress: public QObject 00046 { 00047 Q_OBJECT 00048 protected: 00052 KSocketAddress() { init(); } 00053 00059 KSocketAddress(const sockaddr* sa, ksocklen_t size); 00060 00061 public: 00065 virtual ~KSocketAddress(); 00066 00071 virtual QString pretty() const; 00072 00077 const sockaddr* address() const 00078 { return data; } 00079 00084 virtual ksocklen_t size() const 00085 { return datasize; } 00086 00092 operator const sockaddr*() const 00093 { return data; } 00094 00099 int family() const; 00100 00106 inline int ianaFamily() const 00107 { return ianaFamily(family()); } 00108 00114 virtual bool isEqual(const KSocketAddress& other) const; 00115 bool isEqual(const KSocketAddress* other) const 00116 { return isEqual(*other); } 00117 00122 bool operator==(const KSocketAddress& other) const 00123 { return isEqual(other); } 00124 00135 bool isCoreEqual(const KSocketAddress& other) const; 00136 00147 bool isCoreEqual(const KSocketAddress* other) const 00148 { return isCoreEqual(*other); } 00149 00157 virtual QString nodeName() const; 00158 00166 virtual QString serviceName() const; 00167 00168 protected: 00169 sockaddr* data; 00170 ksocklen_t datasize; 00171 bool owndata; 00172 00173 private: 00174 void init(); 00175 /* No copy constructor */ 00176 KSocketAddress(KSocketAddress&); 00177 KSocketAddress& operator=(KSocketAddress&); 00178 00179 public: 00187 static KSocketAddress* newAddress(const struct sockaddr *sa, ksocklen_t size); 00188 00196 static int ianaFamily(int af); 00197 00202 static int fromIanaFamily(int iana); 00203 00204 friend class KExtendedSocket; 00205 protected: 00206 virtual void virtual_hook( int id, void* data ); 00207 private: 00208 KSocketAddressPrivate* d; 00209 }; 00210 00211 /* 00212 * External definitions 00213 * We need these for KInetSocketAddress 00214 */ 00215 struct sockaddr_in; 00216 struct sockaddr_in6; 00217 struct in_addr; 00218 struct in6_addr; 00219 00220 class KInetSocketAddressPrivate; 00232 class KInetSocketAddress: public ::KSocketAddress 00233 { 00234 Q_OBJECT 00235 public: 00239 KInetSocketAddress(); 00240 00244 KInetSocketAddress(const KInetSocketAddress&); 00245 00251 KInetSocketAddress(const sockaddr_in* sin, ksocklen_t len); 00252 00258 KInetSocketAddress(const sockaddr_in6* sin6, ksocklen_t len); 00259 00265 KInetSocketAddress(const in_addr& addr, unsigned short port); 00266 00272 KInetSocketAddress(const in6_addr& addr, unsigned short port); 00273 00283 KInetSocketAddress(const QString& addr, unsigned short port, int family = -1); 00284 00288 virtual ~KInetSocketAddress(); 00289 00295 bool setAddress(const KInetSocketAddress& ksa); 00296 00303 bool setAddress(const sockaddr_in* sin, ksocklen_t len); 00304 00313 bool setAddress(const sockaddr_in6* sin6, ksocklen_t len); 00314 00321 bool setAddress(const in_addr& addr, unsigned short port); 00322 00329 bool setAddress(const in6_addr& addr, unsigned short port); 00330 00348 bool setAddress(const QString& addr, unsigned short port, int family = -1); 00349 00355 bool setHost(const in_addr& addr); 00356 00362 bool setHost(const in6_addr& addr); 00363 00370 bool setHost(const QString& addr, int family = -1); 00371 00377 bool setPort(unsigned short port); 00378 00386 bool setFamily(int family); 00387 00393 bool setFlowinfo(Q_UINT32 flowinfo); 00394 00400 bool setScopeId(int scopeid); 00401 00406 virtual QString pretty() const; 00407 00412 virtual QString nodeName() const; 00413 // QString prettyHost() const; 00414 00419 virtual QString serviceName() const; 00420 00430 const sockaddr_in* addressV4() const; 00431 00436 const sockaddr_in6* addressV6() const; 00437 00443 in_addr hostV4() const; 00444 00451 in6_addr hostV6() const; 00452 00457 unsigned short port() const; 00458 00463 Q_UINT32 flowinfo() const; 00464 00469 int scopeId() const; 00470 00476 virtual ksocklen_t size() const; // should be socklen_t 00477 00478 /* comparation */ 00490 static bool areEqualInet(const KSocketAddress &s1, const KSocketAddress &s2, bool coreOnly); 00491 00503 static bool areEqualInet6(const KSocketAddress &s1, const KSocketAddress &s2, bool coreOnly); 00504 00505 /* operators */ 00506 00513 operator const sockaddr_in*() const 00514 { return addressV4(); } 00515 00521 operator const sockaddr_in6*() const 00522 { return addressV6(); } 00523 00527 KInetSocketAddress& operator=(const KInetSocketAddress &other) 00528 { setAddress(other); return *this; } 00529 00530 private: 00531 00532 void fromV4(); 00533 void fromV6(); 00534 00535 public: 00543 static QString addrToString(int family, const void *addr); 00544 00554 static bool stringToAddr(int family, const char *text, void *dest); 00555 00556 friend class KExtendedSocket; 00557 protected: 00558 virtual void virtual_hook( int id, void* data ); 00559 private: 00560 KInetSocketAddressPrivate* d; 00561 }; 00562 00563 extern const ::KInetSocketAddress addressAny, addressLoopback; 00564 00565 /* 00566 * External definition KUnixSocketAddress 00567 */ 00568 struct sockaddr_un; 00569 00570 class KUnixSocketAddressPrivate; 00583 class KUnixSocketAddress: public ::KSocketAddress 00584 { 00585 Q_OBJECT 00586 public: 00590 KUnixSocketAddress(); 00591 00597 KUnixSocketAddress(const sockaddr_un* raw_data, ksocklen_t size); 00598 00603 KUnixSocketAddress(QCString pathname); 00604 00608 virtual ~KUnixSocketAddress(); 00609 00616 bool setAddress(const sockaddr_un* socket_address, ksocklen_t size); 00617 00623 bool setAddress(QCString path); 00624 00630 QCString pathname() const; 00631 00636 virtual QString pretty() const; 00637 00638 /* 00639 * Returns the path in the form of a QString. 00640 * This can be fed into KExtendedSocket. 00641 * @return the path (can be QString::null). 00642 * @see pathname() 00643 */ 00644 virtual QString serviceName() const; 00645 00650 const sockaddr_un* address() const; 00651 00657 operator const sockaddr_un*() const 00658 { return address(); } 00659 00670 static bool areEqualUnix(const KSocketAddress &s1, const KSocketAddress &s2, bool coreOnly); 00671 00672 private: 00673 void init(); 00674 00675 friend class KExtendedSocket; 00676 protected: 00677 virtual void virtual_hook( int id, void* data ); 00678 private: 00679 KUnixSocketAddressPrivate* d; 00680 }; 00681 00682 #endif // KSOCKADDR_H
KDE Logo
This file is part of the documentation for kdecore Library Version 3.3.1.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sun Oct 17 11:26:09 2004 by doxygen 1.3.8 written by Dimitri van Heesch, © 1997-2003