summaryrefslogtreecommitdiff
path: root/src/arpa/inet/inet_ntop.c
diff options
context:
space:
mode:
authorJakob Kaivo <jkk@ung.org>2020-10-29 15:57:00 -0400
committerJakob Kaivo <jkk@ung.org>2020-10-29 15:57:00 -0400
commit972d2eee3a3518f18e0958e6f8a1b2ffafd6d39a (patch)
tree52fa9568b8c64e70ecbadc39ef63b35157731312 /src/arpa/inet/inet_ntop.c
parent097e3e2dc18091096fc846fcc15402accf906448 (diff)
outline stuff from arpa/inet.h
Diffstat (limited to 'src/arpa/inet/inet_ntop.c')
-rw-r--r--src/arpa/inet/inet_ntop.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/arpa/inet/inet_ntop.c b/src/arpa/inet/inet_ntop.c
new file mode 100644
index 00000000..0a89cedf
--- /dev/null
+++ b/src/arpa/inet/inet_ntop.c
@@ -0,0 +1,34 @@
+#include <arpa/inet.h>
+#include <errno.h>
+#include <stdio.h>
+#include <string.h>
+
+const char *inet_ntop(int af, const void *restrict src, char *restrict dst, socklen_t size)
+{
+ if (af == AF_INET) {
+ in_addr_t *a = src;
+ char s[INET_ADDRSTRLEN] = "";
+ if (snprintf(s, sizeof(s), "%hhu.%hhu.%hhu.%hhu",
+ (*src >> 24) & 0xff,
+ (*src >> 16) & 0xff,
+ (*src >> 8) & 0xff,
+ (*src) & 0xff) > size) {
+ errno = ENOSPC;
+ return NULL;
+ }
+ strcpy(dst, s);
+ return dst;
+ }
+
+ if (af != AF_INET6) {
+ errno = EAFNOSUPPORT;
+ return NULL;
+ }
+
+ /*
+ char s[INET6_ADDRSTRLEN] = "";
+ unsigned char *a = src;
+ */
+ /* do IPv6 conversion */
+ return dst;
+}