Link to home
Start Free TrialLog in
Avatar of vividh
vividh

asked on

Accessiing routing information

I have to access the routing information in my program. The file route.h contains the hashed linked list structure as defined in most of the books. But on my Unixware 1.14 version, the structure doesn't contain the "rt_next" member which points to the next routing entry. If this is the case how can you know the exact structure in the system for the routing tables. Where do I get information for this(manuals, header files etc)
Avatar of JYoungman
JYoungman

You are almost certainly better off parsing the output of
"netstat -r".

ASKER CERTIFIED SOLUTION
Avatar of seedy
seedy

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Let me know if you need a code segment that shows how this is done.
Avatar of vividh

ASKER

Seedy can you send me the code segment which will extract me the routing tables from the kernel.
Here you go!

--- code segment start ---
int     fd, iRet;
struct  strioctl ioc;
struct  rtrecord *rtent;
int     iEntries;
int     ii;

if ((fd = open("/dev/ip", O_RDONLY)) < 0) {
        return(-1);
}

/* First find how many entries are in the routing table */
ioc.ic_cmd = SIOCGRTSIZ;
ioc.ic_timout = 0;
ioc.ic_len = 0;
ioc.ic_dp = (caddr_t) NULL ;
if ((iEntries = ioctl(fd, I_STR, (caddr_t) &ioc)) < 0) {
        return(-1);
}

/* Make space for as many entries */
rtent = (struct rtrecord *) malloc(sizeof(struct rtrecord) * iEntries);
if ( rtent == NULL ) {
        return(-1);  
}

/* Get the entries */
ioc.ic_cmd = SIOCGRTTAB;
ioc.ic_timout = 0;
ioc.ic_len = sizeof(struct rtrecord) * iEntries;
ioc.ic_dp = (caddr_t) rtent ;
if ((iRet = ioctl(fd, I_STR, (caddr_t) &ioc)) < 0) {
        return(-1);
}

/* Entries are in rtent ; loop over each entry and do what you want */
for ( ii = 0; ii < iEntries; ii++) {
        /*******   ADD YOUR CODE HERE *****/
        rtent++;
}

--- code segment end ---
Avatar of vividh

ASKER

The SIOCGRTSIZ defination is not available in Unixware 1.1.2/1.1.4. With 2.1 it is perfect but my limitation is that I am currently working on 1.1.2/1.1.4. If you have worked on these pls help me so.

I am sorry, as I said already, I am familiar only with 2.1.  And I do not have a 1.x around here to look into.