我遇到了一个问题,当我使用该函数getsockopt
获取 MSS 时,我得到了一个负数(或 0)。但是功能是成功的,套接字是正确的值hSocketService
是正确的并且可以工作。
所以我得到了:
getsockopt OK
Taille maximale d'un segment = -13312
这是代码:
int tailleMsgRecu, nbreBytesRecus, finDetectee, tailleS, tailleO;
/* 7. Recherche du MTU -*-Mache pas-*-*/
tailleO=sizeof(int);
if (getsockopt(hSocketService, IPPROTO_TCP, TCP_MAXSEG, &tailleS, &tailleO) == -1)
{
printf("Erreur sur le getsockopt de la socket %d\n", errno);
exit(1);
}
else
{
printf("getsockopt OK\n");
printf("Taille maximale d'un segment = %d\n", tailleS);
}
谢谢
编辑
我忘了准确地说我正在使用带有 Clion 的 cygwin 在 Windows 上运行代码。
我更改了代码,现在tailleS
是类型socklen_t
,打印它的值和printf("Taille maximale d'un segment = %u\n", tailleS);
结果是Taille maximale d'un segment = 0
。
所以问题仍然是一样的,即使 getsockopt 正在工作,我也没有得到正确的值。