WORD version = MAKEWORD(1,1);
WSADATA wsaData;
WSAStartup(version, &wsaData);
unsigned int uint_b;
int uint_size=4;
SOCKET test = socket(AF_INET,SOCK_DGRAM,IPPROTO_UDP);
if(test == INVALID_SOCKET)
{
printf("ERROR: %i\n",WSAGetLastError ());
return;
}
if(getsockopt(test,SOL_SOCKET,SO_MAX_MSG_SIZE,(char*)&uint_b,&uint_size)==SOCKET_ERROR)
{
printf("Error with getsockopt: %i, was %i\n",WSAGetLastError (),uint_b);
return;
}
printf("Size: %i\n",uint_b);
The output I get is:
Size: 65507
So I must be just doing something simple wrong,
Thanks for all help, ~SPH
UDP and getsockopt
I have a simple problem I''m getting 65507 as my maximum packet size... so I am obviously doing something wrong. I recently gave up on my TCP based multiplayer code and deleted it, now I am starting anew with UDP. So I decided to see whay my limitations would be by querying for the packet size:
AIM ME: aGaBoOgAmOnGeR
Perhaps instead of SOL_SOCKET as your level parameter you should use the protocol number of UDP (This is 17 on my system, and under Unix you can do getprotoent(), but I am not sure how to get that number in windows) ?
I don''t actually know, I was just sifting through the man pages for getsockopt. Hope that helped.
I don''t actually know, I was just sifting through the man pages for getsockopt. Hope that helped.
Nope, the MSDN documentation says that SOL_SOCKET is the correct level, and if I specify anything else I get an error.
Thanks, all help is appreciated, ~SPH
AIM ME: aGaBoOgAmOnGeR
quote:
(char*)&uint_b
Why are you casting into a char* ? It calls for an unsigned int, so the casting is not necessary. It doesn''t seem like it would mess anything up, but I suppose it could depending on whether your machine is big-endian or little-endian.
int getsockopt(
SOCKET s,
int level,
int optname,
char* optval,
int* optlen
);
The above is from the MSDN docs, so it does take a char* in windows. Also endian-ness wouldn''t matter because they are both 4 byte types, all pointers are on a 32-bit system.
Casting is a compilation thing, the address is pushed onto the stack all the same no matter the data type.
Anyway, does anyone know what I might be doing wrong with getsockopt?
Thanks, ~SPH
AIM ME: aGaBoOgAmOnGeR
The MSDN documentation also says that you must bind() a socket before you can consider a call to getsocketopt() to retrieve SO_MAX_MSG_SIZE valid. That number you are getting isn''t that bad either, since IPv4 UDP packets have a 16-bit length constraint and a 28-byte UDP header + 65507 = 65535.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement