kdecore Library API Documentation

KInetSocketAddress Class Reference

An Inet (IPv4 or IPv6) socket address an Internet socket address. More...

#include <ksockaddr.h>

Inheritance diagram for KInetSocketAddress:

Inheritance graph
[legend]
Collaboration diagram for KInetSocketAddress:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 KInetSocketAddress ()
 Default constructor.

 KInetSocketAddress (const KInetSocketAddress &)
 Copy constructor.

 KInetSocketAddress (const sockaddr_in *sin, ksocklen_t len)
 Creates an IPv4 socket from raw sockaddr_in.

 KInetSocketAddress (const sockaddr_in6 *sin6, ksocklen_t len)
 Creates an IPv6 socket from raw sockaddr_in6.

 KInetSocketAddress (const in_addr &addr, unsigned short port)
 Creates a socket from information.

 KInetSocketAddress (const in6_addr &addr, unsigned short port)
 Creates a socket from information.

 KInetSocketAddress (const QString &addr, unsigned short port, int family=-1)
 Creates a socket from text representation.

virtual ~KInetSocketAddress ()
 Destructor.

bool setAddress (const KInetSocketAddress &ksa)
 Sets this socket to given socket.

bool setAddress (const sockaddr_in *sin, ksocklen_t len)
 Sets this socket to given raw socket.

bool setAddress (const sockaddr_in6 *sin6, ksocklen_t len)
 Sets this socket to given raw socket.

bool setAddress (const in_addr &addr, unsigned short port)
 Sets this socket to raw address and port.

bool setAddress (const in6_addr &addr, unsigned short port)
 Sets this socket to raw address and port.

bool setAddress (const QString &addr, unsigned short port, int family=-1)
 Sets this socket to text address and port.

bool setHost (const in_addr &addr)
 Sets this socket's host address to given raw address.

bool setHost (const in6_addr &addr)
 Sets this socket's host address to given raw address.

bool setHost (const QString &addr, int family=-1)
 Sets this socket's host address to given text representation.

bool setPort (unsigned short port)
 Sets this socket's port number to given port number.

bool setFamily (int family)
 Turns this into an IPv4 or IPv6 address.

bool setFlowinfo (Q_UINT32 flowinfo)
 Sets flowinfo information for this socket address if this is IPv6.

bool setScopeId (int scopeid)
 Sets the scope id for this socket if this is IPv6.

virtual QString pretty () const
 Returns a pretty representation of this address.

virtual QString nodeName () const
 Returns the text representation of the host address.

virtual QString serviceName () const
 Returns the text representation of the port number.

const sockaddr_in * addressV4 () const
 Returns the socket address.

const sockaddr_in6 * addressV6 () const
 Returns the socket address in IPv6.

in_addr hostV4 () const
 Returns the host address.

in6_addr hostV6 () const
 Returns the host address.

unsigned short port () const
 Returns the port number.

Q_UINT32 flowinfo () const
 Returns flowinfo for IPv6 socket.

int scopeId () const
 Returns the scope id for this IPv6 socket.

virtual ksocklen_t size () const
 Returns the socket length.

 operator const sockaddr_in * () const
 Returns the socket address.

 operator const sockaddr_in6 * () const
 Returns the socket address.

KInetSocketAddressoperator= (const KInetSocketAddress &other)
 Sets this object to be the same as the other.


Static Public Member Functions

bool areEqualInet (const KSocketAddress &s1, const KSocketAddress &s2, bool coreOnly)
 Compares two IPv4 addresses.

bool areEqualInet6 (const KSocketAddress &s1, const KSocketAddress &s2, bool coreOnly)
 Compares two IPv6 addresses.

QString addrToString (int family, const void *addr)
 Convert s the given raw address into text form.

bool stringToAddr (int family, const char *text, void *dest)
 Converts the address given in text form into raw form.


Protected Member Functions

virtual void virtual_hook (int id, void *data)

Friends

class KExtendedSocket

Detailed Description

