ksockaddr.h
来自「konqueror3 embedded版本, KDE环境下的当家浏览器的嵌入式版」· C头文件 代码 · 共 684 行 · 第 1/2 页
H
684 行
* This function returns false if the socket address was not valid. * @param addr the address * @param port the port number * @param family the address family, -1 for any * @return true if successful, false otherwise */ bool setAddress(const QString& addr, unsigned short port, int family = -1); /** * Sets this socket's host address to given raw address. * @param addr the address * @return true if successful, false otherwise */ bool setHost(const in_addr& addr); /** * Sets this socket's host address to given raw address. * @param addr the address * @return true if successful, false otherwise */ bool setHost(const in6_addr& addr); /** * Sets this socket's host address to given text representation. * @param addr the address * @param family the address family, -1 to guess the family * @return true if successful, false otherwise */ bool setHost(const QString& addr, int family = -1); /** * Sets this socket's port number to given port number. * @param port the port number * @return true if successful, false otherwise */ bool setPort(unsigned short port); /** * Turns this into an IPv4 or IPv6 address. * * @param family the new address family * @return false if this is v6 and information was lost. That doesn't * mean the conversion was unsuccessful. */ bool setFamily(int family); /** * Sets flowinfo information for this socket address if this is IPv6. * @param flowinfo flowinfo * @return true if successful, false otherwise */ bool setFlowinfo(Q_UINT32 flowinfo); /** * Sets the scope id for this socket if this is IPv6. * @param scopeid the scope id * @return true if successful, false otherwise */ bool setScopeId(int scopeid); /** * Returns a pretty representation of this address. * @return a pretty representation */ virtual QString pretty() const; /** * Returns the text representation of the host address. * @return a text representation of the host address */ virtual QString nodeName() const; // QString prettyHost() const; /** * Returns the text representation of the port number. * @return the name of the service (a number) */ virtual QString serviceName() const; /** * Returns the socket address. * * This will be NULL if this is a non-convertible v6. * This function will return an IPv4 socket if this IPv6 * socket is a v4-mapped address. That is, if it's really * an IPv4 address, but in v6 disguise. * @return the sockaddr_in struct, can be 0. */ const sockaddr_in* addressV4() const; /** * Returns the socket address in IPv6 * @return the sockaddr_in struct, can be 0 if IPv6 is unsupported. */ const sockaddr_in6* addressV6() const; /** * Returns the host address. * Might be empty. * @return the host address */ in_addr hostV4() const; /** * Returns the host address. * * WARNING: this function is not defined if there is no IPv6 support * @return the host address */ in6_addr hostV6() const; /** * Returns the port number. * @return the port number */ unsigned short port() const; /** * Returns flowinfo for IPv6 socket. * @return the flowinfo, 0 if unsupported */ Q_UINT32 flowinfo() const; /** * Returns the scope id for this IPv6 socket. * @return the scope id */ int scopeId() const; /** * Returns the socket length. * Will be either sizeof(sockaddr_in) or sizeof(sockaddr_in6) * @return the length of the socket */ virtual ksocklen_t size() const; // should be socklen_t /* comparation */ /** * Compares two IPv4 addresses. * @param s1 the first address to compare * @param s2 the second address to compare * @param coreOnly true if only core parts should be compared (only * the address) * @return true if the given addresses are equal. * @see areEqualInet6() * @see KSocketAddress::isEqual() * @see KSocketAddress::isCoreEqual() */ static bool areEqualInet(const KSocketAddress &s1, const KSocketAddress &s2, bool coreOnly); /** * Compares two IPv6 addresses. * @param s1 the first address to compare * @param s2 the second address to compare * @param coreOnly true if only core parts should be compared (only * the address) * @return true if the given addresses are equal. * @see areEqualInet() * @see KSocketAddress::isEqual() * @see KSocketAddress::isCoreEqual() */ static bool areEqualInet6(const KSocketAddress &s1, const KSocketAddress &s2, bool coreOnly); /* operators */ /** * Returns the socket address. * This will be NULL if this is a non-convertible v6. * @return the sockaddr_in structure, can be 0 if v6. * @see addressV4() */ operator const sockaddr_in*() const { return addressV4(); } /** * Returns the socket address. * @return the sockaddr_in structure, can be 0 if v6 is unsupported. * @see addressV6() */ operator const sockaddr_in6*() const { return addressV6(); } /** * Sets this object to be the same as the other. */ KInetSocketAddress& operator=(const KInetSocketAddress &other) { setAddress(other); return *this; }private: void fromV4(); void fromV6();public: /** * Convert s the given raw address into text form. * This function returns QString::null if the address cannot be converted. * @param family the family of the address * @param addr the address, in raw form * @return the converted address, or QString::null if not possible. */ static QString addrToString(int family, const void *addr); /** * Converts the address given in text form into raw form. * The size of the destination buffer @p dest is supposed to be * large enough to hold the address of the given family. * @param family the family of the address * @param text the text representation of the address * @param dest the destination buffer of the address * @return true if convertion was successful. */ static bool stringToAddr(int family, const char *text, void *dest); friend class KExtendedSocket;protected: virtual void virtual_hook( int id, void* data );private: KInetSocketAddressPrivate* d;};extern const ::KInetSocketAddress addressAny, addressLoopback;/* * External definition KUnixSocketAddress */struct sockaddr_un;class KUnixSocketAddressPrivate;/** * A Unix socket address * * This is a Unix socket address. * * This class expects QCString instead of QString values, which means the * filenames should be encoded in whatever form locale/system deems necessary * before passing down to the function * * @author Thiago Macieira <thiago.macieira@kdemail.net> * @short a Unix socket address */class KDECORE_EXPORT KUnixSocketAddress: public ::KSocketAddress{ Q_OBJECTpublic: /** * Default constructor */ KUnixSocketAddress(); /** * Constructor from raw data. * @param raw_data raw data * @param size data length */ KUnixSocketAddress(const sockaddr_un* raw_data, ksocklen_t size); /** * Constructor from pathname. * @param pathname pathname */ KUnixSocketAddress(QCString pathname); /** * Destructor */ virtual ~KUnixSocketAddress(); /** * Sets this to given sockaddr_un. * @param socket_address socket address * @param size the socket length * @return true if successful, false otherwise */ bool setAddress(const sockaddr_un* socket_address, ksocklen_t size); /** * Sets this to given pathname. * @param path pathname * @return true if successful, false otherwise */ bool setAddress(QCString path); /** * Returns the pathname. * @return the pathname, can be QCString::null if uninitialized, or * "" if unknown */ QCString pathname() const; /** * Returns pretty representation of this socket. * @return a pretty text representation of the socket. */ virtual QString pretty() const; /* * Returns the path in the form of a QString. * This can be fed into KExtendedSocket. * @return the path (can be QString::null). * @see pathname() */ virtual QString serviceName() const; /** * Returns raw socket address. * @return the raw socket address (can be 0 if uninitialized) */ const sockaddr_un* address() const; /** * Returns raw socket address. * @return the raw socket address (can be 0 if uninitialized) * @see address() */ operator const sockaddr_un*() const { return address(); } /** * Compares two unix socket addresses. * @param s1 the first address to compare * @param s2 the second address to compare * @param coreOnly true if only core parts should be compared (currently * unused) * @return true if the given addresses are equal. * @see KSocketAddress::isEqual() * @see KSocketAddress::isCoreEqual() */ static bool areEqualUnix(const KSocketAddress &s1, const KSocketAddress &s2, bool coreOnly);private: void init(); friend class KExtendedSocket;protected: virtual void virtual_hook( int id, void* data );private: KUnixSocketAddressPrivate* d;};#endif // KSOCKADDR_H
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?