On Wed, Nov 16, 2005 at 10:06:27AM -0800, Martin wrote: > What / how do I construct a routing raw socket call to retrieve the > outgoing interface index for a particular route that is destined out of > an interface other than Ethernet such as a point to point? > > With Ethernet interfaces I was able to contruct a rt_msghdr with RTM_GET > and RTA_DST- retrieve the gateway IP for the route then recursively call > the same function passing the gateway IP and the sock_addr_in > ->sin_addr.s_port would return with the interface index. > > But this does not work with PPP interfaces or other non-Ethernet. Any > insight to what i am lacking in the route request would be appreciated. > Apply the below patch to the route(8) command, then issue this:
route -vn get -host x.x.x.x The IFP sockaddr will always be sockaddr_dl (AF_LINK) which has an interface index. For example, : # ifconfig ng0 10.0.0.1 10.0.0.2 : # ./route -vn get -host 10.0.0.2 : u: inet 10.0.0.2; u: link ; RTM_GET: Report Metrics: len 164, pid: 0, seq 1, errno 0, flags:<UP,GATEWAY,HOST,STATIC> : locks: inits: : sockaddrs: <DST,IFP> : 10.0.0.2 :0 : route to: 10.0.0.2 : destination: 10.0.0.2 : interface: ng0 : flags: <UP,HOST,DONE> : recvpipe sendpipe ssthresh rtt,msec rttvar hopcount mtu expire : 0 0 0 0 0 0 1500 0 : : locks: inits: : sockaddrs: <DST,GATEWAY,IFP,IFA,BRD> : 10.0.0.2 10.0.0.1 ng0:3 10.0.0.1 10.0.0.2 ^^^^^ %%% Index: route.c =================================================================== RCS file: /home/ncvs/src/sbin/route/route.c,v retrieving revision 1.81 diff -u -r1.81 route.c --- route.c 28 Sep 2005 12:12:15 -0000 1.81 +++ route.c 16 Nov 2005 19:35:30 -0000 @@ -385,7 +385,12 @@ break; case AF_LINK: - return (link_ntoa((struct sockaddr_dl *)sa)); + { + static char buf[80]; + struct sockaddr_dl *sdl = (struct sockaddr_dl *)sa; + sprintf(buf, "%s:%d", link_ntoa(sdl), sdl->sdl_index); + return (buf); + } default: { u_short *s = (u_short *)sa; %%% Cheers, -- Ruslan Ermilov [EMAIL PROTECTED] FreeBSD committer
pgpCUW9arxsQO.pgp
Description: PGP signature