26 #ifndef KSOCKETADDRESS_H
27 #define KSOCKETADDRESS_H
30 #include <QtCore/QByteArray>
41 class KInetSocketAddress;
42 class KUnixSocketAddress;
101 { setAddress(addr); }
123 { setAddress(&ip4addr, 4); }
149 {
return compare(other,
true); }
164 bool compare(
const KIpAddress& other,
bool checkMapped =
true)
const;
172 {
return m_version; }
177 inline bool isIPv4Addr()
const
183 inline bool isIPv6Addr()
const
192 bool setAddress(
const QString& address);
200 bool setAddress(
const char* address);
210 bool setAddress(
const void* raw,
int version = 4);
220 inline const void *addr()
const
236 inline quint32 IPv4Addr(
bool convertMapped =
true)
const
238 return (convertMapped && isV4Mapped()) ? m_data[3] : m_data[0];
246 inline bool isUnspecified()
const
247 {
return version() == 0 ?
true : (*
this == anyhostV4 || *
this == anyhostV6); }
252 inline bool isLocalhost()
const
253 {
return version() == 0 ?
false : (*
this == localhostV4 || *
this == localhostV6); }
258 inline bool isLoopback()
const
259 {
return isLocalhost(); }
267 inline bool isClassA()
const
268 {
return version() != 4 ?
false : (IPv4Addr() & 0x80000000) == 0; }
276 inline bool isClassB()
const
277 {
return version() != 4 ?
false : (IPv4Addr() & 0xc0000000) == 0x80000000; }
285 inline bool isClassC()
const
286 {
return version() != 4 ?
false : (IPv4Addr() & 0xe0000000) == 0xc0000000; }
294 inline bool isClassD()
const
295 {
return version() != 4 ?
false : (IPv4Addr() & 0xf0000000) == 0xe0000000; }
300 inline bool isMulticast()
const
302 if (
version() == 4)
return isClassD();
303 if (
version() == 6)
return ((quint8*)addr())[0] == 0xff;
310 inline bool isLinkLocal()
const
312 if (
version() != 6)
return false;
313 quint8* addr = (quint8*)this->addr();
314 return (addr[0] & 0xff) == 0xfe &&
315 (addr[1] & 0xc0) == 0x80;
321 inline bool isSiteLocal()
const
323 if (
version() != 6)
return false;
324 quint8* addr = (quint8*)this->addr();
325 return (addr[0] & 0xff) == 0xfe &&
326 (addr[1] & 0xc0) == 0xc0;
332 inline bool isGlobal()
const
333 {
return version() != 6 ?
false : !(isMulticast() || isLinkLocal() || isSiteLocal()); }
338 inline bool isV4Mapped()
const
340 if (
version() != 6)
return false;
342 return addr[0] == 0 && addr[1] == 0 &&
343 ((quint16*)&addr[2])[0] == 0 &&
344 ((quint16*)&addr[2])[1] == 0xffff;
350 inline bool isV4Compat()
const
352 if (
version() != 6 || isLocalhost())
return false;
354 return addr[0] == 0 && addr[1] == 0 && addr[2] == 0 && addr[3] != 0;
360 inline bool isMulticastNodeLocal()
const
361 {
return version() == 6 && isMulticast() && (((
quint32*)addr())[0] & 0xf) == 0x1; }
366 inline bool isMulticastLinkLocal()
const
367 {
return version() == 6 && isMulticast() && (((
quint32*)addr())[0] & 0xf) == 0x2; }
372 inline bool isMulticastSiteLocal()
const
373 {
return version() == 6 && isMulticast() && (((
quint32*)addr())[0] & 0xf) == 0x5; }
378 inline bool isMulticastOrgLocal()
const
379 {
return version() == 6 && isMulticast() && (((
quint32*)addr())[0] & 0xf) == 0x8; }
384 inline bool isMulticastGlobal()
const
385 {
return version() == 6 && isMulticast() && (((
quint32*)addr())[0] & 0xf) == 0xe; }
405 class KSocketAddressData;
463 const sockaddr* address()
const;
490 inline operator const sockaddr*()
const
491 {
return address(); }
496 quint16 length()
const;
541 inline int ianaFamily()
const
563 virtual QString nodeName()
const;
574 virtual QString serviceName()
const;
582 virtual QString toString()
const;
609 KSocketAddressData *
d;
623 static int ianaFamily(
int af);
629 static int fromIanaFamily(
int iana);
707 inline operator const sockaddr_in*()
const
708 {
return (
const sockaddr_in*)address(); }
721 int ipVersion()
const;
745 quint16 port()
const;
881 inline operator const sockaddr_un*()
const
882 {
return (
const sockaddr_un*)address(); }