PS: I know the recv code is bad, it was hastily done and never has worked. I just use ip tools to moniter incoming packets. Also excuse the server IP I know thats not google.com I was using their talk server IP for a second test. Same results different except a different page is returned when I send the packet.
Code: Select all
#include <sys/types.h>
#include <winsock.h>
#include <stdio.h>
int main()
{
WSADATA wsaData;
SOCKADDR_IN sin;
SOCKADDR sina;
int sina_size;
int iResult;
hostent* localHost;
char* localIP;
char *message, *rec;
int rec_size;
system("pause");
iResult = WSAStartup(MAKEWORD(2,2), &wsaData);
if (iResult != 0) {
printf("WSAStartup failed: %d\n", iResult);
return 1;
}
//get a free socket
int socknumb = socket(AF_INET, SOCK_STREAM, 0);
printf("%i\n", socknumb);
localHost = gethostbyname("");
localIP = inet_ntoa (*(struct in_addr *)*localHost->h_addr_list);
sin.sin_family = AF_INET;
sin.sin_addr.s_addr = inet_addr(localIP);
sin.sin_port = htons(1024);
//bind the socket
int bindresult = bind(socknumb, (LPSOCKADDR)&sin, sizeof(sin));
printf("%i\n", bindresult);
sockaddr_in server;
server.sin_family = AF_INET;
server.sin_addr.s_addr = inet_addr( "216.239.51.125" );
server.sin_port = htons( 80 );
//connect to the server
int connectresult = connect(socknumb, (LPSOCKADDR)&server, sizeof(server));
printf("%d\n", connectresult);
while( 1 == 1 )
{
//start message crafting here
message = (char*) malloc (12);
message[0] = char( 8 );
message[1] = char( 0 );
message[2] = char( 48 );
message[3] = char( 0x5c );
message[4] = char( 1 );
message[5] = char( 0 );
message[6] = char( 4 );
message[7] = char( 0 );
//end message craft and send the packet
int sendresult = send(socknumb, message, 32, MSG_DONTROUTE);
printf("%d\n", sendresult);
shutdown(socknumb, SD_SEND);
//recv code
int recresult = 1;
rec = (char*) malloc (rec_size);
recresult = recv(socknumb, rec, rec_size, 0);
int err = WSAGetLastError();
printf("%d %d\n", recresult, err);
int x = 0;
while(x < rec_size)
{
printf("%i ", int(rec[x]));
x++;
}
printf("\n");
system("pause");
}
}