Better handling of inet_ntop() failures (which should not happen in practice, since...
authorThomas Pornin <pornin@bolet.org>
Sat, 12 Nov 2016 14:30:47 +0000 (15:30 +0100)
committerThomas Pornin <pornin@bolet.org>
Sat, 12 Nov 2016 14:30:47 +0000 (15:30 +0100)
tools/client.c
tools/server.c

index 692b60f..7acfebf 100644 (file)
@@ -70,7 +70,9 @@ host_connect(const char *host, const char *port, int verbose)
                        addr = NULL;
                }
                if (addr != NULL) {
-                       inet_ntop(p->ai_family, addr, tmp, sizeof tmp);
+                       if (!inet_ntop(p->ai_family, addr, tmp, sizeof tmp)) {
+                               strcpy(tmp, "<invalid>");
+                       }
                } else {
                        sprintf(tmp, "<unknown family: %d>",
                                (int)sa->sa_family);
index 0af6b42..983fbe6 100644 (file)
@@ -87,7 +87,9 @@ host_bind(const char *host, const char *port, int verbose)
                        sa_len = p->ai_addrlen;
                }
                if (addr != NULL) {
-                       inet_ntop(p->ai_family, addr, tmp, sizeof tmp);
+                       if (!inet_ntop(p->ai_family, addr, tmp, sizeof tmp)) {
+                               strcpy(tmp, "<invalid>");
+                       }
                } else {
                        sprintf(tmp, "<unknown family: %d>",
                                (int)sa->sa_family);