[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lwip-users] IP Address Display Functions
From: |
Chris Strahm |
Subject: |
[lwip-users] IP Address Display Functions |
Date: |
Mon, 24 Aug 2009 02:33:21 -0700 |
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.
- [lwip-users] Possible deadlock in LWIP 1.3.1 RC1, Eran Rundstein, 2009/08/23
- Re: [lwip-users] Possible deadlock in LWIP 1.3.1 RC1, Kieran Mansley, 2009/08/24
- [lwip-users] IP Address Display Functions,
Chris Strahm <=
- Re: [lwip-users] IP Address Display Functions, address@hidden, 2009/08/24
- RE: [lwip-users] IP Address Display Functions, Bill Auerbach, 2009/08/24
- Re: [lwip-users] IP Address Display Functions, Mandeep Sandhu, 2009/08/25
- Re: [lwip-users] IP Address Display Functions, Kieran Mansley, 2009/08/25
- RE: [lwip-users] IP Address Display Functions, Bill Auerbach, 2009/08/25
- RE: [lwip-users] IP Address Display Functions, Kieran Mansley, 2009/08/25
- RE: [lwip-users] IP Address Display Functions, Kieran Mansley, 2009/08/25
- RE: [lwip-users] IP Address Display Functions, Kieran Mansley, 2009/08/25
- [lwip-users] Re: IP Address Display Functions, Jakob Stoklund Olesen, 2009/08/25
- RE: [lwip-users] Re: IP Address Display Functions, Bill Auerbach, 2009/08/25