25 #ifndef KSOCKETADDRESS_H
26 #define KSOCKETADDRESS_H
29 #include <tqcstring.h>
31 #include <kdelibs_export.h>
101 { setAddress(addr); }
110 { setAddress(addr, version); }
123 { setAddress(&ip4addr, 4); }
149 {
return compare(other,
true); }
164 bool compare(
const KIpAddress& other,
bool checkMapped =
true)
const;
172 {
return m_version; }
178 {
return version() == 4; }
184 {
return version() == 6; }
192 bool setAddress(
const TQString& address);
200 bool setAddress(
const char* address);
210 bool setAddress(
const void* raw,
int version = 4);
215 TQString toString()
const;
220 inline const void *
addr()
const
235 inline TQ_UINT32
IPv4Addr(
bool convertMapped =
true)
const
237 return (convertMapped && isV4Mapped()) ? m_data[3] : m_data[0];
248 TQ_UINT32 hostIPv4Addr(
bool convertMapped =
true)
const;
257 {
return version() == 0 ? true : (*
this == anyhostV4 || *
this == anyhostV6); }
263 {
return version() == 0 ? false : (*
this == localhostV4 || *
this == localhostV6); }
269 {
return isLocalhost(); }
278 {
return version() != 4 ? false : (hostIPv4Addr() & 0x80000000) == 0; }
287 {
return version() != 4 ? false : (hostIPv4Addr() & 0xc0000000) == 0x80000000; }
296 {
return version() != 4 ? false : (hostIPv4Addr() & 0xe0000000) == 0xc0000000; }
305 {
return version() != 4 ? false : (hostIPv4Addr() & 0xf0000000) == 0xe0000000; }
312 if (version() == 4)
return isClassD();
313 if (version() == 6)
return ((TQ_UINT8*)addr())[0] == 0xff;
322 if (version() != 6)
return false;
323 TQ_UINT8* addr = (TQ_UINT8*)this->addr();
324 return (addr[0] & 0xff) == 0xfe &&
325 (addr[1] & 0xc0) == 0x80;
333 if (version() != 6)
return false;
334 TQ_UINT8* addr = (TQ_UINT8*)this->addr();
335 return (addr[0] & 0xff) == 0xfe &&
336 (addr[1] & 0xc0) == 0xc0;
343 {
return version() != 6 ? false : !(isMulticast() || isLinkLocal() || isSiteLocal()); }
350 if (version() != 6)
return false;
351 TQ_UINT32* addr = (TQ_UINT32*)this->addr();
352 return addr[0] == 0 && addr[1] == 0 &&
353 ((TQ_UINT16*)&addr[2])[0] == 0 &&
354 ((TQ_UINT16*)&addr[2])[1] == 0xffff;
362 if (version() != 6 || isLocalhost())
return false;
363 TQ_UINT32* addr = (TQ_UINT32*)this->addr();
364 return addr[0] == 0 && addr[1] == 0 && addr[2] == 0 && addr[3] != 0;
371 {
return version() == 6 && isMulticast() && (((TQ_UINT32*)addr())[0] & 0xf) == 0x1; }
377 {
return version() == 6 && isMulticast() && (((TQ_UINT32*)addr())[0] & 0xf) == 0x2; }
383 {
return version() == 6 && isMulticast() && (((TQ_UINT32*)addr())[0] & 0xf) == 0x5; }
389 {
return version() == 6 && isMulticast() && (((TQ_UINT32*)addr())[0] & 0xf) == 0x8; }
395 {
return version() == 6 && isMulticast() && (((TQ_UINT32*)addr())[0] & 0xf) == 0xe; }
415 class KSocketAddressData;
472 const sockaddr* address()
const;
499 inline operator const sockaddr*()
const
500 {
return address(); }
505 TQ_UINT16 length()
const;
551 {
return ianaFamily(family()); }
572 virtual TQString nodeName()
const;
583 virtual TQString serviceName()
const;
591 virtual TQString toString()
const;
618 KSocketAddressData *d;
632 static int ianaFamily(
int af);
638 static int fromIanaFamily(
int iana);
715 inline operator const sockaddr_in*()
const
716 {
return (
const sockaddr_in*)
address(); }
721 inline operator const sockaddr_in6*()
const
722 {
return (
const sockaddr_in6*)
address(); }
729 int ipVersion()
const;
753 TQ_UINT16 port()
const;
790 TQ_UINT32 flowinfo()
const;
888 inline operator const sockaddr_un*()
const
889 {
return (
const sockaddr_un*)
address(); }
895 TQString pathname()
const;
An Inet (IPv4 or IPv6) socket address.
an Internet socket address
const void * addr() const
Returns a pointer to binary raw data representing the address.
bool isSiteLocal() const
Returns true if this is an IPv6 site-local address.
KIpAddress(TQ_UINT32 ip4addr)
This is a convenience constructor.
bool isMulticastOrgLocal() const
Returns true if this is an IPv6 organisational-local multicast address.
int version() const
Retrieves the IP version in this object.
KIpAddress(const void *addr, int version=4)
Creates an object from the given raw data and IP version.
KIpAddress(const KIpAddress &other)
Copy constructor.
bool isClassC() const
Returns true if this is an IPv4 class C address, i.e., one from 192.0.0.0 to 223.255....
bool isIPv6Addr() const
Returns true if this is an IPv6 address.
bool isClassB() const
Returns true if this is an IPv4 class B address, i.e., one from 128.0.0.0 to 191.255....
KIpAddress()
Default constructor.
bool isLocalhost() const
Returns true if this is either the IPv4 or the IPv6 localhost address.
TQ_UINT32 IPv4Addr(bool convertMapped=true) const
This is a convenience function.
static const KIpAddress localhostV4
localhost in IPv4 (127.0.0.1)
bool isLinkLocal() const
Returns true if this is an IPv6 link-local address.
KIpAddress(const TQString &addr)
Creates an object from the given string representation.
bool isMulticastSiteLocal() const
Returns true if this is an IPv6 site-local multicast address.
bool isMulticast() const
Returns true if this is a multicast address, be it IPv4 or IPv6.
bool isMulticastNodeLocal() const
Returns true if this is an IPv6 node-local multicast address.
bool isUnspecified() const
Returns true if this is the IPv4 or IPv6 unspecified address.
bool isMulticastLinkLocal() const
Returns true if this is an IPv6 link-local multicast address.
bool isV4Compat() const
Returns true if this is a v4-compat IPv6 address.
bool isClassD() const
Returns true if this is an IPv4 class D (a.k.a.
bool isGlobal() const
Returns true if this is a global IPv6 address.
static const KIpAddress anyhostV6
the any host or undefined address in IPv6 (::)
bool isLoopback() const
This is an alias for isLocalhost.
static const KIpAddress localhostV6
localhost in IPv6 (::1)
static const KIpAddress anyhostV4
the any host or undefined address in IPv4 (0.0.0.0)
bool isMulticastGlobal() const
Returns true if this is an IPv6 global multicast address.
bool isV4Mapped() const
Returns true if this is a v4-mapped IPv6 address.
bool isClassA() const
Returns true if this is an IPv4 class A address, i.e., from 0.0.0.0 to 127.255.255....
bool isIPv4Addr() const
Returns true if this is an IPv4 address.
KIpAddress(const char *addr)
Creates an object from the given string representation.
A generic socket address.
int ianaFamily() const
Returns the IANA family number of this address.
A Unix (local) socket address.
const sockaddr * address() const
Returns a sockaddr structure, for passing down to library functions.
A namespace to store all networking-related (socket) classes.