I got an issue, when i use the function getsockopt to get the MSS i got a negative number (or 0). But the function is successfull, the socket is correct value hSocketService is correct and working.
So i got:
getsockopt OK
Taille maximale d'un segment = -13312
Here is the code:
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);
}
thanks
EDIT
I forgot to precise that I'm running the code on windows using cygwin with Clion.
I changed the code and now tailleS is of type socklen_t, and printing its value with printf("Taille maximale d'un segment = %u\n", tailleS);
the result is Taille maximale d'un segment = 0.
So the issue is still the same, I'm not getting the right value even if getsockopt is working.
Your
tailleSvariable must be of typesocklen_twhich resolves to an unsigned value on most platforms - You do, however, use a signed integer. This garbles the value.Printing that value should be done with a
%uformat specifier to tellprintfthat this variable is unsigned.And a last remark: You seem to be aware that what you're retrieving is NOT the MTU, but rather the TCP segment size which is a different thing (close, but still different)