summaryrefslogtreecommitdiff
path: root/src/tc-socket.c
diff options
context:
space:
mode:
authorJörg Frings-Fürst <debian@jff-webhosting.net>2023-03-11 18:24:14 +0100
committerJörg Frings-Fürst <debian@jff-webhosting.net>2023-03-11 18:24:14 +0100
commit3cd3fca072b0f0958d260a5b147bb09df165bd0f (patch)
treec9a7de96002ffaa5df663540398f81d7ba69241e /src/tc-socket.c
parent2feb2da15867887be02beaadf9a92d2e8a997b85 (diff)
parent980784c1917f19bfd2e9b11faca76d14e8589daa (diff)
Update upstream source from tag 'upstream/4.12'
Update to upstream version '4.12' with Debian dir 2e81fc9e49b613c77c6c552b837c5a8ee952b59b
Diffstat (limited to 'src/tc-socket.c')
-rw-r--r--src/tc-socket.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/tc-socket.c b/src/tc-socket.c
index 9c73d24..9904ba8 100644
--- a/src/tc-socket.c
+++ b/src/tc-socket.c
@@ -7,6 +7,7 @@
#include <libHX/socket.h>
#ifndef _WIN32
# include <netdb.h>
+# include <unistd.h>
#endif
#ifndef AI_V4MAPPED
# define AI_V4MAPPED 0
@@ -19,6 +20,15 @@ int main(void)
"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) {
+ char host[32] = {};
+ uint16_t port = 0;
+
+ int ret = HX_addrport_split(addrs[i], host, sizeof(host), &port);
+ if (ret >= 0)
+ printf("Parse \"%s\" -> [%s]:%hu\n", addrs[i], host, port);
+ else
+ return EXIT_FAILURE;
+
printf("%-16s\t", addrs[i]);
int lcl = HX_ipaddr_is_local(addrs[i], AI_V4MAPPED);
if (lcl < 0) {
@@ -27,5 +37,39 @@ int main(void)
}
printf("%d\n", lcl);
}
+
+ char host[32] = {};
+ uint16_t port = 0;
+ int ret = HX_addrport_split("[fe80::1]:80", host, sizeof(host), &port);
+ if (ret < 0 || port != 80)
+ return EXIT_FAILURE;
+ port = 443;
+ ret = HX_addrport_split("::80", host, sizeof(host), &port);
+ if (ret < 0 || port != 443)
+ return EXIT_FAILURE;
+ ret = HX_addrport_split(":::80", host, sizeof(host), &port);
+ if (ret < 0 || port != 443)
+ return EXIT_FAILURE;
+ ret = HX_addrport_split("0.0.0.0", host, sizeof(host), &port);
+ if (ret < 0 || port != 443)
+ return EXIT_FAILURE;
+ ret = HX_addrport_split("0.0.0.0:80", host, sizeof(host), &port);
+ if (ret < 0 || port != 80)
+ return EXIT_FAILURE;
+
+ int fd = HX_inet_connect("::1", 80, 0);
+ if (fd >= 0) {
+ printf("Connected to [::1]:80\n");
+ close(fd);
+ } else {
+ fprintf(stderr, "HX_inet_connect [::1]:80: %s\n", strerror(-fd));
+ }
+ fd = HX_inet_connect("::", 80, 0);
+ if (fd >= 0) {
+ printf("Connected to [::]:80\n");
+ close(fd);
+ } else {
+ fprintf(stderr, "HX_inet_connect [::]:80: %s\n", strerror(-fd));
+ }
return EXIT_SUCCESS;
}