Why does this simple web client hang

StackMasher

Well-Known Member
OP
Member
Joined
Nov 29, 2016
Messages
136
Trophies
0
Age
20
XP
370
Country
I'm learning networking and sockets so I decided to test my skills by writing a client. It just hangs for some reason:
Code:
#include <sys/socket.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <cstring>
#include <iostream>

const char* request = "GET http://www.imdb.com/index.html HTTP/1.0";

int main()
{
   int sock = socket(AF_INET, SOCK_STREAM, 0);

   try
   {
       if (sock<1)
           throw "Failed to create a socket";

       sockaddr_in session;
       session.sin_port = htons(80);
       session.sin_family = AF_INET;
       session.sin_addr.s_addr = inet_addr("72.21.206.80");

       if (connect(sock, (sockaddr*)&session, sizeof(session)) < 0)
           throw "Failed to establish a connection";

       send(sock, request, strlen(request), 0);
       char buf[1000];
       recv(sock, buf, 1000, 0);

       for (int i{}; i<1000; ++i)
          std::cout << buf[i];
   }
   catch (const char* exc)
   {
       std::cerr << "An error occured: " << exc << std::endl;
       close(sock);
   }
}
Any idea why? (I'm aware of the buffer overflow vuln this is just a quick and dirty program)
 
Last edited by StackMasher,

th3_r3v

Member
Newcomer
Joined
Apr 6, 2017
Messages
8
Trophies
0
Age
49
XP
42
Country
United States
@StackMasher . I would guess it's got something to do with just the GET request outside of a regular 'browser'/client. I tired to perform a simple GET as well with an online tool. I got the same response, a long hang.

In the end, I did receive a report of all the http transactions, but none were executed. Just an fyi. I would guess by looking at the drive-by DL tree that you have close to 200 transactions trying to run, which maybe locking your client as well.
 

Attachments

  • IMG_0129.PNG
    IMG_0129.PNG
    84.3 KB · Views: 226

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
  • No one is chatting at the moment.
    Psionic Roshambo @ Psionic Roshambo: Do I make you randy!!! Lol