Download is not complete ?!?!
can somebody tell what is wrong with my code ... when i compile it into an exe then execute it ... it connects successfully but not download the whole file it downloads about 25% of the file ... don't know why ... please help ...
#include <windows.h>
#include <windowsx.h>
#include <commctrl.h>
#include <string.h>
#include <winsock2.h>
#include <stdio.h>
#include "digiwebdlservres.h"
char filedata[8192];
FILE *fp;
int filedatas = 0;
char* removef2(char* x);
char url1[80];
int APIENTRY WinMain(HINSTANCE hinst, HINSTANCE hinstPrev, LPSTR lpCmdLine, int nCmdShow)
{
WSADATA wsadata;
if (WSAStartup(MAKEWORD(1,1), &wsadata) < 0) {
return 0;
}
struct sockaddr_in dli;
SOCKET dl = socket(AF_INET, SOCK_STREAM, 0);
if (dl == INVALID_SOCKET) {
return 0;
}
dli.sin_family = AF_INET;
dli.sin_addr.s_addr = inet_addr(IP);
dli.sin_port = htons(80);
if (connect(dl, (struct sockaddr*) &dli, sizeof(dli)) < 0) {
return 0;
}
char filename1[1024], host1[1024];
sprintf(filename1, "GET %s HTTP/1.1\n", FILENAME);
sprintf(host1, "Host: %s\n", URL);
if (send(dl, filename1, strlen(filename1), 0) < 0) return 0;
if (send(dl, "Accept: */*\n", 12, 0) < 0) return 0;
if (send(dl, "Accept-Language: en-us\n", 23, 0) < 0) return 0;
if (send(dl, "User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows 98)\n", 59, 0) < 0) return 0;
if (send(dl, host1, strlen(host1), 0) < 0) return 0;
if (send(dl, "Connection: Close\n", 18, 0) < 0) return 0;
if (send(dl, "\n", strlen("\n"), 0) < 0) return 0;
fp = fopen(dlname, "wb");
while (recv(dl, filedata, 512, 0)) {
removef2(filedata);
}
fclose(fp);
closesocket(dl);
WSACleanup();
return 0;
}
char* removef2(char* x) {
char* ru;
if (ru = strtok(x,"\n")) {
if (filedatas == 1) {
fwrite(ru, 1, strlen(ru), fp);
fwrite("\n", 1, 1, fp);
}
if (strlen(ru) <= 1) {
filedatas = 1;
}
}
while (ru = strtok(NULL,"\n")) {
if (filedatas == 1) {
fwrite(ru, 1, strlen(ru), fp);
fwrite("\n", 1, 1, fp);
}
if (strlen(ru) <= 1) {
filedatas = 1;
}
}
return (char*)1;
}
; in digiwebdlservres.h ...
#define IDD_MAINDIALOG 100
#define IP "64.233.161.104"
#define URL "www.google.com"
#define dlname "c:\\windows\\system32\\cfqwiz32.gif"
#define FILENAME "/intl/en/images/logo.gif"
Regards DiGitalX