An Inet (IPv4 or IPv6) socket address an Internet 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 <thiagom@mail.com>
Version:
Id
ksockaddr.h,v 1.15 2002/09/09 21:11:35 tjansen Exp

Definition at line 236 of file ksockaddr.h.


Constructor & Destructor Documentation

KInetSocketAddress::KInetSocketAddress  ) 
 

Default constructor.

Does nothing

Definition at line 271 of file ksockaddr.cpp.

KInetSocketAddress::KInetSocketAddress const KInetSocketAddress  ) 
 

Copy constructor.

Definition at line 276 of file ksockaddr.cpp.

References setAddress().

KInetSocketAddress::KInetSocketAddress const sockaddr_in *  sin,
ksocklen_t  len
 

Creates an IPv4 socket from raw sockaddr_in.

Parameters:
sin a sockaddr_in structure to copy from
len the socket address length

Definition at line 282 of file ksockaddr.cpp.

References setAddress().

KInetSocketAddress::KInetSocketAddress const sockaddr_in6 *  sin6,
ksocklen_t  len
 

Creates an IPv6 socket from raw sockaddr_in6.

Parameters:
sin6 a sockaddr_in6 structure to copy from
len the socket address length

Definition at line 288 of file ksockaddr.cpp.

References setAddress().

KInetSocketAddress::KInetSocketAddress const in_addr &  addr,
unsigned short  port
 

Creates a socket from information.

Parameters:
addr a binary address
port a port number

Definition at line 294 of file ksockaddr.cpp.

References port(), and setAddress().

KInetSocketAddress::KInetSocketAddress const in6_addr &  addr,
unsigned short  port
 

Creates a socket from information.

Parameters:
addr a binary address
port a port number

Definition at line 300 of file ksockaddr.cpp.

References port(), and setAddress().

KInetSocketAddress::KInetSocketAddress const QString addr,
unsigned short  port,
int  family = -1
 

Creates a socket from text representation.

Parameters:
addr a text representation of the address
port a port number
family the family for this address. Use -1 to guess the family type
See also:
setAddress

Definition at line 306 of file ksockaddr.cpp.

References KSocketAddress::family(), and setAddress().

KInetSocketAddress::~KInetSocketAddress  )  [virtual]
 

Destructor.

Definition at line 312 of file ksockaddr.cpp.


Member Function Documentation

bool KInetSocketAddress::setAddress const KInetSocketAddress ksa  ) 
 

Sets this socket to given socket.

Parameters:
ksa the other socket
Returns:
true if successful, false otherwise

Definition at line 319 of file ksockaddr.cpp.

References addressV4(), addressV6(), KSocketAddress::family(), and size().

Referenced by KInetSocketAddress(), and operator=().

bool KInetSocketAddress::setAddress const sockaddr_in *  sin,
ksocklen_t  len
 

Sets this socket to given raw socket.

Parameters:
sin the raw socket
len the socket address length
Returns:
true if successful, false otherwise

Definition at line 330 of file ksockaddr.cpp.

References setHost(), and setPort().

bool KInetSocketAddress::setAddress const sockaddr_in6 *  sin6,
ksocklen_t  len
 

Sets this socket to given raw socket.

Note: this function does not clear the scope ID and flow info values

Parameters:
sin6 the raw socket
len the socket address length
Returns:
true if successful, false otherwise

Definition at line 342 of file ksockaddr.cpp.

bool KInetSocketAddress::setAddress const in_addr &  addr,
unsigned short  port
 

Sets this socket to raw address and port.

Parameters:
addr the address
port the port number
Returns:
true if successful, false otherwise

Definition at line 370 of file ksockaddr.cpp.

References setHost(), and setPort().

bool KInetSocketAddress::setAddress const in6_addr &  addr,
unsigned short  port
 

Sets this socket to raw address and port.

Parameters:
addr the address
port the port number
Returns:
true if successful, false otherwise

Definition at line 375 of file ksockaddr.cpp.

References setHost(), and setPort().

bool KInetSocketAddress::setAddress const QString addr,
unsigned short  port,
int  family = -1
 

