Skip to content

Commit

Permalink
posix: net: implement inet_ntoa()
Browse files Browse the repository at this point in the history
Add an implementation of inet_ntoa().

Signed-off-by: Chris Friedt <[email protected]>
  • Loading branch information
cfriedt committed Mar 27, 2024
1 parent 3a78607 commit 7a397a0
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lib/posix/options/net.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/

#include <ctype.h>
#include <stdio.h>

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

return htonl(val);
}

char *inet_ntoa(struct in_addr in)
{
static char buf[INET_ADDRSTRLEN];
unsigned char *bytes = (unsigned char *)&in.s_addr;

snprintf(buf, sizeof(buf), "%d.%d.%d.%d", bytes[0], bytes[1], bytes[2], bytes[3]);

return buf;
}

0 comments on commit 7a397a0

Please sign in to comment.