diff options
author | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2023-01-29 16:17:51 +0100 |
---|---|---|
committer | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2023-01-29 16:17:51 +0100 |
commit | bfef0924f58eab930bdd826ac0132786abc32220 (patch) | |
tree | c37bbc77063f3477236ce4cb7d765794f2018555 /src/tc-socket.c | |
parent | 8132c809273676b684f426ae8c0f8b1e6f40166e (diff) |
New upstream version 4.10upstream/4.10
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; +} |