Failed adding host to route table

bridged with qdn.public.ddk.network
Post Reply
Beth

Failed adding host to route table

Post by Beth » Wed Jan 08, 2003 7:37 pm

I have QNX 6.1 system running Tiny TCPIP stack. Before adding a host to
routing table the ipstats shows the following:
.....
....
en0 : addr 192.168.2.45 netmask 255.255.255.0 up
lo0 : addr 127.0.0.1 netmask 255.0.0.0 up

DST: 192.168.2.0 NETMASK: 255.255.255.0 GATEWAY: en0
DST: 127.0.0.0 NETMASK: 255.0.0.0 GATEWAY: lo0
DST: 0.0.0.0 NETMASK: 0.0.0.0 GATEWAY: 192.168.2.1
....

I ran a program "addrt" to add host into the table, the ipstats is
changed to:
...
en0 : addr 192.168.2.45 netmask 255.255.255.0 up
lo0 : addr 127.0.0.1 netmask 255.0.0.0 up

DST: 192.168.2.27 NETMASK: 255.255.255.255 GATEWAY: 192.168.2.1
DST: 192.168.2.0 NETMASK: 255.255.255.0 GATEWAY: en0
DST: 127.0.0.0 NETMASK: 255.0.0.0 GATEWAY: lo0
DST: 0.0.0.0 NETMASK: 0.0.0.0 GATEWAY: 192.168.2.1
...

The problem is, when I ping the host 192.168.2.27, 50% of time, it's
successful. When it's failed,
the ping never came back.

Any idea how I can debug this problem?

Here is my source code:
int main(int argc, char * argv[])
{
int sock;
int rc = 0;
struct ortentry rt;
struct sockaddr_in *rt_gateway;
struct sockaddr_in *rt_dst;
struct sockaddr_in *rt_netmask;
ip_addr p_ip, p_mask, p_gw;

/* add host to gw */

char ipbuf[30]="192.168.2.27";
char gwbuf[30]="192.168.2.1";
char mskbuf[30]="255.255.255.255";
int cmd = SIOCADDRT;

sock = socket( AF_INET, SOCK_DGRAM, 0 );
if ( sock < 0 )
return sock;

memset( &rt, 0, sizeof(rt) );

rt.rt_flags = RTF_HOST | RTF_UP;

rt_gateway = (struct sockaddr_in *)&rt.rt_gateway;
rt_dst = (struct sockaddr_in *)&rt.rt_dst;
rt_netmask = (struct sockaddr_in *)&rt.rt_netmask;

rt_gateway->sin_family = AF_INET;
rt_dst->sin_family = AF_INET;
rt_netmask->sin_family = AF_INET;

rt_gateway->sin_len = sizeof(rt.rt_gateway);
rt_dst->sin_len = sizeof(rt.rt_dst);
rt_netmask->sin_len = sizeof(rt.rt_netmask);

ip_addr_set_long(&p_gw, inet_network(gwbuf), IP_HOSTORDER);
ip_addr_set_long( &p_mask, inet_network(mskbuf), IP_HOSTORDER);
ip_addr_set_long( &p_ip, inet_network(ipbuf), IP_HOSTORDER);

rt_gateway->sin_addr.s_addr = p_gw.net_order.s_addr;
rt_dst->sin_addr.s_addr = p_ip.net_order.s_addr;
rt_netmask->sin_addr.s_addr = p_mask.net_order.s_addr;

if ( (rc = ioctl( sock, cmd, &rt )) == -1 ) {
printf ( "error is: %d, %s \n", errno, strerror(errno) );
}
close( sock );

return rc;
}


Thanks,
-Beth

Mike Lee

Re: Failed adding host to route table

Post by Mike Lee » Tue Jan 14, 2003 3:37 pm

I don't think you can have a Netmask of all ones. Your problem should go
away if you correct your Netmask.

"Beth" <id@address.com> wrote in message
news:3E1C7DFE.C158009F@address.com...
I have QNX 6.1 system running Tiny TCPIP stack. Before adding a host to
routing table the ipstats shows the following:
....
...
en0 : addr 192.168.2.45 netmask 255.255.255.0 up
lo0 : addr 127.0.0.1 netmask 255.0.0.0 up

DST: 192.168.2.0 NETMASK: 255.255.255.0 GATEWAY: en0
DST: 127.0.0.0 NETMASK: 255.0.0.0 GATEWAY: lo0
DST: 0.0.0.0 NETMASK: 0.0.0.0 GATEWAY: 192.168.2.1
...

I ran a program "addrt" to add host into the table, the ipstats is
changed to:
..
en0 : addr 192.168.2.45 netmask 255.255.255.0 up
lo0 : addr 127.0.0.1 netmask 255.0.0.0 up

DST: 192.168.2.27 NETMASK: 255.255.255.255 GATEWAY: 192.168.2.1
DST: 192.168.2.0 NETMASK: 255.255.255.0 GATEWAY: en0
DST: 127.0.0.0 NETMASK: 255.0.0.0 GATEWAY: lo0
DST: 0.0.0.0 NETMASK: 0.0.0.0 GATEWAY: 192.168.2.1
..

The problem is, when I ping the host 192.168.2.27, 50% of time, it's
successful. When it's failed,
the ping never came back.

Any idea how I can debug this problem?

Here is my source code:
int main(int argc, char * argv[])
{
int sock;
int rc = 0;
struct ortentry rt;
struct sockaddr_in *rt_gateway;
struct sockaddr_in *rt_dst;
struct sockaddr_in *rt_netmask;
ip_addr p_ip, p_mask, p_gw;

/* add host to gw */

char ipbuf[30]="192.168.2.27";
char gwbuf[30]="192.168.2.1";
char mskbuf[30]="255.255.255.255";
int cmd = SIOCADDRT;

sock = socket( AF_INET, SOCK_DGRAM, 0 );
if ( sock < 0 )
return sock;

memset( &rt, 0, sizeof(rt) );

rt.rt_flags = RTF_HOST | RTF_UP;

rt_gateway = (struct sockaddr_in *)&rt.rt_gateway;
rt_dst = (struct sockaddr_in *)&rt.rt_dst;
rt_netmask = (struct sockaddr_in *)&rt.rt_netmask;

rt_gateway->sin_family = AF_INET;
rt_dst->sin_family = AF_INET;
rt_netmask->sin_family = AF_INET;

rt_gateway->sin_len = sizeof(rt.rt_gateway);
rt_dst->sin_len = sizeof(rt.rt_dst);
rt_netmask->sin_len = sizeof(rt.rt_netmask);

ip_addr_set_long(&p_gw, inet_network(gwbuf), IP_HOSTORDER);
ip_addr_set_long( &p_mask, inet_network(mskbuf), IP_HOSTORDER);
ip_addr_set_long( &p_ip, inet_network(ipbuf), IP_HOSTORDER);

rt_gateway->sin_addr.s_addr = p_gw.net_order.s_addr;
rt_dst->sin_addr.s_addr = p_ip.net_order.s_addr;
rt_netmask->sin_addr.s_addr = p_mask.net_order.s_addr;

if ( (rc = ioctl( sock, cmd, &rt )) == -1 ) {
printf ( "error is: %d, %s \n", errno, strerror(errno) );
}
close( sock );

return rc;
}


Thanks,
-Beth

Post Reply

Return to “qdn.public.ddk.network”