]> sjero.net Git - iperf/blobdiff - src/PerfSocket.cpp
Support for UDP-Lite in iperf
[iperf] / src / PerfSocket.cpp
index 2c169014b080d8bff8fb0bf9416427a6d2d646c1..1c3a779731f692aad66f50072cdf991579557939 100644 (file)
@@ -99,14 +99,22 @@ void SetSocketOptions( thread_Settings *inSettings )
     }
 
 
-    // set IP TOS (type-of-service) field
-#ifdef IP_TOS
+    // Set the DiffServ codepoint for IPv4 TOS or IPv6 traffic class
     if ( inSettings->mTOS > 0 ) {
         val = inSettings->mTOS;
-        rc = setsockopt( inSettings->mSock, IPPROTO_IP, IP_TOS, &val, len );
-        WARN_errno( rc == SOCKET_ERROR, "setsockopt IP_TOS" );
-    }
+#if defined(IP_TOS)
+       if ( inSettings->mSockAF == AF_INET ) {
+          rc = setsockopt( inSettings->mSock, IPPROTO_IP, IP_TOS, &val, len );
+          WARN_errno( rc == SOCKET_ERROR, "setsockopt IP_TOS" );
+       }
 #endif
+#if defined(IPV6_TCLASS)
+       if ( inSettings->mSockAF == AF_INET6 ) {
+         rc = setsockopt( inSettings->mSock, IPPROTO_IPV6, IPV6_TCLASS, &val, len );
+          WARN_errno( rc == SOCKET_ERROR, "setsockopt IPV6_TCLASS" );
+       }
+#endif
+    }
 
 
     // TCP-specific options
@@ -126,6 +134,13 @@ void SetSocketOptions( thread_Settings *inSettings )
             WARN_errno( rc == SOCKET_ERROR, "setsockopt TCP_NODELAY" );
         }
 #endif
+        if ( inSettings->congAlgo ) {
+            len = strlen( inSettings->congAlgo );
+            rc = setsockopt( inSettings->mSock, IPPROTO_TCP, TCP_CONGESTION,
+                             inSettings->congAlgo , len );
+            WARN_errno( rc == SOCKET_ERROR, "setsockopt TCP_CONGESTION" );
+        }
+
     } else {
         rc = set_buffer_sock_size(inSettings->mSock, inSettings->mWinSize,
                                   inSettings->mThreadMode == kMode_Client);
@@ -142,6 +157,18 @@ void SetSocketOptions( thread_Settings *inSettings )
                          &val, len );
         WARN_errno( rc == SOCKET_ERROR, "setsockopt DCCP_SOCKOPT_SERVICE" );
     }
+    //  UDP-Lite specific options
+    if ( inSettings->mProtocol == kProto_UDPLITE ) {
+        /* we set the checksum coverage for both directions */
+        rc = setsockopt(inSettings->mSock, IPPROTO_UDPLITE, UDPLITE_SEND_CSCOV,
+                        &inSettings->cscov, len);
+        WARN_errno(rc == SOCKET_ERROR, "setsockopt UDPLITE_SEND_CSCOV");
+
+        rc = setsockopt(inSettings->mSock, IPPROTO_UDPLITE, UDPLITE_RECV_CSCOV,
+                        &inSettings->cscov, len);
+
+        WARN_errno(rc == SOCKET_ERROR, "setsockopt UDPLITE_RECV_CSCOV");
+    }
 
     // reuse the address, so we can run if a former server was killed off
     if (inSettings->mThreadMode == kMode_Listener) {