[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-core-devel
Subject: Re: Endian bug in KNetwork::KIpAddress
From: Nadeem Hasan <nhasan () nadmm ! com>
Date: 2006-07-22 12:36:26
Message-ID: 200607220836.30721.nhasan () nadmm ! com
[Download RAW message or body]
[Attachment #2 (multipart/mixed)]
On Saturday 22 July 2006 04:50, you wrote:
> Calling ntohl should be preferred in the isClass* functions, since it
> wouldn't change the address data, that other sections of code must be
> using already.
>
> I have no development environment here either. I cannot do any changes.
Ok...I have a near blind patch attached. It compiles, but I cannot verify that
it actually works (though it should). I would really like this fix to get
into 3.5.4 so If someone can give me a green light, I will commit.
Regards.
--
Nadeem Hasan (nhasan-at-nadmm.com)
GPG Fingerprint: 7141 0B1C 9CAF 624D 307F F8EF 6C0C 753E DD3A 0F53
["ksocketaddress.diff" (text/x-diff)]
Index: ksocketaddress.h
===================================================================
--- ksocketaddress.h (revision 565100)
+++ ksocketaddress.h (working copy)
@@ -30,6 +30,8 @@
#include <kdelibs_export.h>
+#include <arpa/inet.h>
+
struct sockaddr;
struct sockaddr_in;
struct sockaddr_in6;
@@ -225,7 +227,7 @@
* 32-bit integer. The result is only valid if @ref isIPv4Addr returns
* true. Alternatively, if the contained IPv6 address is a v4-mapped one
* and the @p convertMapped parameter is true, the result will also be
- * valid.
+ * valid. The address returned is in network byte order.
*
* Note: you should not treat IP addresses as integers. Instead,
* use types defined for that purpose, such as KIpAddress or the
@@ -265,7 +267,7 @@
* This function does not test for v4-mapped addresses.
*/
inline bool isClassA() const
- { return version() != 4 ? false : (IPv4Addr() & 0x80000000) == 0; }
+ { return version() != 4 ? false : (ntohl(IPv4Addr()) & 0x80000000) == 0; }
/**
* Returns true if this is an IPv4 class B address, i.e., one from
@@ -274,7 +276,7 @@
* This function does not test for v4-mapped addresses.
*/
inline bool isClassB() const
- { return version() != 4 ? false : (IPv4Addr() & 0xc0000000) == 0x80000000; }
+ { return version() != 4 ? false : (ntohl(IPv4Addr()) & 0xc0000000) == 0x80000000; }
/**
* Returns true if this is an IPv4 class C address, i.e., one from
@@ -283,7 +285,7 @@
* This function does not test for v4-mapped addresses.
*/
inline bool isClassC() const
- { return version() != 4 ? false : (IPv4Addr() & 0xe0000000) == 0xc0000000; }
+ { return version() != 4 ? false : (ntohl(IPv4Addr()) & 0xe0000000) == 0xc0000000; }
/**
* Returns true if this is an IPv4 class D (a.k.a. multicast) address.
@@ -292,7 +294,7 @@
* tests for IPv6 multicast addresses.
*/
inline bool isClassD() const
- { return version() != 4 ? false : (IPv4Addr() & 0xf0000000) == 0xe0000000; }
+ { return version() != 4 ? false : (ntohl(IPv4Addr()) & 0xf0000000) == 0xe0000000; }
/**
* Returns true if this is a multicast address, be it IPv4 or IPv6.
[Attachment #6 (application/pgp-signature)]
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic