[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lwip-users] struct ip_addr VS struct in_addr
From: |
Ceresoli Luca |
Subject: |
[lwip-users] struct ip_addr VS struct in_addr |
Date: |
Fri, 29 Aug 2008 10:15:09 +0200 |
I wrote a small library based on lwIP, raw interface.
Now there's the need to make it compilable also on top of a BSD standard stack
(Linux).
For this I am trying to remove lwIP-specific code where possible from the API
of my code. The most notable part of this work seems to be removing any usage
of struct ip_addr (lwIP-specific), perhaps in favor of struct in_addr
(portable).
This work is introducing the frequent need of translating from one struct to
the other somewhere between the API and the raw calls.
I'm ending up with code such as:
int my_api_call(const struct in_addr *dst_in_addr, ...)
{
struct ip_addr dst_ip_addr;
...
memcpy(&dst_ip_addr, &dst_in_addr->s_addr, sizeof(dst_ip_addr.addr)); //
<---- look here
ret = udp_sendto(pcb, p, &dst_ip_addr, dst_port);
...
}
I wonder if my approach is correct and if something better than memcpy() can be
done (my CPU does not support unaligned access).
A more fancy idea: rename the unique field of ip_addr from addr to s_addr, so
one struct can be simply be type-cast to the other. I bet there's some packing
issue about this (http://savannah.nongnu.org/bugs/?21664#comment4) but I'm
quite unaware of API implementation so I can't judge.
Regards,
Luca Ceresoli
- [lwip-users] struct ip_addr VS struct in_addr,
Ceresoli Luca <=