X-Git-Url: https://www.tinc-vpn.org/git/browse?p=tinc;a=blobdiff_plain;f=test%2Fsplice.c;h=118d01185f7997753b5ded9d03f4404827d8131f;hp=31d071c90bfc8960c505e9c54a859f149d108d8a;hb=7ab400aebdc38e7ee5dafc0a2291bbbea25e3f7c;hpb=50a665643268deb1e50f118a3dcfc3e6c0f821c5 diff --git a/test/splice.c b/test/splice.c index 31d071c9..118d0118 100644 --- a/test/splice.c +++ b/test/splice.c @@ -70,15 +70,16 @@ int main(int argc, char *argv[]) { int sock[2]; char buf[1024]; - struct addrinfo *ai, hint; - memset(&hint, 0, sizeof(hint)); - - hint.ai_family = AF_UNSPEC; - hint.ai_socktype = SOCK_STREAM; - hint.ai_protocol = IPPROTO_TCP; - hint.ai_flags = 0; + const struct addrinfo hint = { + .ai_family = AF_UNSPEC, + .ai_socktype = SOCK_STREAM, + .ai_protocol = IPPROTO_TCP, + .ai_flags = 0, + }; for(int i = 0; i < 2; i++) { + struct addrinfo *ai; + if(getaddrinfo(argv[2 + 3 * i], argv[3 + 3 * i], &hint, &ai) || !ai) { fprintf(stderr, "getaddrinfo() failed: %s\n", sockstrerror(sockerrno)); return 1; @@ -88,14 +89,18 @@ int main(int argc, char *argv[]) { if(sock[i] == -1) { fprintf(stderr, "Could not create socket: %s\n", sockstrerror(sockerrno)); + freeaddrinfo(ai); return 1; } if(connect(sock[i], ai->ai_addr, ai->ai_addrlen)) { fprintf(stderr, "Could not connect to %s: %s\n", argv[i + 3 * i], sockstrerror(sockerrno)); + freeaddrinfo(ai); return 1; } + freeaddrinfo(ai); + fprintf(stderr, "Connected to %s\n", argv[1 + 3 * i]); /* Pretend to be the other one */