summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--com32/hdt/hdt-dump-pxe.c19
-rw-r--r--com32/include/netinet/in.h4
-rw-r--r--com32/lib/inet.c14
3 files changed, 20 insertions, 17 deletions
diff --git a/com32/hdt/hdt-dump-pxe.c b/com32/hdt/hdt-dump-pxe.c
index 6f4f511a..4e25c943 100644
--- a/com32/hdt/hdt-dump-pxe.c
+++ b/com32/hdt/hdt-dump-pxe.c
@@ -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;
diff --git a/com32/include/netinet/in.h b/com32/include/netinet/in.h
index eae11623..d2af351f 100644
--- a/com32/include/netinet/in.h
+++ b/com32/include/netinet/in.h
@@ -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 */
diff --git a/com32/lib/inet.c b/com32/lib/inet.c
index 18891e88..133645ed 100644
--- a/com32/lib/inet.c
+++ b/com32/lib/inet.c
@@ -28,10 +28,12 @@
#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;
}