Skip to content

Commit 7a397a0

Browse files
committed
posix: net: implement inet_ntoa()
Add an implementation of inet_ntoa(). Signed-off-by: Chris Friedt <chrisfriedt@gmail.com>
1 parent 3a78607 commit 7a397a0

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

‎lib/posix/options/net.c‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66

77
#include <ctype.h>
8+
#include <stdio.h>
89

910
#include <zephyr/posix/arpa/inet.h>
1011
#include <zephyr/posix/netinet/in.h>
@@ -65,3 +66,13 @@ in_addr_t inet_addr(const char *cp)
6566

6667
return htonl(val);
6768
}
69+
70+
char *inet_ntoa(struct in_addr in)
71+
{
72+
static char buf[INET_ADDRSTRLEN];
73+
unsigned char *bytes = (unsigned char *)&in.s_addr;
74+
75+
snprintf(buf, sizeof(buf), "%d.%d.%d.%d", bytes[0], bytes[1], bytes[2], bytes[3]);
76+
77+
return buf;
78+
}

0 commit comments

Comments
 (0)