Sets this socket to text address and port.

You can use the 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.

This function returns false if the socket address was not valid.

Parameters:
addr the address
port the port number
family the address family, -1 for any
Returns:
true if successful, false otherwise

Definition at line 380 of file ksockaddr.cpp.

References setHost(), and setPort().

bool KInetSocketAddress::setHost const in_addr &  addr  ) 
 

Sets this socket's host address to given raw address.

Parameters:
addr the address
Returns:
true if successful, false otherwise

Definition at line 385 of file ksockaddr.cpp.

Referenced by setAddress().

bool KInetSocketAddress::setHost const in6_addr &  addr  ) 
 

Sets this socket's host address to given raw address.

Parameters:
addr the address
Returns:
true if successful, false otherwise

Definition at line 393 of file ksockaddr.cpp.

bool KInetSocketAddress::setHost const QString addr,
int  family = -1
 

Sets this socket's host address to given text representation.

Parameters:
addr the address
family the address family, -1 to guess the family
Returns:
true if successful, false otherwise

Definition at line 405 of file ksockaddr.cpp.

References QString::find(), and QString::latin1().

bool KInetSocketAddress::setPort unsigned short  port  ) 
 

Sets this socket's port number to given port number.

Parameters:
port the port number
Returns:
true if successful, false otherwise

Definition at line 454 of file ksockaddr.cpp.

Referenced by setAddress().

bool KInetSocketAddress::setFamily int  family  ) 
 

Turns this into an IPv4 or IPv6 address.

Parameters:
family the new address family
Returns:
false if this is v6 and information was lost. That doesn't mean the conversion was unsuccessful.

Definition at line 465 of file ksockaddr.cpp.

bool KInetSocketAddress::setFlowinfo Q_UINT32  flowinfo  ) 
 

Sets flowinfo information for this socket address if this is IPv6.

Parameters:
flowinfo flowinfo
Returns:
true if successful, false otherwise

Definition at line 488 of file ksockaddr.cpp.

bool KInetSocketAddress::setScopeId int  scopeid  ) 
 

Sets the scope id for this socket if this is IPv6.

Parameters:
scopeid the scope id
Returns:
true if successful, false otherwise

Definition at line 500 of file ksockaddr.cpp.

QString KInetSocketAddress::pretty  )  const [virtual]
 

Returns a pretty representation of this address.

Returns:
a pretty representation

Reimplemented from KSocketAddress.

Definition at line 559 of file ksockaddr.cpp.

References QString::arg(), nodeName(), and serviceName().

QString KInetSocketAddress::nodeName  )  const [virtual]
 

Returns the text representation of the host address.

Returns:
a text representation of the host address

Reimplemented from KSocketAddress.

Definition at line 574 of file ksockaddr.cpp.

References QString::fromLatin1().

Referenced by pretty().

QString KInetSocketAddress::serviceName  )  const [virtual]
 

Returns the text representation of the port number.

Parameters:
the name of the service (a number)

Reimplemented from KSocketAddress.

Definition at line 593 of file ksockaddr.cpp.

References QString::number(), and port().

Referenced by pretty().

const sockaddr_in * KInetSocketAddress::addressV4  )  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.

Returns:
the sockaddr_in struct, can be 0.

Definition at line 513 of file ksockaddr.cpp.

Referenced by operator const sockaddr_in *(), and setAddress().

const sockaddr_in6 * KInetSocketAddress::addressV6  )  const
 

Returns the socket address in IPv6.

Returns:
the sockaddr_in struct, can be 0 if IPv6 is unsupported.

Definition at line 532 of file ksockaddr.cpp.

Referenced by operator const sockaddr_in6 *(), and setAddress().

in_addr KInetSocketAddress::hostV4  )  const
 

Returns the host address.

Might be empty.

Returns:
the host address

Definition at line 541 of file ksockaddr.cpp.

in6_addr KInetSocketAddress::hostV6  )  const
 

Returns the host address.

WARNING: this function is not defined if there is no IPv6 support

Returns:
the host address

