Re: no route to host



On 2006-07-23, davids@xxxxxxxxxxxxx <davids@xxxxxxxxxxxxx> wrote:

jasen wrote:

the error is "no route to host" (as I said above) according to perror(in the
pesudocode) I think that means ENETUNREACH

as far as connect(). (socket() and gethostbyname() work ...)

If you are saying that 'connect' returns 'no route to host', do you
call 'bind' on the socket?

no, I thought bind was only needed for servers. ip(7) suggests that skipping
this step will give my socket a random source address.

The socket opens, connects, and works, the first time.

but if I reset the PPP connection, when my software times out (30s)
and tries to reconnect the DNS queries go out fine (addr 203.152.100.32 ,
I see the TXD/RXD leds flicker) but the connect itself fails.

if I restart the application it works first time, if I retry repeatedly
without restarting it fails every time.

Is this a freshly-allocated socket (from 'socket') or are you trying to
re-use the old socket?

it's a fresh one here's actual code.

static int tcp_open(const char *host,int portno)
{
int sockfd ;
static struct sockaddr_in addr={0};
struct hostent *hi=gethostbyname(host);
printf("tcp_open\n");
if(!hi || hi->h_addrtype != AF_INET )
{
fprintf(stderr,"bad_address: %s\n",host);
return -1;
}

struct in_addr **app=(void*)hi->h_addr_list,**ap2;
for(ap2=app;*ap2;ap2++)
printf("host %s has address %s\n",host,inet_ntoa(**ap2));
if(!*app){fprintf(stderr,"host %s not found\n",host);return -1;}

do
{
sockfd=socket(PF_INET,SOCK_STREAM,IPPROTO_TCP);
if( sockfd < 0)
{
perror("no socket!");
return sockfd;
}
addr.sin_port=htons(portno);
addr.sin_family=AF_INET;
addr.sin_addr=**app;
if( ! connect(sockfd,(void*)&addr,sizeof addr))
return sockfd;
perror("no connect!");
close(sockfd);
}
while(*++app);
perror("gave up!");
printf("Unable to connect!!\n");
return -1;
}


this is the output I get:

tcp_open
host news.free.net.nz has address 203.152.112.31
no connect!: No route to host
gave up!: No route to host
Unable to connect!


Bye.
Jasen
.



Relevant Pages

  • Re: checking connection to server:port
    ... when I trying to connect with PHP it fails: Warning: ... (No route to host) ... irb:001:0> require 'socket' ...
    (comp.lang.ruby)
  • Re: no route to host
    ... If you are saying that 'connect' returns 'no route to host', ... call 'bind' on the socket? ... Is this a freshly-allocated socket or are you trying to ...
    (comp.os.linux.development.apps)
  • Re: Getting "ICMP Host redirect from gateway" response
    ... I tried and succeeded in getting a REDIRECT response, ... I added a route with 192.168.0.10 as a gateway to a local host ...
    (comp.os.linux.networking)
  • ath0 pain on visiting network
    ... ping: sendto: No route to host ...
    (freebsd-current)
  • CISCO 2600 - routing problem
    ... I have Internet access from both the router and the host with static ... but with static route over cable modem: ... I can ping Internet only from router not from ...
    (comp.dcom.sys.cisco)