- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
int makedata(int id,int part,void *d,int datalen,void *buf)
{
//packet struct :
// code = short int, lenght = shotr int, id = int, numofpart = int, data = 1024
int packlen = sizeof(short int)*2 + sizeof(int)*2 + datalen;
char *tbuf = new char [packlen];
char* tbufptr = tbuf;
*((short int *)tbufptr) = data; //first field
(short int *)tbufptr++;
*((short int *)tbufptr) = packlen; //second field
(short int *)tbufptr++;
*((int *)tbufptr) = id;
(int *)tbufptr++;
*((int *)tbufptr) = part;
(int *)tbufptr++;
*((short int *)tbufptr) = datalen;
(short int *)tbufptr++;
memcpy((void*)tbufptr,d,datalen);
buf=tbuf;
return packlen;
}
fileinfo* getask(void *b)
{
fileinfo *fi = new fileinfo();
char *bufptr = (char*)b;
(short int*)bufptr++;
short int plen = *((short int*)bufptr);
(short int*)bufptr++;
fi->numofpart = *((int*)bufptr);
(int*)bufptr++;
fi->filelenght = *((int*)bufptr);
(int*)bufptr++;
int filelen = plen-(bufptr-(char*)b);
fi->filename = new char[filelen];
strncpy(fi->filename,bufptr,filelen);
return fi;
}
Вместо того, что бы воспользоваться структурой, забиваем всё ручками.