From: R.E. Wolff Date: Fri, 20 Jun 2014 12:26:36 +0000 (+0200) Subject: fixed len confusion for IPV4 / IPV6 addresses X-Git-Tag: v0.86~13 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0cc9f56313eb9329f1af870b35d63d1d04c9258f;p=thirdparty%2Fmtr.git fixed len confusion for IPV4 / IPV6 addresses --- diff --git a/mtr.c b/mtr.c index 7225286..fed019c 100644 --- a/mtr.c +++ b/mtr.c @@ -144,8 +144,7 @@ append_to_names(const char* progname, const char* item) { fprintf(stderr, "%s: memory allocation failure\n", progname); exit(EXIT_FAILURE); } - // prepared for adding NULL name, but decided against that in the end. - name->name = item?strdup(item):item; + name->name = strdup(item); name->next = names; names = name; } diff --git a/net.c b/net.c index 7d51fd0..d43054b 100644 --- a/net.c +++ b/net.c @@ -330,23 +330,24 @@ void net_send_tcp(int index) addrcpy((void *) &local4->sin_addr, (void *) &ssa4->sin_addr, af); addrcpy((void *) &remote4->sin_addr, (void *) remoteaddress, af); remote4->sin_port = htons(remoteport); + len = sizeof (struct sockaddr_in); break; #ifdef ENABLE_IPV6 case AF_INET6: addrcpy((void *) &local6->sin6_addr, (void *) &ssa6->sin6_addr, af); addrcpy((void *) &remote6->sin6_addr, (void *) remoteaddress, af); remote6->sin6_port = htons(remoteport); + len = sizeof (struct sockaddr_in6); break; #endif } - if (bind(s, (struct sockaddr *) &local, sizeof (local))) { + if (bind(s, (struct sockaddr *) &local, len)) { display_clear(); perror("bind()"); exit(EXIT_FAILURE); } - len = sizeof (local); if (getsockname(s, (struct sockaddr *) &local, &len)) { display_clear(); perror("getsockname()"); @@ -410,7 +411,7 @@ void net_send_tcp(int index) gettimeofday(&sequence[port].time, NULL); sequence[port].socket = s; - connect(s, (struct sockaddr *) &remote, sizeof (remote)); + connect(s, (struct sockaddr *) &remote, len); } /* Attempt to find the host at a particular number of hops away */