aboutsummaryrefslogtreecommitdiff
path: root/lib/mlibc/tests/posix/inet_ntop.c
diff options
context:
space:
mode:
authorIan Moffett <ian@osmora.org>2024-03-07 17:28:00 -0500
committerIan Moffett <ian@osmora.org>2024-03-07 17:28:32 -0500
commitbd5969fc876a10b18613302db7087ef3c40f18e1 (patch)
tree7c2b8619afe902abf99570df2873fbdf40a4d1a1 /lib/mlibc/tests/posix/inet_ntop.c
parenta95b38b1b92b172e6cc4e8e56a88a30cc65907b0 (diff)
lib: Add mlibc
Signed-off-by: Ian Moffett <ian@osmora.org>
Diffstat (limited to 'lib/mlibc/tests/posix/inet_ntop.c')
-rw-r--r--lib/mlibc/tests/posix/inet_ntop.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/lib/mlibc/tests/posix/inet_ntop.c b/lib/mlibc/tests/posix/inet_ntop.c
new file mode 100644
index 0000000..feca26c
--- /dev/null
+++ b/lib/mlibc/tests/posix/inet_ntop.c
@@ -0,0 +1,30 @@
+#include <arpa/inet.h>
+#include <stdio.h>
+#include <assert.h>
+#include <string.h>
+
+int main() {
+ struct in_addr addr;
+ addr.s_addr = (1 << 24) |
+ (1 << 16) | (1 << 8) | 1;
+ char buf[INET_ADDRSTRLEN];
+ assert(inet_ntop(AF_INET, &addr, buf, INET_ADDRSTRLEN) != NULL);
+ assert(strncmp("1.1.1.1", buf, INET_ADDRSTRLEN) == 0);
+
+ struct in6_addr addr2 = { .s6_addr = {0x20, 0x1, 0xd, 0xb8, 0, 0, 0, 0, 0, 0x1, 0, 0, 0, 0, 0, 0x1} };
+ char buf2[INET6_ADDRSTRLEN];
+ assert(inet_ntop(AF_INET6, &addr2, buf2, INET6_ADDRSTRLEN) != NULL);
+ assert(strncmp("2001:db8::1:0:0:1", buf2, INET6_ADDRSTRLEN) == 0);
+
+ struct in6_addr addr3 = { .s6_addr = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1} };
+ char buf3[INET6_ADDRSTRLEN];
+ assert(inet_ntop(AF_INET6, &addr3, buf3, INET6_ADDRSTRLEN) != NULL);
+ assert(strncmp("::1", buf3, INET6_ADDRSTRLEN) == 0);
+
+ struct in6_addr addr4 = { .s6_addr = {0x20, 0x1, 0xd, 0xb8, 00, 00, 00, 0x1, 00, 0x1, 00, 0x1, 00, 0x1, 00, 0x1} };
+ char buf4[INET6_ADDRSTRLEN];
+ assert(inet_ntop(AF_INET6, &addr4, buf4, INET6_ADDRSTRLEN) != NULL);
+ assert(strncmp("2001:db8:0:1:1:1:1:1", buf4, INET6_ADDRSTRLEN) == 0);
+
+ return 0;
+}