From 0c8bfd91ab11a00b796f32982a30414c8bac7ec9 Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Mon, 25 Apr 2011 17:15:40 -0700 Subject: [PATCH] com32: inet_ntoa() takes struct in_addr The standard definition for inet_ntoa() is to take struct in_addr, and not doing that causes a conflict on the lwip branch. Signed-off-by: H. Peter Anvin --- com32/hdt/hdt-dump-pxe.c | 19 +++++++++---------- com32/include/netinet/in.h | 4 +++- com32/lib/inet.c | 14 ++++++++------ 3 files changed, 20 insertions(+), 17 deletions(-) diff --git a/com32/hdt/hdt-dump-pxe.c b/com32/hdt/hdt-dump-pxe.c index 6f4f511..4e25c94 100644 --- a/com32/hdt/hdt-dump-pxe.c +++ b/com32/hdt/hdt-dump-pxe.c @@ -32,6 +32,7 @@ #include void dump_pxe(struct s_hardware *hardware, ZZJSON_CONFIG *config, ZZJSON **item) { + struct in_addr in; CREATE_NEW_OBJECT; add_hb(is_pxe_valid); @@ -64,16 +65,14 @@ void dump_pxe(struct s_hardware *hardware, ZZJSON_CONFIG *config, ZZJSON **item) add_hi(pxe.nictype); add_hs(pxe.mac_addr); - char ip[16] = {0}; - snprintf(ip,sizeof(ip), "%d.%d.%d.%d", - hardware->pxe.ip_addr[0], - hardware->pxe.ip_addr[1], - hardware->pxe.ip_addr[2], - hardware->pxe.ip_addr[3]); - add_s("pxe.client_ip",inet_ntoa(hardware->pxe.dhcpdata.cip)); - add_s("pxe.next_server_ip",inet_ntoa(hardware->pxe.dhcpdata.sip)); - add_s("pxe.relay_agent_ip",inet_ntoa(hardware->pxe.dhcpdata.gip)); - add_s("pxe.ipaddr",ip); + in.s_addr = hardware->pxe.dhcpdata.cip; + add_s("pxe.client_ip", inet_ntoa(in)); + in.s_addr = hardware->pxe.dhcpdata.sip; + add_s("pxe.next_server_ip",inet_ntoa(in)); + in.s_addr = hardware->pxe.dhcpdata.gip; + add_s("pxe.relay_agent_ip",inet_ntoa(in)); + memcpy(&in, hardware->pxe.ip_addr, sizeof in); + add_s("pxe.ipaddr",inet_ntoa(in)); add_b("gpxe_detected",is_gpxe()); } FLUSH_OBJECT; diff --git a/com32/include/netinet/in.h b/com32/include/netinet/in.h index eae1162..d2af351 100644 --- a/com32/include/netinet/in.h +++ b/com32/include/netinet/in.h @@ -5,6 +5,7 @@ #include #include +#include #define __htons_macro(v) ((uint16_t) \ (((uint16_t)(v) << 8) | \ @@ -53,5 +54,6 @@ struct in_addr { in_addr_t s_addr; }; -char * inet_ntoa (in_addr_t addr); +__extern char *inet_ntoa(struct in_addr); + #endif /* _NETINET_IN_H */ diff --git a/com32/lib/inet.c b/com32/lib/inet.c index 18891e8..133645e 100644 --- a/com32/lib/inet.c +++ b/com32/lib/inet.c @@ -28,10 +28,12 @@ #include #include -char * inet_ntoa ( in_addr_t addr ) { - static char buf[16] = {0}; - uint8_t *bytes = ( uint8_t * ) &addr; - - sprintf ( buf, "%d.%d.%d.%d", bytes[0], bytes[1], bytes[2], bytes[3] ); - return buf; + +char *inet_ntoa(struct in_addr addr) +{ + static char buf[16]; + const uint8_t *bytes = (const uint8_t *)&addr.s_addr; + + sprintf(buf, "%u.%u.%u.%u", bytes[0], bytes[1], bytes[2], bytes[3]); + return buf; } -- 2.7.4