unsigned short KInetSocketAddress::port  )  const
 

Returns the port number.

Returns:
the port number

Definition at line 598 of file ksockaddr.cpp.

Referenced by KInetSocketAddress(), and serviceName().

Q_UINT32 KInetSocketAddress::flowinfo  )  const
 

Returns flowinfo for IPv6 socket.

Returns:
the flowinfo, 0 if unsupported

Definition at line 608 of file ksockaddr.cpp.

int KInetSocketAddress::scopeId  )  const
 

Returns the scope id for this IPv6 socket.

Returns:
the scope id

ksocklen_t KInetSocketAddress::size  )  const [virtual]
 

Returns the socket length.

Will be either sizeof(sockaddr_in) or sizeof(sockaddr_in6)

Returns:
the length of the socket

Reimplemented from KSocketAddress.

Definition at line 617 of file ksockaddr.cpp.

Referenced by setAddress().

bool KInetSocketAddress::areEqualInet const KSocketAddress s1,
const KSocketAddress s2,
bool  coreOnly
[static]
 

Compares two IPv4 addresses.

Parameters:
s1 the first address to compare
s2 the second address to compare
coreOnly true if only core parts should be compared (only the address)
Returns:
true if the given addresses are equal.
See also:
areEqualInet6()

KSocketAddress::isEqual()

KSocketAddress::isCoreEqual()

Definition at line 629 of file ksockaddr.cpp.

References KSocketAddress::address(), KSocketAddress::family(), and KSocketAddress::size().

Referenced by KSocketAddress::isCoreEqual(), and KSocketAddress::isEqual().

bool KInetSocketAddress::areEqualInet6 const KSocketAddress s1,
const KSocketAddress s2,
bool  coreOnly
[static]
 

Compares two IPv6 addresses.

Parameters:
s1 the first address to compare
s2 the second address to compare
coreOnly true if only core parts should be compared (only the address)
Returns:
true if the given addresses are equal.
See also:
areEqualInet()

KSocketAddress::isEqual()

KSocketAddress::isCoreEqual()

Definition at line 646 of file ksockaddr.cpp.

References KSocketAddress::address(), KSocketAddress::family(), and KSocketAddress::size().

Referenced by KSocketAddress::isCoreEqual(), and KSocketAddress::isEqual().

KInetSocketAddress::operator const sockaddr_in *  )  const [inline]
 

Returns the socket address.

This will be NULL if this is a non-convertible v6.

Returns:
the sockaddr_in structure, can be 0 if v6.
See also:
addressV4()

Definition at line 517 of file ksockaddr.h.

References addressV4().

KInetSocketAddress::operator const sockaddr_in6 *  )  const [inline]
 

Returns the socket address.

Returns:
the sockaddr_in structure, can be 0 if v6 is unsupported.
See also:
addressV6()

Definition at line 525 of file ksockaddr.h.

References addressV6().

KInetSocketAddress& KInetSocketAddress::operator= const KInetSocketAddress other  )  [inline]
 

Sets this object to be the same as the other.

Definition at line 531 of file ksockaddr.h.

References setAddress().

QString KInetSocketAddress::addrToString int  family,
const void *  addr
[static]
 

Convert s the given raw address into text form.

This function returns QString::null if the address cannot be converted.

Parameters:
family the family of the address
addr the address, in raw form
Returns:
the converted address, or QString::null if not possible.

Definition at line 716 of file ksockaddr.cpp.

References QString::fromLatin1().

bool KInetSocketAddress::stringToAddr int  family,
const char *  text,
void *  dest
[static]
 

Converts the address given in text form into raw form.

The size of the destination buffer dest is supposed to be large enough to hold the address of the given family.

Parameters:
family the family of the address
text the text representation of the address
dest the destination buffer of the address
Returns:
true if convertion was successful.

Definition at line 723 of file ksockaddr.cpp.


The documentation for this class was generated from the following files:
KDE Logo
This file is part of the documentation for kdelibs Version 3.1.5.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Wed Jan 28 12:49:26 2004 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001