lwip-users
[Top][All Lists]
Advanced

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

[lwip-users] Re: [lwip] Re: lwIP on DSPs


From: Adam Dunkels
Subject: [lwip-users] Re: [lwip] Re: lwIP on DSPs
Date: Wed, 08 Jan 2003 22:24:01 -0000

On Monday 03 December 2001 21.48, you wrote:
> The stuct definition you give below would work too.  However it
> changes the names of the members of the structs and no longer hides
> the details of the implementation.  The struct definition I gave
> would work for 8 bit chars as well as 16 bit ones.  (It's just that
> for 8 bit chars, the original is more efficient.)

I went ahead and implemented the struct stuff from my last mail in the IP 
module. The details of the implementation is hidden by the use of IPH_ macros 
for setting and reading header values - the actual struct members are never 
used directly. The new IP header struct looks like this (notice that 
underscores (_) have been prepended to the member names to indicate that they 
shouldn't be used directly):

struct ip_hdr {
  u16_t _v_hl_tos;
  u16_t _len;                /* total length */
  u16_t _id;                 /* identification */
  u16_t _offset;             /* fragment offset field */
#define IP_RF 0x8000        /* reserved fragment flag */
#define IP_DF 0x4000        /* dont fragment flag */
#define IP_MF 0x2000        /* more fragments flag */
#define IP_OFFMASK 0x1fff   /* mask for fragmenting bits */
  u16_t _ttl_proto;                 /* time to live */
  u16_t _chksum;             /* checksum */
  struct ip_addr src, dest;
};

And the macros for reading header fields look like this:

#define IPH_V(hdr)  (ntohs((hdr)->_v_hl_tos) >> 12)
#define IPH_HL(hdr) ((ntohs((hdr)->_v_hl_tos) >> 8) & 0x0f)
#define IPH_TOS(hdr) htons((ntohs((hdr)->_v_hl_tos) & 0xff))
#define IPH_LEN(hdr) ((hdr)->_len)

Setting header values are done with macros that look like the following:

#define IPH_LEN_SET(hdr, len) (hdr)->_len = (len)

I have changed the IP code so that is uses the macros instead of the 
structure members. The code is commited to the CVS and can be downloaded from 
the homepage. I haven't fixed the TCP and UDP headers, but it will be fixed 
in the next few days.

This scheme will work for systems with 32 bit chars as well, by the way. Of 
course, the protocol header structures have to be redefined with u32_t types, 
but the code will not have to be changed.

/adam
-- 
Adam Dunkels <address@hidden>
http://www.sics.se/~adam
[This message was sent through the lwip discussion list.]




reply via email to

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