[netperf-dev] netperf2 commit notice r338 - in trunk: . src

raj at netperf.org raj at netperf.org
Thu Oct 8 14:17:09 PDT 2009


Author: raj
Date: 2009-10-08 14:17:08 -0700 (Thu, 08 Oct 2009)
New Revision: 338

Modified:
   trunk/AUTHORS
   trunk/Release_Notes
   trunk/src/netlib.c
   trunk/src/netlib.h
   trunk/src/netsh.c
Log:
fixes for ipv6 from brian haley

Modified: trunk/AUTHORS
===================================================================
--- trunk/AUTHORS	2009-10-06 17:57:30 UTC (rev 337)
+++ trunk/AUTHORS	2009-10-08 21:17:08 UTC (rev 338)
@@ -243,3 +243,6 @@
 
 Pal Baranyai
 Typo in nettest_dlpi.c
+
+Brian Haley
+Changes to allow something like netperf -H ::1 to work
\ No newline at end of file

Modified: trunk/Release_Notes
===================================================================
--- trunk/Release_Notes	2009-10-06 17:57:30 UTC (rev 337)
+++ trunk/Release_Notes	2009-10-08 21:17:08 UTC (rev 338)
@@ -2,6 +2,11 @@
 
 *) Missing fprintf format statements provided by Bruno Cornec
 
+*) Numerous cleanups from Jose Pedro Oliveira
+
+*) Fixes to allow netperf -H ::1 to work without having to add -6 or
+    an AF_INET6 -L option
+
 These are the Release Notes for Revision 2.4.5 of netperf:
 
 Things changed in this release:

Modified: trunk/src/netlib.c
===================================================================
--- trunk/src/netlib.c	2009-10-06 17:57:30 UTC (rev 337)
+++ trunk/src/netlib.c	2009-10-08 21:17:08 UTC (rev 338)
@@ -2902,6 +2902,64 @@
   fflush(dumploc);
 }
 
