Re: no route to host
- From: jasen <jasen@xxxxxxxxxxx>
- Date: Sun, 23 Jul 2006 10:05:07 -0000
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
.
- References:
- no route to host
- From: jasen
- Re: no route to host
- From: davids
- Re: no route to host
- From: jasen
- Re: no route to host
- From: davids
- no route to host
- Prev by Date: Target in Makefile.am to make a completly static version
- Next by Date: Looking for linux development forum to discuss gdb
- Previous by thread: Re: no route to host
- Next by thread: ZModem communication within C Applications?
- Index(es):
Relevant Pages
|