]> sjero.net Git - iperf/blobdiff - src/PerfSocket.cpp
Support for UDP-Lite in iperf
[iperf] / src / PerfSocket.cpp
index 04a68b9583ced9bb44de5a7f070fdebbcd76c660..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
@@ -149,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) {