patchlwIP - A Lightweight TCP/IP stack - Patches: patch #6900, IP Address Conversion Functions

 
 

You are not allowed to post comments on this tracker with your current authentication level.

patch #6900: IP Address Conversion Functions

Submitter:  Chris N. Strahm <cstrahm>
Submitted:  Tue 25 Aug 2009 02:30:46 AM UTC
   
 
Category:  None Priority:  5 - Normal
Status:  Done Privacy:  Public
Assigned to:  goldsimon Open/Closed:  Closed
Planned Release:  1.4.0

Tue 25 Aug 2009 02:53:57 PM UTC, comment #4: 

Added #define ip_ntoa(addr) to ip_addr.h

Simon Goldschmidt <goldsimon>
Group administrator
Tue 25 Aug 2009 10:47:56 AM UTC, comment #3: 


> I'm not sure I see the benefit here.


I do: it makes user code much clearer if the casts are not needed.

Simon Goldschmidt <goldsimon>
Group administrator
Tue 25 Aug 2009 10:47:04 AM UTC, comment #2: 

Since there is no inline statement in C (only in C++), I'd make it a define that passes on the address to inet_ntoa() (or a static function defined in ip_addr.h - much the same as inline).

Simon Goldschmidt <goldsimon>
Group administrator
Tue 25 Aug 2009 09:46:31 AM UTC, comment #1: 

I'm not sure I see the benefit here.  It seems to avoid some type casting that works at the expense of more code.  Perhaps it won't result in any more code actually being generated though.  Could we make this an inline function to give the compiler a hint?

Kieran Mansley <kieranm>
Group Member
Tue 25 Aug 2009 02:30:46 AM UTC, original submission:  

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.


Chris N. Strahm <cstrahm>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by kieranm (Posted a comment)
  • -email is unavailable- added by goldsimon (Updated the item)
  • -email is unavailable- added by cstrahm (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

     

    Follow 4 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2009-08-25 goldsimon Open/ClosedOpen Closed
        Assigned toNone goldsimon
        StatusNone Done
    2009-08-25 goldsimon Planned ReleaseNone 1.4.0

    Back to the top

    Powered by Savane 3.13-02a9.
    Corresponding source code