diff options
author | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2023-02-10 15:27:06 +0100 |
---|---|---|
committer | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2023-02-10 15:27:06 +0100 |
commit | 7501bff8432444b7ae8e7f3d9289c0d61f3f0b64 (patch) | |
tree | bd53603f464c3747e897a8996158a0fef7b41bc3 /src/tc-socket.c | |
parent | 0f124df68d87c9073f76efeff1a901a69b1f3e13 (diff) | |
parent | 9e9336185f86bd97ff22f54e4d561c2cccccecf5 (diff) |
Merge branch 'release/debian/4.10-1'debian/4.10-1
Diffstat (limited to 'src/tc-socket.c')
-rw-r--r-- | src/tc-socket.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/tc-socket.c b/src/tc-socket.c new file mode 100644 index 0000000..9c73d24 --- /dev/null +++ b/src/tc-socket.c @@ -0,0 +1,31 @@ +// SPDX-License-Identifier: MIT +#include <errno.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <libHX/defs.h> +#include <libHX/socket.h> +#ifndef _WIN32 +# include <netdb.h> +#endif +#ifndef AI_V4MAPPED +# define AI_V4MAPPED 0 +#endif + +int main(void) +{ + static const char *addrs[] = { + "::1", "::2", "::ffff:127.0.0.1", "::", + "127.0.0.1", "127.0.0.2", "1.1.1.1", "255.255.255.255", + }; + for (size_t i = 0; i < ARRAY_SIZE(addrs); ++i) { + printf("%-16s\t", addrs[i]); + int lcl = HX_ipaddr_is_local(addrs[i], AI_V4MAPPED); + if (lcl < 0) { + printf("%s\n", strerror(-lcl)); + return EXIT_FAILURE; + } + printf("%d\n", lcl); + } + return EXIT_SUCCESS; +} |