connect() returns "Network unreachable", but it isn't??

This is a discussion on connect() returns "Network unreachable", but it isn't?? within the Networking/Device Communication forums, part of the General Programming Boards category; Hi all, What would lead connect() to fail and return "Network unreachable"? What I'm trying to do is send a ...

  1. #1
    Registered User
    Join Date
    Jun 2003
    Posts
    41

    Unhappy connect() returns "Network unreachable", but it isn't??

    Hi all,
    What would lead connect() to fail and return "Network unreachable"? What I'm trying to do is send a brief msg through port 80 to www.nerrenvirons.org from inside my firewall. I can websurf there, traceroute there, etc.., so as far as I can tell, the network CAN be reached. However whenever I execute this code, I always get "Network unreachable".

    Both destination and source are running Apache -- but that means port 80 MUST be open, since I can http://www.nerrenvirons.org, right?

    Here's my code. Any ideas??

    Code:
        
       //now open a socket to homebase so we can transmit the data
       if ((sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0)
       {
          Log("While trying to open a socket to home base, it failed");
          delete data;
          return (FALSE);
       } //end if
        
       //resolve our hostname into a host struct to get the IP address
       struct hostent *hostStructure = gethostbyname(repositoryURL);
    
       //construct the server address structure 
       memset(&ServerAddress, 0, sizeof(ServerAddress));     // zero out the structure to begin with
       ServerAddress.sin_family      = AF_INET;            
       ServerAddress.sin_addr.s_addr = inet_addr(hostStructure->h_addr_list[0]); //just try the first address 
       ServerAddress.sin_port        = htons(repositoryPort); 
             
       JString msg = "GET blah";
       Log("Sending this to home base: " + msg);   
       
       // now establish the actual connection to home base
       if (connect(sock, (struct sockaddr *) &ServerAddress, sizeof(ServerAddress)) < 0)
       {
          Log("Connect failed - " + (JString)strerror(errno));
          Log(hostStructure->h_addr_list[0]);
          delete data;
          return (FALSE);
       } //end if
    Now when I set a break-point right before connect is called, these are the values, which SEEM to make sense:

    hostStructure->h_name="grampus.marisys.com"
    hostStructure.h_aliases[0] = "www.nerrenvirons.org"

    ServerAddress.sin_addr = 4294967295

    NOTE: www.nerrenvirons.org sites behind a proxy server called grampus.marisys.com.

    Any ideas?? Thanks for any help.

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231

    Re: connect() returns "Network unreachable", but it isn't??

    >>What would lead connect() to fail and return "Network unreachable"?<<
    Receipt of an ICMP packet saying so.

    >>ServerAddress.sin_addr = 4294967295
    That number equates to 255.255.255.255

    http://www.ecst.csuchico.edu/~beej/guide/net_old/#dns
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  3. #3
    Registered User
    Join Date
    Jun 2003
    Posts
    41

    Thumbs up

    Thanks! Your link explained everything, it works fine now.

    Now I keep getting HTTP errors since I assume I'm not building my HTTP request headers properly. Know of any beginner's links to HTTP? Reading the RFC is a little overwhelming.

    Thanks again for your help.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Polynomials and ADT's
    By Emeighty in forum C++ Programming
    Replies: 20
    Last Post: 08-19-2008, 08:32 AM
  2. connect timeout
    By X PaYnE X in forum Networking/Device Communication
    Replies: 8
    Last Post: 05-14-2005, 09:30 PM
  3. connect() returns -1
    By Da-Nuka in forum Networking/Device Communication
    Replies: 3
    Last Post: 03-02-2005, 03:56 PM
  4. Client timed-out once on connect(), can never connect() again
    By registering in forum Networking/Device Communication
    Replies: 6
    Last Post: 10-28-2003, 02:46 PM
  5. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21