我正在尝试使用setsockopt
将IPTOS
值设置为IPTOS_THROUGHPUT
. setsockopt
电话回来了0
。但是,getsockopt
显示IP_TOS
值设置为1
,与IPTOS_THROUGHPUT
( 0x8
) 不同。有谁知道是什么导致了and的IPTOS
价值不匹配?setsockopt
getsockopt
这是日志输出:
在套接字 26 上设置 DSCP 标记
套接字 26 到 8 上的 setsockopt 返回 0
插座 26 上的 DSCP 标记为 1,与预期的 8 不同
下面是代码:
int iptos = IPTOS_THROUGHPUT;
log(debug, 10, "Set DSCP Marking on socket %d\n", sockfd);
retval = setsockopt(sockfd, IPPROTO_TCP, IP_TOS, &iptos, sizeof(iptos));
if (retval<0) {
log(error, 99, "Failed to set DSCP marking on socket %d with error %d\n",
sockfd, retval);
} else {
log(debug, 10, "setsockopt on socket %d to %d returns %d\n", sockfd, iptos,
retval);
int tos=0;
socklen_t toslen=sizeof(tos);
retval = getsockopt(sockfd, IPPROTO_TCP, IP_TOS, &tos, &toslen);
if(retval<0) {
log(warning, 99, "Failed to get DSCP marking on socket %d with error %d\n",
sockfd, retval);
}else {
if( tos != iptos ) {
log(warning, 99, "DSCP marking on socket %d is %d, different from expected %d\n",
sockfd, tos, iptos);
retval = 9999;
}
else {
log(debug, 10, "Success: Set DSCP Marking on socket %d to %d\n",
sockfd, iptos);
retval = 0;
}
}
}