lwip-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lwip-users] [lwip] Bug in ip_output_if with little_endian byte order.


From: Xavier Hanin
Subject: [lwip-users] [lwip] Bug in ip_output_if with little_endian byte order.
Date: Thu, 09 Jan 2003 00:41:46 -0000

In the function ip_output_if (src\core\ipv4\ip.c), the identification field is 
set with the following call :

IPH_ID_SET(iphdr, htons(++ip_id));

If you are using lwIP with BYTE_ORDER set as LITTLE_ENDIAN then

#define HTONS(n) (((((u16_t)(n) & 0xff)) << 8) | (((u16_t)(n) & 0xff00) >> 8))
#define htons HTONS

the call to htons(++ip_id) will increase the value of ip_id by 2, and not by 1 
as expected because
htons(++ip_id) is equivalent to (((((u16_t)((++ip_id) & 0xff)) << 8) | 
(((u16_t)((++ip_id) & 0xff00) >> 8))
It also returns a wrong value for htons, as the input value is modified during 
the calculation.

The issue is the same for htonl. If you were using an increment operator with 
htonl,
you would increase the value by 4, and also have a wrong result.

I checked the use of htons and htonl in lwIP, and I *think* that's the only 
place where such type of issue might happen.

We should call htons and htonl without modifying the value of the parameter 
within the call.

The proper way of setting up the identification field is:

++ip_id;
IPH_ID_SET(iphdr, htons(ip_id));

Xavier.




[This message was sent through the lwip discussion list.]




reply via email to

[Prev in Thread] Current Thread [Next in Thread]