Receiving Pong from Gnut I'm developing a Linux Gnutella client for studing purposes. The thing is that I'm trying to prove my version with Gnut, and I don't receive what I expected when Sent my ping.
I send the "GNUTELLA CONNECT...." and Gnut replies my with the "Gnutella OK", so I write into the port the ping with a certaing ID.
I debugged the Gnut code, and I saw that It receives my Ping well, and proccess it ok, and sends to me back, with the same ID i gave it.
The problem is, that I receive anything but what I'm expected to receive.
Thanks.
This is the part of the code where I receive the Pong Structure.
Note: pszBuffer is declared as Global Variable, and is an unsigned *char.
Structure:
struct stHeader
{
unsigned char szID[16];
unsigned char cPayload; // 1 byte
unsigned char cTTL;
unsigned char cHops;
unsigned char lPayLength[4]; // 4 bytes
};
struct stPong
{
unsigned char iPort[2]; // 2 bytes
unsigned char szIP[4];
unsigned char lCantArch[4];
unsigned char lCantKb[4];
};
/************************************************** ****************************/
int fRecibirPong(int iSock)
{
HEADER *stHead;
PAQUETE *pstPaquete;
PONG *stPong;
unsigned long int lTam;
if ((stHead = (HEADER*)malloc(sizeof(HEADER))) == NULL)
{
fMsgError("MEMORIA INSUFICIENTE");
fFin();
}
// printf("Tamaņo de stHead: %d\n", sizeof(HEADER));
memset(pszBuffer,0,MAXBUFCONECT);
if (recv(iSock, pszBuffer, sizeof(HEADER),0) < 0)
{
fMsgError("ERROR AL RECIBIR UN PONG");
fFin();
}
stHead = (HEADER *)pszBuffer;
fImprimirHeader(stHead);
lTam = *((int *)stHead->lPayLength);
printf("Tamaņo de stPong: %ld\n", lTam);
if ((stPong = (PONG*)malloc(sizeof(PONG))) == NULL)
{
fMsgError("MEMORIA INSUFICIENTE");
fFin();
}
memset(pszBuffer,0,MAXBUFCONECT);
if (recv(iSock, pszBuffer, sizeof(PONG),0) < 0)
{
fMsgError("ERROR AL RECIBIR UN PONG");
fFin();
}
stPong = (PONG*)pszBuffer;
fGuardarLog("PONG RECIBIDO");
fImprimirPong(stPong);
return 1;
} |