}
- // 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
{"listenport", required_argument, NULL, 'L'},
{"parallel", required_argument, NULL, 'P'},
{"remove", no_argument, NULL, 'R'},
-{"tos", required_argument, NULL, 'S'},
+{"dscp", required_argument, NULL, 'S'},
{"ttl", required_argument, NULL, 'T'},
{"single_udp", no_argument, NULL, 'U'},
{"ipv6_domian", no_argument, NULL, 'V'},
{"IPERF_NODELAY", no_argument, NULL, 'N'},
{"IPERF_LISTENPORT", required_argument, NULL, 'L'},
{"IPERF_PARALLEL", required_argument, NULL, 'P'},
-{"IPERF_TOS", required_argument, NULL, 'S'},
+{"IPERF_DSCP", required_argument, NULL, 'S'},
{"IPERF_TTL", required_argument, NULL, 'T'},
{"IPERF_SINGLE_UDP", no_argument, NULL, 'U'},
{"IPERF_IPV6_DOMAIN", no_argument, NULL, 'V'},
setRemoveService( mExtSettings );
break;
- case 'S': // IP type-of-service
- // TODO use a function that understands base-2
- // the zero base here allows the user to specify
- // "0x#" hex, "0#" octal, and "#" decimal numbers
- mExtSettings->mTOS = strtol( optarg, NULL, 0 );
+ case 'S':
+ // Convert into IPv4/v6 6-bit DiffServ codepoint. If string
+ // - consists of six 0/1 digits, it is seen as binary number;
+ // - is preceded by `0x', it is interpreted as hex number;
+ // - is preceded by `0', it is interpreted as octal number;
+ // - otherwise it is interpreted as decimal number.
+ // The maximum possible 6-bit value is 252 (0xfc).
+ if ( strspn(optarg, "01") == 6 )
+ mExtSettings->mTOS = strtol(optarg, NULL, 2);
+ else
+ mExtSettings->mTOS = strtol(optarg, NULL, 0);
+ if ( mExtSettings->mTOS < 0 || mExtSettings->mTOS > 0xfc )
+ die("Invalid DiffServ codepoint %s", optarg);
+ mExtSettings->mTOS <<= 2;
break;
case 'T': // time-to-live for multicast