From 000e9fad94f0bc7b2b7877fb7d98fc7e31e97ff5 Mon Sep 17 00:00:00 2001 From: fadhil riyanto Date: Wed, 9 Oct 2024 14:57:50 +0700 Subject: test detect ipversion Signed-off-by: fadhil riyanto --- test/ipver.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 test/ipver.c (limited to 'test/ipver.c') diff --git a/test/ipver.c b/test/ipver.c new file mode 100644 index 0000000..1007d8d --- /dev/null +++ b/test/ipver.c @@ -0,0 +1,20 @@ +#include +#include + +static int ip_version(const char *src) { + char buf[INET6_ADDRSTRLEN]; + if (inet_pton(AF_INET, src, buf)) { + return 4; + } else if (inet_pton(AF_INET6, src, buf)) { + return 6; + } + return -1; +} + +int main(int argc, char *argv[]) { + for (int i = 1; i < argc; ++i) { + printf("%s\t%d\n", argv[i], ip_version(argv[i])); + } + + return 0; +} -- cgit v1.2.3