+struct addrinfo *
+resolve_host(char *hostname,
+	     char *port,
+	     int   family)
+{
+  struct addrinfo   hints;
+  struct addrinfo  *ai;
+  int count;
+  int error;
+
+  if (debug) {
+    fprintf(where,
+            "resolve_host called with host '%s' port '%s' family %s\n",
+            hostname,
+            port,
+            inet_ftos(family));
+    fflush(where);
+  }
+
+  memset(&hints, 0, sizeof(hints));
+  hints.ai_family = family;
+  hints.ai_socktype = SOCK_STREAM;
+  hints.ai_protocol = IPPROTO_TCP;
+  hints.ai_flags = AI_CANONNAME;
+  count = 0;
+  do {
+    error = getaddrinfo((char *)hostname,
+                        (char *)port,
+                        &hints,
+                        &ai);
+    count += 1;
+    if (error == EAI_AGAIN) {
+      if (debug) {
+        fprintf(where,"Sleeping on getaddrinfo EAI_AGAIN\n");
+        fflush(where);
+      }
+      sleep(1);
+    }
+  } while ((error == EAI_AGAIN) && (count <= 5));
+
+  if (error) {
+    printf("establish control: could not resolve host '%s' port '%s' af %s",
+           hostname,
+           port,
+           inet_ftos(family));
+    printf("\n\tgetaddrinfo returned %d %s\n",
+           error,
+           gai_strerror(error));
+    return(NULL);
+  }
+
+  if (debug) {
+    dump_addrinfo(where, ai, hostname, port, family);
+  }
+
+  return (ai);
+}
+
 /*
   establish_control()
 
@@ -2934,15 +2992,20 @@
 {
   int not_connected;
   SOCKET control_sock;
-  int count;
-  int error;
 
-  struct addrinfo   hints;
   struct addrinfo  *local_res;
   struct addrinfo  *remote_res;
   struct addrinfo  *local_res_temp;
   struct addrinfo  *remote_res_temp;
 
+  remote_res = resolve_host(hostname, port, remfam);
+  if (!remote_res)
+    return(INVALID_SOCKET);
+
+  local_res = resolve_host(localhost, localport, locfam);
+  if (!local_res)
+    return(INVALID_SOCKET);
+
   if (debug) {
     fprintf(where,
             "establish_control called with host '%s' port '%s' remfam %s\n",
@@ -2957,84 +3020,6 @@
     fflush(where);
   }
 
-  /* first, we do the remote */
-  memset(&hints, 0, sizeof(hints));
-  hints.ai_family = remfam;
-  hints.ai_socktype = SOCK_STREAM;
-  hints.ai_protocol = IPPROTO_TCP;
-  hints.ai_flags = 0|AI_CANONNAME;
-  count = 0;
-  do {
-    error = getaddrinfo((char *)hostname,
-                        (char *)port,
-                        &hints,
-                        &remote_res);
-    count += 1;
-    if (error == EAI_AGAIN) {
-      if (debug) {
-        fprintf(where,"Sleeping on getaddrinfo EAI_AGAIN\n");
-        fflush(where);
-      }
-      sleep(1);
-    }
-  } while ((error == EAI_AGAIN) && (count <= 5));
-
-  if (error) {
-    printf("establish control: could not resolve remote '%s' port '%s' af %s",
-           hostname,
-           port,
-           inet_ftos(remfam));
-    printf("\n\tgetaddrinfo returned %d %s\n",
-           error,
-           gai_strerror(error));
-    return(INVALID_SOCKET);
-  }
-
-  if (debug) {
-    dump_addrinfo(where, remote_res, hostname, port, remfam);
-  }
-
-  /* now we do the local */
-  memset(&hints, 0, sizeof(hints));
-  hints.ai_family = locfam;
-  hints.ai_socktype = SOCK_STREAM;
-  hints.ai_protocol = IPPROTO_TCP;
-  hints.ai_flags = AI_PASSIVE|AI_CANONNAME;
-  count = 0;
-  do {
-    count += 1;
-    error = getaddrinfo((char *)localhost,
-                           (char *)localport,
-                           &hints,
-                           &local_res);
-    if (error == EAI_AGAIN) {
-      if (debug) {
-        fprintf(where,
-                "Sleeping on getaddrinfo(%s,%s) EAI_AGAIN count %d \n",
-                localhost,
-                localport,
-                count);
-        fflush(where);
-      }
-      sleep(1);
-    }
-  } while ((error == EAI_AGAIN) && (count <= 5));
-
-  if (error) {
-    printf("establish control: could not resolve local '%s' port '%s' af %s",
-           localhost,
-           localport,
-           inet_ftos(locfam));
-    printf("\n\tgetaddrinfo returned %d %s\n",
-           error,
-           gai_strerror(error));
-    return(INVALID_SOCKET);
-  }
-
-  if (debug) {
-    dump_addrinfo(where, local_res, localhost, localport, locfam);
-  }
-
   not_connected = 1;
   local_res_temp = local_res;
   remote_res_temp = remote_res;

Modified: trunk/src/netlib.h
===================================================================
--- trunk/src/netlib.h	2009-10-06 17:57:30 UTC (rev 337)
+++ trunk/src/netlib.h	2009-10-08 21:17:08 UTC (rev 338)
@@ -482,6 +482,9 @@
 extern  void    netlib_init();
 extern  int     netlib_get_page_size();
 extern  void    install_signal_catchers();
+extern  struct addrinfo *resolve_host(char hostname[], 
+				      char port[], 
+				      int af);
 extern  void    establish_control(char hostname[], 
 				  char port[], 
 				  int af,

Modified: trunk/src/netsh.c
===================================================================
--- trunk/src/netsh.c	2009-10-06 17:57:30 UTC (rev 337)
+++ trunk/src/netsh.c	2009-10-08 21:17:08 UTC (rev 338)
@@ -967,6 +967,29 @@
 	     address_family);
       exit(-1);
     }
+  } else {
+    /* resolve the hostname and pull the address family from the addrinfo */
+    struct addrinfo *ai, *ai_tmp;
+
+    ai = resolve_host(host_name, NULL, address_family);
+    if (!ai) {
+      printf("Netperf could not resolve %s as a host name\n", host_name);
+      exit(-1);
+    }
+    ai_tmp = ai;
+    if (address_family != AF_UNSPEC) {
+      for (; ai_tmp; ai_tmp = ai_tmp->ai_next) {
+        if (address_family == ai_tmp->ai_family)
+	  break;
+      }
+      if (!ai_tmp) {
+        printf("Netperf address family mismatch: host %s, family %d\n",
+		host_name, address_family);
+        exit(-1);
+      }
+    }
+    address_family = ai_tmp->ai_family;
+    freeaddrinfo(ai);
   }
   
   /* now, having established the name to which the control will



More information about the netperf-dev mailing list