diff options
Diffstat (limited to 'src/tc-netio.c')
-rw-r--r-- | src/tc-netio.c | 25 |
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; +} |