ksockaddr.h

来自「konqueror3 embedded版本, KDE环境下的当家浏览器的嵌入式版」· C头文件 代码 · 共 684 行 · 第 1/2 页

H
684
字号
/* *  This file is part of the KDE libraries *  Copyright (C) 2000-2003 Thiago Macieira <thiago.macieira@kdemail.net> * *  This library is free software; you can redistribute it and/or *  modify it under the terms of the GNU Library General Public *  License as published by the Free Software Foundation; either *  version 2 of the License, or (at your option) any later version. * *  This library is distributed in the hope that it will be useful, *  but WITHOUT ANY WARRANTY; without even the implied warranty of *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU *  Library General Public License for more details. * *  You should have received a copy of the GNU Library General Public License *  along with this library; see the file COPYING.LIB.  If not, write to *  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, *  Boston, MA 02110-1301, USA. */#ifndef KSOCKADDR_H#define KSOCKADDR_H#include <qobject.h>#include <qcstring.h>#include <qstring.h>#include "kdelibs_export.h"/* * This file defines a class that envelopes most, if not all, socket addresses */typedef unsigned ksocklen_t;struct sockaddr;class KExtendedSocket;		// No need to define it fullyclass KSocketAddressPrivate;/** * A socket address. * * This class envelopes almost if not all socket addresses. * * @author Thiago Macieira <thiago.macieira@kdemail.net> * @short a socket address. */class KDECORE_EXPORT KSocketAddress: public QObject{  Q_OBJECTprotected:  /**   * Creates an empty class   */  KSocketAddress() { init(); }  /**   * Creates with given data   * @param sa a sockaddr structure   * @param size the size of @p sa   */  KSocketAddress(const sockaddr* sa, ksocklen_t size);public:  /**   * Destructor.   */  virtual ~KSocketAddress();  /**   * Returns a string representation of this socket.   * @return a pretty string representation   */  virtual QString pretty() const;  /**   * Returns a sockaddr structure, for passing down to library functions.   * @return the sockaddr structure, can be 0   */  const sockaddr* address() const  { return data; }  /**   * Returns sockaddr structure size.   * @return the size of the sockaddr structre, 0 if there is none.   */  virtual ksocklen_t size() const  { return datasize; }  /**   * Returns a sockaddr structure, for passing down to library functions.   * @return the sockaddr structure, can be 0.   * @see address()   */  operator const sockaddr*() const  { return data; }  /**   * Returns the family of this address.   * @return the family of this address, AF_UNSPEC if it's undefined   */  int family() const;  /**   * Returns the IANA family number of this address.   * @return the IANA family number of this address (1 for AF_INET.   *         2 for AF_INET6, otherwise 0)   */  inline int ianaFamily() const  { return ianaFamily(family()); }  /**   * Returns true if this equals the other socket.   * @param other	the other socket   * @return true if both sockets are equal   */  virtual bool isEqual(const KSocketAddress& other) const;  bool isEqual(const KSocketAddress* other) const  { return isEqual(*other); }  /**   * Overloaded == operator.   * @see isEqual()   */  bool operator==(const KSocketAddress& other) const  { return isEqual(other); }  /**   * Some sockets may differ in such things as services or port numbers,   * like Internet sockets. This function compares only the core part   * of that, if possible.   *   * If not possible, like the default implementation, this returns   * the same as isEqual.   * @param other	the other socket   * @return true if the code part is equal   */  bool isCoreEqual(const KSocketAddress& other) const;  /**   * Some sockets may differ in such things as services or port numbers,   * like Internet sockets. This function compares only the core part   * of that, if possible.   *   * If not possible, like the default implementation, this returns   * the same as isEqual.   * @param other	the other socket   * @return true if the code part is equal   */  bool isCoreEqual(const KSocketAddress* other) const  { return isCoreEqual(*other); }  /**   * Returns the node name of this socket, as KExtendedSocket::lookup expects   * as the first argument.   * In the case of Internet sockets, this is the hostname.   * The default implementation returns QString::null.   * @return the node name, can be QString::null   */  virtual QString nodeName() const;  /**   * Returns the service name for this socket, as KExtendedSocket::lookup expects   * as the service argument.   * In the case of Internet sockets, this is the port number.   * The default implementation returns QString::null.   * @return the service name, can be QString::null   */  virtual QString serviceName() const;protected:  sockaddr*	data;  ksocklen_t	datasize;  bool		owndata;private:  void init();  /* No copy constructor */  KSocketAddress(KSocketAddress&);  KSocketAddress& operator=(KSocketAddress&);public:  /**   * Creates a new KSocketAddress or descendant class from given   * raw socket address.   * @param sa		new socket address   * @param size	new socket address's length   * @return the new KSocketAddress, or 0 if the function failed   */  static KSocketAddress* newAddress(const struct sockaddr *sa, ksocklen_t size);  /**   * Returns the IANA family number of the given address family.   * Returns 0 if there is no corresponding IANA family number.   * @param af		the address family, in AF_* constants   * @return the IANA family number of this address (1 for AF_INET.   *         2 for AF_INET6, otherwise 0)   */  static int ianaFamily(int af);  /**   * Returns the address family of the given IANA family number.   * @return the address family, AF_UNSPEC for unknown IANA family numbers   */  static int fromIanaFamily(int iana);  friend class KExtendedSocket;protected:  virtual void virtual_hook( int id, void* data );private:  KSocketAddressPrivate* d;};/* * External definitions * We need these for KInetSocketAddress */struct sockaddr_in;struct sockaddr_in6;struct in_addr;struct in6_addr;class KInetSocketAddressPrivate;/** * An Inet (IPv4 or IPv6) socket address * * This is an IPv4 or IPv6 address of the Internet * * This class inherits most of the functionality from KSocketAddress, but * is targeted specifically to Internet addresses * * @author Thiago Macieira <thiago.macieira@kdemail.net> * @short an Internet socket address */class KDECORE_EXPORT KInetSocketAddress: public ::KSocketAddress{  Q_OBJECTpublic:  /**   * Default constructor. Does nothing   */  KInetSocketAddress();  /**   * Copy constructor   */  KInetSocketAddress(const KInetSocketAddress&);  /**   * Creates an IPv4 socket from raw sockaddr_in.   * @param sin		a sockaddr_in structure to copy from   * @param len		the socket address length   */  KInetSocketAddress(const sockaddr_in* sin, ksocklen_t len);  /**   * Creates an IPv6 socket from raw sockaddr_in6.   * @param sin6       	a sockaddr_in6 structure to copy from   * @param len		the socket address length   */  KInetSocketAddress(const sockaddr_in6* sin6, ksocklen_t len);  /**   * Creates a socket from information.   * @param addr	a binary address   * @param port	a port number   */  KInetSocketAddress(const in_addr& addr, unsigned short port);  /**   * Creates a socket from information.   * @param addr	a binary address   * @param port	a port number   */  KInetSocketAddress(const in6_addr& addr, unsigned short port);  /**   * Creates a socket from text representation.   *   * @param addr	a text representation of the address   * @param port	a port number   * @param family	the family for this address. Use -1 to guess the   *                    family type   * @see setAddress   */  KInetSocketAddress(const QString& addr, unsigned short port, int family = -1);  /**   * Destructor   */  virtual ~KInetSocketAddress();  /**   * Sets this socket to given socket.   * @param ksa		the other socket   * @return true if successful, false otherwise   */  bool setAddress(const KInetSocketAddress& ksa);  /**   * Sets this socket to given raw socket.   * @param sin		the raw socket   * @param len		the socket address length   * @return true if successful, false otherwise   */  bool setAddress(const sockaddr_in* sin, ksocklen_t len);  /**   * Sets this socket to given raw socket.   *   * Note: this function does not clear the scope ID and flow info values   * @param sin6	the raw socket   * @param len		the socket address length   * @return true if successful, false otherwise   */  bool setAddress(const sockaddr_in6* sin6, ksocklen_t len);  /**   * Sets this socket to raw address and port.   * @param addr	the address   * @param port	the port number   * @return true if successful, false otherwise   */  bool setAddress(const in_addr& addr, unsigned short port);  /**   * Sets this socket to raw address and port.   * @param addr	the address   * @param port	the port number   * @return true if successful, false otherwise   */  bool setAddress(const in6_addr& addr, unsigned short port);  /**   * Sets this socket to text address and port   *   * You can use the @p family parameter to specify what kind of socket   * you want this to be. It could be AF_INET or AF_INET6 or -1.   *   * If the value is -1 (default), this function will make an effort to   * discover what is the family. That isn't too hard, actually, and it   * works in all cases. But, if you want to be sure that your socket   * is of the type you want, use this parameter.   *

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?