diff options
author | fadhil riyanto <me@fadev.org> | 2024-10-09 14:57:50 +0700 |
---|---|---|
committer | fadhil riyanto <me@fadev.org> | 2024-10-09 14:57:50 +0700 |
commit | 000e9fad94f0bc7b2b7877fb7d98fc7e31e97ff5 (patch) | |
tree | e9467b70576587c29a6c5d571b6d44f65e439c92 /test/ipver.c | |
parent | f92cb295c434f8fe986d4817b7dab03618ab3dd7 (diff) |
test detect ipversion
Signed-off-by: fadhil riyanto <me@fadev.org>
Diffstat (limited to 'test/ipver.c')
-rw-r--r-- | test/ipver.c | 20 |
1 files changed, 20 insertions, 0 deletions
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 <arpa/inet.h> +#include <stdio.h> + +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; +} |