4
我試圖用setsockopt
將IPTOS
的值設置爲IPTOS_THROUGHPUT
。致電setsockopt
致電0
。但getsockopt
顯示IP_TOS
值設置爲1
,這與IPTOS_THROUGHPUT
(0x8
)不同。有沒有人知道可能導致setsockopt
和getsockopt
中IPTOS
值不匹配的原因?getsockopt從setsockopt返回不同的IP_TOS值
這裏的日誌輸出:
設置DSCP標記在插座26
在插座26 setsockopt的8個返回0
DSCP的插座26標記爲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;
}
}
}
非常感謝胡!那就是問題所在! –