fire64
08.06.2009, 16:01
Помогите понять, почему данная программа падает на многих компьютерах
#include<stdio.h>
#include<string.h>
#include<winsock2.h>
#include<windows.h>
#define HTTP_PORT 80
#define HTTP_IP "63.228.223.110"
#define HOST "store.steampowered.com"
struct mstudiodata_t
{
int a[1];
char b[3];
char c[3];
};
//
// The Scan function
//
int main()
{
// This function does the actual scanning
WSADATA wsaData;
WSAStartup(MAKEWORD(2,2), &wsaData);
FILE *fp = fopen( "steamid.txt", "wb" );
for( int index = 0; index < 50000; ++index )
{
SOCKET hSocket;
// Initialize the socket
hSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_IP);
if (hSocket == INVALID_SOCKET)
{
// Return FALSE in case of an error
return FALSE;
}
sockaddr_in sin;
sin.sin_addr.S_un.S_addr = inet_addr ( HTTP_IP );;
sin.sin_family = AF_INET;
sin.sin_port = htons(HTTP_PORT);
fd_set fd_read, fd_write, fd_error;
timeval timeout;
timeout.tv_sec = 3; // TODO: Hardcoded, should be configurable
timeout.tv_usec = 0;
u_long nNonBlocking = 1;
// Set socket to non-blocking mode
ioctlsocket(hSocket, FIONBIO, &nNonBlocking);
BOOL bConnected = FALSE;
// Estabilish a TCP connection
connect(hSocket, (sockaddr*)&sin, sizeof(sin));
fd_write.fd_array[0] = hSocket; fd_write.fd_count = 1;
fd_error.fd_array[0] = hSocket; fd_error.fd_count = 1;
if (select(0, 0, &fd_write, &fd_error, &timeout) > 0)
{
if (fd_write.fd_count > 0)
{
// Connection successful
bConnected = TRUE;
}
}
char zapros[2048];
char forma[40] = "";
sprintf(forma, "app/%d", index);
strcpy(zapros,"GET /");
strcat(zapros, forma);
strcat(zapros," HTTP/1.1\nHost: ");
strcat(zapros, HOST);
strcat(zapros,"\nUser-agent: ");
strcat(zapros,"Mozilla/5.0 (Windows; U; Windows NT 5.1; ru; rv:1.9.0.8) Gecko/2009032609 )");
strcat(zapros,"\nAccept: */*\n\n");
if (!bConnected)
{
printf( "Cannot connected\n" );
return FALSE;
}
else
{
// Send the magic http request
if (send(hSocket, zapros, strlen(zapros), 0) == SOCKET_ERROR)
return FALSE;
fd_read.fd_array[0] = hSocket; fd_read.fd_count = 1;
fd_error.fd_array[0] = hSocket; fd_error.fd_count = 1;
char otvet[1] = "";
while (select(0, &fd_read, 0, &fd_error, &timeout) > 0)
{
if (fd_read.fd_count > 0)
{
int nNumRead = recv(hSocket, otvet, 9216, 0);
if (nNumRead <= 0)
break;
}
else
{
break;
}
}
char *found;
found = strstr (otvet,"200");
if (found)
{
char *nachalo = strstr (otvet,"<title>");
char *conec = strstr (otvet,"</title>");
int sizetitle = strlen(nachalo) - strlen(conec);
char pretitle[1] = "";
if ( nachalo )
{
strncat (pretitle, nachalo, sizetitle);
mstudiodata_t *Hdr = ( mstudiodata_t * )pretitle;
char *steam = strstr (Hdr->c,"on Steam");
if( steam )
{
int gamelen = strlen(Hdr->c) - strlen(steam);
char title[1] = "";
strncat (title, Hdr->c, gamelen);
printf( "Game: %s ID: %d\n", title, index );
fprintf( fp, "Game: %s ID: %d\n", title, index );
}
else
{
printf( "Game: %s ID: %d\n", Hdr->c, index );
fprintf( fp, "Game: %s ID: %d\n", Hdr->c, index );
}
}
}
}
closesocket(hSocket);
}
fclose(fp);
return TRUE;
}
#include<stdio.h>
#include<string.h>
#include<winsock2.h>
#include<windows.h>
#define HTTP_PORT 80
#define HTTP_IP "63.228.223.110"
#define HOST "store.steampowered.com"
struct mstudiodata_t
{
int a[1];
char b[3];
char c[3];
};
//
// The Scan function
//
int main()
{
// This function does the actual scanning
WSADATA wsaData;
WSAStartup(MAKEWORD(2,2), &wsaData);
FILE *fp = fopen( "steamid.txt", "wb" );
for( int index = 0; index < 50000; ++index )
{
SOCKET hSocket;
// Initialize the socket
hSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_IP);
if (hSocket == INVALID_SOCKET)
{
// Return FALSE in case of an error
return FALSE;
}
sockaddr_in sin;
sin.sin_addr.S_un.S_addr = inet_addr ( HTTP_IP );;
sin.sin_family = AF_INET;
sin.sin_port = htons(HTTP_PORT);
fd_set fd_read, fd_write, fd_error;
timeval timeout;
timeout.tv_sec = 3; // TODO: Hardcoded, should be configurable
timeout.tv_usec = 0;
u_long nNonBlocking = 1;
// Set socket to non-blocking mode
ioctlsocket(hSocket, FIONBIO, &nNonBlocking);
BOOL bConnected = FALSE;
// Estabilish a TCP connection
connect(hSocket, (sockaddr*)&sin, sizeof(sin));
fd_write.fd_array[0] = hSocket; fd_write.fd_count = 1;
fd_error.fd_array[0] = hSocket; fd_error.fd_count = 1;
if (select(0, 0, &fd_write, &fd_error, &timeout) > 0)
{
if (fd_write.fd_count > 0)
{
// Connection successful
bConnected = TRUE;
}
}
char zapros[2048];
char forma[40] = "";
sprintf(forma, "app/%d", index);
strcpy(zapros,"GET /");
strcat(zapros, forma);
strcat(zapros," HTTP/1.1\nHost: ");
strcat(zapros, HOST);
strcat(zapros,"\nUser-agent: ");
strcat(zapros,"Mozilla/5.0 (Windows; U; Windows NT 5.1; ru; rv:1.9.0.8) Gecko/2009032609 )");
strcat(zapros,"\nAccept: */*\n\n");
if (!bConnected)
{
printf( "Cannot connected\n" );
return FALSE;
}
else
{
// Send the magic http request
if (send(hSocket, zapros, strlen(zapros), 0) == SOCKET_ERROR)
return FALSE;
fd_read.fd_array[0] = hSocket; fd_read.fd_count = 1;
fd_error.fd_array[0] = hSocket; fd_error.fd_count = 1;
char otvet[1] = "";
while (select(0, &fd_read, 0, &fd_error, &timeout) > 0)
{
if (fd_read.fd_count > 0)
{
int nNumRead = recv(hSocket, otvet, 9216, 0);
if (nNumRead <= 0)
break;
}
else
{
break;
}
}
char *found;
found = strstr (otvet,"200");
if (found)
{
char *nachalo = strstr (otvet,"<title>");
char *conec = strstr (otvet,"</title>");
int sizetitle = strlen(nachalo) - strlen(conec);
char pretitle[1] = "";
if ( nachalo )
{
strncat (pretitle, nachalo, sizetitle);
mstudiodata_t *Hdr = ( mstudiodata_t * )pretitle;
char *steam = strstr (Hdr->c,"on Steam");
if( steam )
{
int gamelen = strlen(Hdr->c) - strlen(steam);
char title[1] = "";
strncat (title, Hdr->c, gamelen);
printf( "Game: %s ID: %d\n", title, index );
fprintf( fp, "Game: %s ID: %d\n", title, index );
}
else
{
printf( "Game: %s ID: %d\n", Hdr->c, index );
fprintf( fp, "Game: %s ID: %d\n", Hdr->c, index );
}
}
}
}
closesocket(hSocket);
}
fclose(fp);
return TRUE;
}