kdecore Library API Documentation

KNetwork::KSocketAddress Class Reference

A generic socket address. More...

#include <ksocketaddress.h>

Inheritance diagram for KNetwork::KSocketAddress:

Inheritance graph
[legend]
List of all members.

Public Member Functions

 KSocketAddress ()
 KSocketAddress (const sockaddr *sa, Q_UINT16 len)
 KSocketAddress (const KSocketAddress &other)
virtual ~KSocketAddress ()
KSocketAddressoperator= (const KSocketAddress &other)
const sockaddr * address () const
sockaddr * address ()
KSocketAddresssetAddress (const sockaddr *sa, Q_UINT16 len)
 operator const sockaddr * () const
Q_UINT16 length () const
KSocketAddresssetLength (Q_UINT16 len)
int family () const
virtual KSocketAddresssetFamily (int family)
int ianaFamily () const
bool operator== (const KSocketAddress &other) const
virtual QString nodeName () const
virtual QString serviceName () const
virtual QString toString () const
KInetSocketAddressasInet ()
KInetSocketAddress asInet () const
KUnixSocketAddressasUnix ()
KUnixSocketAddress asUnix () const

Static Public Member Functions

int ianaFamily (int af)
int fromIanaFamily (int iana)

Protected Member Functions

 KSocketAddress (KSocketAddressData *d)

Protected Attributes

KSocketAddressData * d

Detailed Description

A generic socket address.

This class holds one generic socket address.

Author:
Thiago Macieira <thiago.macieira@kdemail.net>

Definition at line 413 of file ksocketaddress.h.


Constructor & Destructor Documentation

KNetwork::KSocketAddress::KSocketAddress  ) 
 

Default constructor.

Creates an empty object

KNetwork::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

KNetwork::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

virtual KNetwork::KSocketAddress::~KSocketAddress  )  [virtual]
 

Destructor.

Frees any associated resources.


Member Function Documentation

KSocketAddress& KNetwork::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

const sockaddr* KNetwork::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.

Referenced by KNetwork::KSocketDevice::disconnect(), KNetwork::KSocksSocketDevice::localAddress(), KNetwork::KSocketDevice::localAddress(), KNetwork::KSocksSocketDevice::peerAddress(), KNetwork::KSocketDevice::peerAddress(), KNetwork::KSocksSocketDevice::writeBlock(), and KNetwork::KSocketDevice::writeBlock().

sockaddr* KNetwork::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.

KSocketAddress& KNetwork::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

KNetwork::KSocketAddress::operator const sockaddr *  )  const [inline]
 

Returns the socket address structure, to be passed down to low level functions.

Definition at line 489 of file ksocketaddress.h.

Q_UINT16 KNetwork::KSocketAddress::length  )  const
 

Returns the length of this socket address structure.

Referenced by KNetwork::KSocketDevice::disconnect(), KNetwork::KSocksSocketDevice::localAddress(), KNetwork::KSocketDevice::localAddress(), KNetwork::KSocksSocketDevice::peerAddress(), KNetwork::KSocketDevice::peerAddress(), KNetwork::KSocksSocketDevice::writeBlock(), and KNetwork::KSocketDevice::writeBlock().

KSocketAddress& KNetwork::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

Referenced by KNetwork::KSocksSocketDevice::localAddress(), KNetwork::KSocketDevice::localAddress(), KNetwork::KSocksSocketDevice::peerAddress(), and KNetwork::KSocketDevice::peerAddress().

int KNetwork::KSocketAddress::family  )  const
 

Returns the family of this address.

Returns:
the family of this address, AF_UNSPEC if it's undefined

virtual KSocketAddress& KNetwork::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

Referenced by KNetwork::KSocketDevice::disconnect().

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 540 of file ksocketaddress.h.

bool KNetwork::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

virtual QString KNetwork::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
Bug:
use KResolver to resolve unknown families

Referenced by KNetwork::KHttpProxySocketDevice::connect().

virtual QString KNetwork::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
Bug:
use KResolver to resolve unknown families

Referenced by KNetwork::KHttpProxySocketDevice::connect().

virtual QString KNetwork::KSocketAddress::toString  )  const [virtual]
 

Returns this socket address as a string suitable for printing.

Family, node and service are part of this address.

Bug:
use KResolver to resolve unknown families

KInetSocketAddress& KNetwork::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.

KInetSocketAddress KNetwork::KSocketAddress::asInet  )  const
 

Returns an object is equal to this object's data, but they don't share it.

KUnixSocketAddress& KNetwork::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.

KUnixSocketAddress KNetwork::KSocketAddress::asUnix  )  const
 

Returns an object is equal to this object's data, but they don't share it.

int KNetwork::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)

int KNetwork::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


The documentation for this class was generated from the following file:
KDE Logo
This file is part of the documentation for kdecore Library Version 3.4.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Tue Apr 12 22:54:05 2005 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003