gpt4 book ai didi

c - getsockopt 返回与 setsockopt 中设置的不同的 IP_TOS 值

转载 作者:IT王子 更新时间:2023-10-29 01:23:55 31 4
gpt4 key购买 nike

我正在尝试使用 setsockoptIPTOS 值设置为 IPTOS_THROUGHPUTsetsockopt 调用返回了 0。但是 getsockopt 显示 IP_TOS 值设置为 1,这不同于 IPTOS_THROUGHPUT (0x8 )。有谁知道是什么导致了 setsockoptgetsockopt 中的 IPTOS 值不匹配?

这是日志输出:

Set DSCP Marking on socket 26

setsockopt on socket 26 to 8 returns 0

DSCP marking on socket 26 is 1, different from expected 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;
}
}
}

最佳答案

您应该使用级别选项 IPPROTO_IP 而不是 IPPROTO_TCP

关于c - getsockopt 返回与 setsockopt 中设置的不同的 IP_TOS 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13162655/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com