summaryrefslogtreecommitdiff
path: root/src/tc-netio.c
diff options
context:
space:
mode:
authorJörg Frings-Fürst <debian@jff-webhosting.net>2023-11-21 09:56:26 +0100
committerJörg Frings-Fürst <debian@jff-webhosting.net>2023-11-21 09:56:26 +0100
commit987942a206ef0f2342bf81d5de6432c6af42b7e7 (patch)
tree6befd1ab8680f2936d94ac84c94cf4f68f16c14e /src/tc-netio.c
parent163bc6d7fc268bdb1c7cc03699f69d0c5cc0b4cd (diff)
New upstream version 4.17upstream/4.17
Diffstat (limited to 'src/tc-netio.c')
-rw-r--r--src/tc-netio.c25
1 files changed, 19 insertions, 6 deletions
diff --git a/src/tc-netio.c b/src/tc-netio.c
index 5d3c22e..4510d0a 100644
--- a/src/tc-netio.c
+++ b/src/tc-netio.c
@@ -19,34 +19,47 @@
#endif
#include <libHX/init.h>
#include <libHX/io.h>
+#include "internal.h"
-int main(void)
+static int runner(void)
{
const char id[] = "SSH-2.0-OpenSSH_9.9";
- struct addrinfo *res;
+ struct addrinfo *res = nullptr;
int fd, ret;
if ((ret = HX_init()) <= 0) {
fprintf(stderr, "HX_init: %s\n", strerror(-ret));
- abort();
+ return EXIT_FAILURE;
}
fd = socket(AF_INET6, SOCK_STREAM, 0);
if (fd < 0) {
perror("socket");
- abort();
+ return EXIT_FAILURE;
}
if (getaddrinfo("::1", "22", NULL, &res) < 0) {
perror("getaddrinfo");
- abort();
+ close(fd);
+ return EXIT_FAILURE;
}
if (connect(fd, res->ai_addr, res->ai_addrlen) < 0) {
perror("connect");
- abort();
+ freeaddrinfo(res);
+ close(fd);
+ return EXIT_FAILURE;
}
if (HXio_fullwrite(fd, id, strlen(id)) < 0)
perror("write");
+ freeaddrinfo(res);
close(fd);
HX_exit();
return EXIT_SUCCESS;
}
+
+int main(void)
+{
+ int ret = runner();
+ if (ret != EXIT_SUCCESS)
+ fprintf(stderr, "FAILED\n");
+ return ret;
+}