1. StackMasher

    OP StackMasher GBAtemp Regular
    Member

    Joined:
    Nov 29, 2016
    Messages:
    136
    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, Mar 9, 2017
  2. th3_r3v

    th3_r3v Newbie
    Newcomer

    Joined:
    Apr 6, 2017
    Messages:
    8
    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.
     

    Attached Files:

  3. evandixon

    evandixon PMD Researcher
    Developer

    Joined:
    May 29, 2009
    Messages:
    1,725
    Country:
    United States
Draft saved Draft deleted
Loading...

Hide similar threads Similar threads with keywords - simple, client,