[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lwip-devel] [patch #6900] IP Address Conversion Functions
From: |
Chris N. Strahm |
Subject: |
[lwip-devel] [patch #6900] IP Address Conversion Functions |
Date: |
Tue, 25 Aug 2009 02:30:50 +0000 |
User-agent: |
Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; Avant Browser; .NET CLR 1.1.4322; .NET CLR 2.0.50727) |
URL:
<http://savannah.nongnu.org/patch/?6900>
Summary: IP Address Conversion Functions
Project: lwIP - A Lightweight TCP/IP stack
Submitted by: cstrahm
Submitted on: Tue 25 Aug 2009 02:30:46 AM GMT
Category: None
Priority: 5 - Normal
Status: None
Privacy: Public
Assigned to: None
Originator Email:
Open/Closed: Open
Discussion Lock: Any
Planned Release: None
_______________________________________________________
Details:
Nice idea. A bug or patch entry at savannah makes sure this doesn't get
forgotten. Thanks.
Simon
Chris Strahm wrote:
> Perhaps I have missed a function that may already exist, if not I guess
this
> would be a request for a new feature/function.
>
> When displaying an IP address as a string this kind of call is often made:
>
> printf("Starting lwIP, StaticIP %s\n", inet_ntoa(*(struct
> in_addr*)&netadr.ip));
>
> The function inet_ntoa() takes a "struct in_addr" parameter.
>
> However the "netadr.ip" value here contains a "struct ip_addr". Since
they
> are not the same, all the above type casting is done to force it to work.
> This causes a warning everywhere from GCC about alignment etc.
>
> A better way to do this is to create a new function such as:
>
> // display ip_addr value as string
> char *ip_ntoa(struct ip_addr adr) {
> struct in_addr ip;
> ip.s_addr = adr.addr;
> return(inet_ntoa(ip));
> } // ip_ntoa
>
> So the above call with the new function is then:
>
> printf("Starting lwIP, StaticIP %s\n", ip_ntoa(netadr.ip));
>
> This eliminates all the type casting and warnings. Since lwIP has both
> "struct in_addr" and "struct ip_addr" used throughout, it seems like
having
> a str conversion routine for each type would make sense.
>
> I added ip_ntoa() to the ip_addr.c and ip_addr.h files which makes it easy
> to use anywhere.
>
> Chris.
_______________________________________________________
Reply to this item at:
<http://savannah.nongnu.org/patch/?6900>
_______________________________________________
Message sent via/by Savannah
http://savannah.nongnu.org/
- [lwip-devel] [patch #6900] IP Address Conversion Functions,
Chris N. Strahm <=