lwip-devel
[Top][All Lists]
Advanced

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

RE: [lwip-devel] Why use a struct for ip_addr?


From: Zschocke, Florian
Subject: RE: [lwip-devel] Why use a struct for ip_addr?
Date: Tue, 13 Apr 2004 11:03:51 +0200

Chris Jones wrote on Thursday, April 08, 2004 11:27 PM:

> Can anyone give me a reason why a structure with a single 32
> bit value is used to handle IP addresses.

This is in compliance with Posix.1g. This is the standard for network
programming with BSD sockets. The lwIP code is based on the original BSD
networking code and uses the data types necessary for other networking
programs to run with it. 

The reason the in_addr is a structure is historical. Quoting W.R. Stevens:
"Earlier releases (4.2BSD) defined the in_addr structure as a union of
various structures, to allow access to each of the 4 bytes and to both of
the 16-bit values contained within the 32-bit IPv4 address. This was used
with class A, B and C addresses to fetch the appropriate bytes of the
address. But with the advent of subnetting and then the disappearance of the
various address classes with classless addressing, the need for the union
disappeared. Most systems today have done away with the union and just
define in_addr as a structure with a single unsigned long member."

Note that the addr member should actually rather be of type in_addr_t which
is required to be an unsigned integer of at least 32 bits. The lwIP code
disregards this detail and directly uses u32_t instead.

Florian




reply via email to

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