From: Guus Sliepen Date: Sun, 22 Jul 2018 11:16:13 +0000 (+0200) Subject: Add more error messages to test program, allow socket reuse. X-Git-Url: http://git.meshlink.io/?p=utcp;a=commitdiff_plain;h=d16abd3be87bdc3872c671a04dccdd5b286a208f Add more error messages to test program, allow socket reuse. --- diff --git a/test.c b/test.c index 81f45a5..96ebb0c 100644 --- a/test.c +++ b/test.c @@ -198,21 +198,28 @@ int main(int argc, char *argv[]) { getaddrinfo(server ? NULL : argv[1], server ? argv[1] : argv[2], &hint, &ai); if(!ai) { + debug("Could not lookup address: %s\n", strerror(errno)); return 1; } int s = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol); if(s == -1) { + debug("Could not create socket: %s\n", strerror(errno)); return 1; } + static const int one = 1; + setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &one, sizeof one); + if(server) { if(bind(s, ai->ai_addr, ai->ai_addrlen)) { + debug("Could not bind: %s\n", strerror(errno)); return 1; } } else { if(connect(s, ai->ai_addr, ai->ai_addrlen)) { + debug("Could not connect: %s\n", strerror(errno)); return 1; } @@ -224,6 +231,7 @@ int main(int argc, char *argv[]) { struct utcp *u = utcp_init(server ? do_accept : NULL, NULL, do_send, &s); if(!u) { + debug("Could not initialize UTCP\n"); return 1; }