[Top][All Lists]

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

Re: [lwip-users] IP Address Display Functions

From: address@hidden
Subject: Re: [lwip-users] IP Address Display Functions
Date: Mon, 24 Aug 2009 18:18:56 +0200
User-agent: Thunderbird (Macintosh/20090812)

Nice idea. A bug or patch entry at savannah makes sure this doesn't get forgotten. Thanks.


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

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;
} // 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.


lwip-users mailing list

reply via email to

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