com32: inet_ntoa() takes struct in_addr
authorH. Peter Anvin <hpa@zytor.com>
Tue, 26 Apr 2011 00:15:40 +0000 (17:15 -0700)
committerH. Peter Anvin <hpa@zytor.com>
Tue, 26 Apr 2011 00:15:40 +0000 (17:15 -0700)
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 <hpa@zytor.com>
com32/hdt/hdt-dump-pxe.c
com32/include/netinet/in.h
com32/lib/inet.c

index 6f4f511..4e25c94 100644 (file)
@@ -32,6 +32,7 @@
 #include <netinet/in.h>
 
 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;
index eae1162..d2af351 100644 (file)
@@ -5,6 +5,7 @@
 
 #include <stdint.h>
 #include <klibc/compiler.h>
+#include <klibc/extern.h>
 
 #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 */
index 18891e8..133645e 100644 (file)
 
 #include <stdio.h>
 #include <netinet/in.h>
-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;
 }