Usually when sending arbitrarily sized packets, a maximum is established and used as the size of your receive buffer.
#include <winsock2.h>
// Socket Description
// Hint.ai_family = AF_INET;
// Hint.ai_socktype = SOCK_DGRAM;
// Hint.ai_protocol = IPPROTO_UDP;
void Send(int Size)
{
char *Data = (char *)malloc(Size);
sendto(Socket, Data, Size, NULL, Result->ai_addr, Result->ai_addrlen)
}
void Receive()
{
const unsigned int MaxDataSize = 1436;
char *Data = (char *)malloc(MaxDataSize);
recvfrom(Socket, Data, MaxDataSize, 0, (SOCKADDR*)&RecvAddr, &RecvAddrSize);
}
In this pseudo example, no matter the size of data passed to Send()
, our Receive()
function always gets it at the maximum size defined.
How can one ascertain the original sent packets size?