4

我正在尝试使用setsockoptIPTOS值设置为IPTOS_THROUGHPUT. setsockopt电话回来了0。但是,getsockopt显示IP_TOS值设置为1,与IPTOS_THROUGHPUT( 0x8) 不同。有谁知道是什么导致了and的IPTOS价值不匹配?setsockoptgetsockopt

这是日志输出:

在套接字 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;
      }
   }
}
4

1 回答 1

4

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

于 2012-10-31T17:29:38.083 回答