blob: 9c73d24a86ea87049fb1407cada5c164421b0947 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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;
}
|