免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 927 | 回复: 0
打印 上一主题 下一主题

linux 路由 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-05-14 14:21 |只看该作者 |倒序浏览
linux里面可以从/proc/net/route文件中得到系统的路由信息,以前写过一个程序查找路由表就是通过读这个文件来获得的,不过当时没有考虑每条路由的flags,这里就留下一下bug.其每条路由定义如下(route.h):
               
               
                #define    RTF_UP        0x0001      /* route usable                 */
#define    RTF_GATEWAY    0x0002     /* destination is a gateway    */
#define    RTF_HOST    0x0004        /* host entry (net otherwise)  */
#define    RTF_REINSTATE    0x0008   /* reinstate route after tmout */
#define    RTF_DYNAMIC    0x0010     /* created dyn. (by redirect)  */
#define    RTF_MODIFIED    0x0020    /* modified dyn. (by redirect) */
#define    RTF_MTU        0x0040     /* specific MTU for this route */
#define    RTF_MSS        RTF_MTU    /* Compatibility :-(           */
#define    RTF_WINDOW    0x0080      /* per route window clamping   */
#define    RTF_IRTT    0x0100        /* Initial round trip time     */
#define    RTF_REJECT    0x0200      /* Reject route                */
现在发现,即使你用route命令去删除一条路由,这条路由仍然存在于/proc/net/route文件中,只是系统把这个路由的flags中的RTF_UP去除了,也就是表明其不可用的,所以以前写的程序是有BUG的。
by the way, 可以通过ioctl函数对系统路由表进行操作,对request参数可以为SIOCADDRT(增加路由)和SIOCDELRT(删除路径),而其实际的路由表示为结构struct rtentry,其定义如下(route.h):
struct rtentry
{
    unsigned long    rt_pad1;
    struct sockaddr    rt_dst;        /* target address        */
    struct sockaddr    rt_gateway;    /* gateway addr (RTF_GATEWAY)    */
    struct sockaddr    rt_genmask;    /* target network mask (IP)    */
    unsigned short    rt_flags;
    short        rt_pad2;
    unsigned long    rt_pad3;
    void        *rt_pad4;
    short        rt_metric;    /* +1 for binary compatibility!    */
    char        *rt_dev;    /* forcing the device at add    */
    unsigned long    rt_mtu;        /* per route MTU/Window     */
#ifndef __KERNEL__
#define rt_mss    rt_mtu            /* Compatibility :-(            */
#endif
    unsigned long    rt_window;    /* Window clamping         */
    unsigned short    rt_irtt;    /* Initial RTT            */
};


本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u1/37836/showart_687905.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP