In the call to recvfrom I have to pass a pointer to a buffer that I want filled with the actual information that is recieved.
What kind of buffer should this be.
Right now the stuff I am sending is a pointer to a structure similar to this one which will be enclosed inside of each packet class I create.
struct S
{
int iType;
int iSize;
//other info sent here
}sInfo;
Each packet class has a virtual function SendOn that is written like below. I''ll probably just derive this from the base class later on since the code will be the same for all objects. Right now it''s virtual and inside each class packet because I need to make sure that the version of SendOn is the version that corresponds to the actual packet type being sent.
void PacketGeneric::SendOn(const struct sockaddr_in toAddress,
const int socket)
{
toAddress.sin_family = AF_INET;
toAddress.sin_port = htons(iToPort);
toAddress.sin_addr = inet_addr(sToIPAddress);
memset(&(client_addr.sin_zero), ''\0'', 8);
int iBytesSent = 0;
S* infoPointer;
infoPointer = &this->sInfo;
while (iBytesSent < iSize)
{
iBytesSent = iBytesSent + sendto(socket,
infoPointer, SizeOfData(), 0, toAddress,
sizeof(toAddress));
}
}
So the above passes a pointer to a memory location and a size and it should correctly send the information contained inside of the structure. So when the information gets to the other side and a call to recvfrom is made, what kind of data will I be recieving?
Can I simply pass recvfrom a pointer to my PacketGeneric object, examine the type of packet from there and then cast it farther into the correct packet type?
Or so I simply get the size of the data from recvfrom and allocate enough memory for it, place the data into that memory and then find a way to access the type and finally cast it to the correct packet type?
Thanks,
Webby