I'm working on a simple project - I want to transfer binary files using winsock. But I've reached a major problem.
I've studied this and googled for a couple of hours, but I do NOT understand what the problem is.
int recvDll(SOCKET s)
{
int file_size;
char fileLength[50] = "";
FILE *fp;
int bytes_recieved, bytes_sent, bytes_written;
int recs = recv(s, fileLength, 32, 0);
fileLength[recs] = '\0';
file_size = atoi(fileLength);
fp = fopen("testrecv.dll", "wb");
printf("[+] Size of recieved DLL: %d\n", file_size);
while(file_size > 0)
{
printf("filesize: %d\n", file_size);
char buf[512];
if(file_size >= 512)
{
bytes_recieved = recv(s, buf, 512, 0);
} else {
printf("x: %d\n", file_size);
bytes_recieved = recv(s, buf, file_size, 0);
buf[file_size] = '\0';
}
fwrite(buf, bytes_recieved, 1, fp);
file_size -= bytes_recieved;
}
fclose(fp);
return 0;
}
The server that sends the file is written i VB, and splits up the file á 512 byte. But the transfer seems to be discontinued right in the middle of the download.
This is a typical output:
[+] Size of recieved DLL: 122861 filesize: 122861 filesize: 122349 filesize: 121863 filesize: 121351 filesize: 120839 filesize: 120327 filesize: 120324 filesize: 119812 filesize: 119300 filesize: 118864 filesize: 118785 filesize: 118273 filesize: 117761 filesize: 117249 filesize: 117246 filesize: 116734 filesize: 116222 filesize: 115786 filesize: 115707 filesize: 115195 filesize: 114683 filesize: 114171 filesize: 114168 filesize: 113656 filesize: 113144 filesize: 112632 filesize: 112629 filesize: 112117 filesize: 111605 filesize: 111093 filesize: 111090 filesize: 110579
I would appreciate any help, since this has been bugging me for a long time now.


Sign In
Create Account

Back to top









