]> sjero.net Git - iperf/blobdiff - src/ReportDefault.c
Native IPv6 support for iperf
[iperf] / src / ReportDefault.c
index a3ecc979060091c31dc30242c9cbd946668ce274..dcb38527476d9ed3c71d14580409568ff39cf8eb 100644 (file)
@@ -140,6 +140,17 @@ void reporter_serverstats( Connection_Info *nused, Transfer_Info *stats ) {
     reporter_printstats( stats );
 }
 
+static char *McastIface(const unsigned if_index)
+{
+       static char ifnam[IF_NAMESIZE];
+
+       if (!if_index)
+               return "default interface";
+       if (if_indextoname(if_index, ifnam))
+               return ifnam;
+       return "unknown interface";
+}
+
 /*
  * Report the client or listener Settings in default style
  */
@@ -162,19 +173,18 @@ void reporter_reportsettings( ReporterData *data ) {
                 data->mPort );
     }
     if ( data->mLocalhost != NULL ) {
-        printf( bind_address, data->mLocalhost );
-        if ( SockAddr_isMulticast( &data->connection.local ) ) {
-            printf( join_multicast, data->mLocalhost );
-        }
+        if (SockAddr_isMulticast((struct sockaddr *)&data->connection.local))
+            printf(join_multicast, data->mLocalhost, McastIface(data->mMcastIface));
+       else
+           printf(bind_address, data->mLocalhost);
     }
 
     if ( isPacketOriented( data ) ) {
         printf( (data->mThreadMode == kMode_Listener ? 
                  server_datagram_size : client_datagram_size),
                 data->mBufLen );
-        if ( SockAddr_isMulticast( &data->connection.peer ) ) {
+        if (SockAddr_isMulticast((struct sockaddr *)&data->connection.peer))
             printf( multicast_ttl, data->info.mTTL);
-        }
     } else if (data->mProtocol == kProto_DCCP)
             printf("NOTE: running in bytestream-mode (maximum speed)\n");
 
@@ -200,56 +210,20 @@ void reporter_reportsettings( ReporterData *data ) {
 /*
  * Report a socket's peer IP address in default style
  */
-void *reporter_reportpeer( Connection_Info *stats, int ID ) {
-    if ( ID > 0 ) {
-        // copy the inet_ntop into temp buffers, to avoid overwriting
-        char local_addr[ REPORT_ADDRLEN ];
-        char remote_addr[ REPORT_ADDRLEN ];
-        struct sockaddr *local = ((struct sockaddr*)&stats->local);
-        struct sockaddr *peer = ((struct sockaddr*)&stats->peer);
-    
-        if ( local->sa_family == AF_INET ) {
-            inet_ntop( AF_INET, &((struct sockaddr_in*)local)->sin_addr, 
-                       local_addr, REPORT_ADDRLEN);
-        }
-#ifdef HAVE_IPV6
-          else {
-            inet_ntop( AF_INET6, &((struct sockaddr_in6*)local)->sin6_addr, 
-                       local_addr, REPORT_ADDRLEN);
-        }
-#endif
-    
-        if ( peer->sa_family == AF_INET ) {
-            inet_ntop( AF_INET, &((struct sockaddr_in*)peer)->sin_addr, 
-                       remote_addr, REPORT_ADDRLEN);
-        }
-#ifdef HAVE_IPV6
-          else {
-            inet_ntop( AF_INET6, &((struct sockaddr_in6*)peer)->sin6_addr, 
-                       remote_addr, REPORT_ADDRLEN);
-        }
-#endif
-    
-        printf( report_peer,
-                ID,
-                local_addr,  ( local->sa_family == AF_INET ?
-                              ntohs(((struct sockaddr_in*)local)->sin_port) :
-#ifdef HAVE_IPV6
-                              ntohs(((struct sockaddr_in6*)local)->sin6_port)),
-#else
-                              0),
-#endif
-                remote_addr, ( peer->sa_family == AF_INET ?
-                              ntohs(((struct sockaddr_in*)peer)->sin_port) :
-#ifdef HAVE_IPV6
-                              ntohs(((struct sockaddr_in6*)peer)->sin6_port)));
-#else
-                              0));
-#endif
+void *reporter_reportpeer(Connection_Info *stats, int ID)
+{
+    if (ID > 0) {
+        char    laddr[REPORT_ADDRLEN],
+                daddr[REPORT_ADDRLEN];
+       unsigned lport = SockAddr_port(&stats->local),
+                dport = SockAddr_port(&stats->peer);
+
+       SockAddr_name(&stats->local, laddr, sizeof(laddr));
+       SockAddr_name(&stats->peer,  daddr, sizeof(daddr));
+        printf(report_peer, ID, laddr, lport, daddr, dport);
     }
     return NULL;
 }
-// end ReportPeer
 
 /* -------------------------------------------------------------------
  * Report the MSS and MTU, given the MSS (or a guess thereof)