KDECore
KNetwork::KSocketAddress Class Reference
A generic socket address. More...
#include <ksocketaddress.h>
Public Member Functions | |
sockaddr * | address () |
const sockaddr * | address () const |
KInetSocketAddress | asInet () const |
KInetSocketAddress & | asInet () |
KUnixSocketAddress | asUnix () const |
KUnixSocketAddress & | asUnix () |
int | family () const |
int | ianaFamily () const |
KSocketAddress (const KSocketAddress &other) | |
KSocketAddress (const sockaddr *sa, Q_UINT16 len) | |
KSocketAddress () | |
Q_UINT16 | length () const |
virtual QString | nodeName () const |
operator const sockaddr * () const | |
KSocketAddress & | operator= (const KSocketAddress &other) |
bool | operator== (const KSocketAddress &other) const |
virtual QString | serviceName () const |
KSocketAddress & | setAddress (const sockaddr *sa, Q_UINT16 len) |
virtual KSocketAddress & | setFamily (int family) |
KSocketAddress & | setLength (Q_UINT16 len) |
virtual QString | toString () const |
virtual | ~KSocketAddress () |
Static Public Member Functions | |
static int | fromIanaFamily (int iana) |
static int | ianaFamily (int af) |
Protected Member Functions | |
KSocketAddress (KSocketAddressData *d) | |
Protected Attributes | |
KSocketAddressData * | d |
Detailed Description
A generic socket address.This class holds one generic socket address.
Definition at line 423 of file ksocketaddress.h.
Constructor & Destructor Documentation
KSocketAddress::KSocketAddress | ( | ) |
KSocketAddress::KSocketAddress | ( | const sockaddr * | sa, | |
Q_UINT16 | len | |||
) |
Creates this object with the given data.
The raw socket address is copied into this object.
- Parameters:
-
sa the socket address structure len the socket address length
Definition at line 414 of file ksocketaddress.cpp.
KSocketAddress::KSocketAddress | ( | const KSocketAddress & | other | ) |
Copy constructor.
This creates a copy of the other object.
Data is not shared.
- Parameters:
-
other the object to copy from
Definition at line 420 of file ksocketaddress.cpp.
KSocketAddress::~KSocketAddress | ( | ) | [virtual] |
KSocketAddress::KSocketAddress | ( | KSocketAddressData * | d | ) | [protected] |
Member Function Documentation
sockaddr * KSocketAddress::address | ( | ) |
Returns the socket address structure, to be passed down to low level functions.
Note that this function returns NULL for invalid or empty sockets, so you may use to to test for validity.
The returned value, if not NULL, is an internal buffer which is guaranteed to be at least length() bytes long.
Definition at line 458 of file ksocketaddress.cpp.
const sockaddr * KSocketAddress::address | ( | ) | const |
Returns the socket address structure, to be passed down to low level functions.
Note that this function returns NULL for invalid or empty sockets, so you may use to to test for validity.
Definition at line 451 of file ksocketaddress.cpp.
KInetSocketAddress KSocketAddress::asInet | ( | ) | const |
Returns an object is equal to this object's data, but they don't share it.
Definition at line 635 of file ksocketaddress.cpp.
KInetSocketAddress & KSocketAddress::asInet | ( | ) |
Returns an object reference that can be used to manipulate this socket as an Internet socket address.
Both objects share the same data.
Definition at line 630 of file ksocketaddress.cpp.
KUnixSocketAddress KSocketAddress::asUnix | ( | ) | const |
Returns an object is equal to this object's data, but they don't share it.
Definition at line 645 of file ksocketaddress.cpp.
KUnixSocketAddress & KSocketAddress::asUnix | ( | ) |
Returns an object reference that can be used to manipulate this socket as a Unix socket address.
Both objects share the same data.
Definition at line 640 of file ksocketaddress.cpp.
int KSocketAddress::family | ( | ) | const |
Returns the family of this address.
- Returns:
- the family of this address, AF_UNSPEC if it's undefined
Definition at line 489 of file ksocketaddress.cpp.
int KSocketAddress::fromIanaFamily | ( | int | iana | ) | [static] |
Returns the address family of the given IANA family number.
- Returns:
- the address family, AF_UNSPEC for unknown IANA family numbers
Definition at line 667 of file ksocketaddress.cpp.
int KSocketAddress::ianaFamily | ( | int | af | ) | [static] |
Returns the IANA family number of the given address family.
Returns 0 if there is no corresponding IANA family number.
- Parameters:
-
af the address family, in AF_* constants
- Returns:
- the IANA family number of this address (1 for AF_INET. 2 for AF_INET6, otherwise 0)
Definition at line 650 of file ksocketaddress.cpp.
int KNetwork::KSocketAddress::ianaFamily | ( | ) | const [inline] |
Returns the IANA family number of this address.
- Returns:
- the IANA family number of this address (1 for AF_INET. 2 for AF_INET6, otherwise 0)
Definition at line 550 of file ksocketaddress.h.
Q_UINT16 KSocketAddress::length | ( | ) | const |
Returns the length of this socket address structure.
Definition at line 475 of file ksocketaddress.cpp.
QString KSocketAddress::nodeName | ( | ) | const [virtual] |
Returns the node name of this socket.
In the case of Internet sockets, this is string representation of the IP address. The default implementation returns QString::null.
- Returns:
- the node name, can be QString::null
Definition at line 562 of file ksocketaddress.cpp.
KNetwork::KSocketAddress::operator const sockaddr * | ( | ) | const [inline] |
Returns the socket address structure, to be passed down to low level functions.
Definition at line 499 of file ksocketaddress.h.
KSocketAddress & KSocketAddress::operator= | ( | const KSocketAddress & | other | ) |
Performs a shallow copy of the other object into this one.
Data will be copied.
- Parameters:
-
other the object to copy from
Definition at line 442 of file ksocketaddress.cpp.
bool KSocketAddress::operator== | ( | const KSocketAddress & | other | ) | const |
Returns true if this equals the other socket.
Socket addresses are considered matching if and only if all data is the same.
- Parameters:
-
other the other socket
- Returns:
- true if both sockets are equal
Definition at line 505 of file ksocketaddress.cpp.
QString KSocketAddress::serviceName | ( | ) | const [virtual] |
Returns the service name for this socket.
In the case of Internet sockets, this is the port number. The default implementation returns QString::null.
- Returns:
- the service name, can be QString::null
Definition at line 588 of file ksocketaddress.cpp.
KSocketAddress & KSocketAddress::setAddress | ( | const sockaddr * | sa, | |
Q_UINT16 | len | |||
) |
Sets the address to the given address.
The raw socket address is copied into this object.
- Parameters:
-
sa the socket address structure len the socket address length
Definition at line 465 of file ksocketaddress.cpp.
KSocketAddress & KSocketAddress::setFamily | ( | int | family | ) | [virtual] |
Sets the family of this object.
Note: setting the family will probably invalidate any address data contained in this object. Use this function with care.
- Parameters:
-
family the new family to set
Definition at line 496 of file ksocketaddress.cpp.
KSocketAddress & KSocketAddress::setLength | ( | Q_UINT16 | len | ) |
Sets the length of this socket structure.
Use this function with care. It allows you to resize the internal buffer to fit needs. This function should not be used except for handling unknown socket address structures.
Also note that this function may invalidate the socket if a known family is set (Internet or Unix socket) and the new length would be too small to hold the system's sockaddr_* structure. If unsure, reset the family:
KSocketAddress qsa; [...] qsa.setFamily(AF_UNSPEC).setLength(newlen);
- Parameters:
-
len the new length
Definition at line 482 of file ksocketaddress.cpp.
QString KSocketAddress::toString | ( | ) | const [virtual] |
Returns this socket address as a string suitable for printing.
Family, node and service are part of this address.
Definition at line 608 of file ksocketaddress.cpp.
Member Data Documentation
KSocketAddressData* KNetwork::KSocketAddress::d [protected] |
The documentation for this class was generated from the following files: