]> git.ipfire.org Git - thirdparty/mtr.git/commitdiff
fixed len confusion for IPV4 / IPV6 addresses
authorR.E. Wolff <R.E.Wolff@BitWizard.nl>
Fri, 20 Jun 2014 12:26:36 +0000 (14:26 +0200)
committerR.E. Wolff <R.E.Wolff@BitWizard.nl>
Fri, 20 Jun 2014 12:26:36 +0000 (14:26 +0200)
mtr.c
net.c

diff --git a/mtr.c b/mtr.c
index 722528631c50aeed15800476d5925c96b9e67693..fed019c97a8a48dea746de8e43bccc1169b69350 100644 (file)
--- 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 7d51fd029c06c8c21f658b3d8419fe5a3a188592..d43054bacdd152a7ccfcd5fb9e324455a470b449 100644 (file)
--- 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  */