厚德博学 敬业乐群
@sky
全部博文(252)
2015年(2)
2014年(1)
2013年(1)
2012年(16)
2011年(42)
2010年(67)
2009年(87)
2008年(36)
25742040
shijiulo
niuxlinu
ebayboy
hayand66
大鬼不动
acer1025
醉鬼的故
小雅贝贝
XINGCHEN
wzy_yzw
十的9次
zds05
bjywxc
zlhc1
smile124
cynthia
格伯纳
分类:
2010-07-19 08:35:10
#include <linux/init.h> #include <net/net_namespace.h> #include <linux/module.h> #include <linux/list.h> #include <linux/spinlock_types.h> #include <net/ip_fib.h> #define TABLE_LOCAL_INDEX 0 #define TABLE_MAIN_INDEX 1 MODULE_LICENSE( "Dual BSD/GPL" ); static void print_default_gw(void); /********************************** * 以下结来自 net/ipv4/fib_hash.c *********************************/ struct fib_alias { struct list_head fa_list; struct fib_info *fa_info; u8 fa_tos; u8 fa_type; u8 fa_scope; u8 fa_state; struct rcu_head rcu; }; struct fib_node { struct hlist_node fn_hash; struct list_head fn_alias; __be32 fn_key; struct fib_alias fn_embedded_alias; }; struct fn_zone { struct fn_zone *fz_next; struct hlist_head *fz_hash; int fz_nent; int fz_divisor; u32 fz_hashmask; int fz_order; __be32 fz_mask; }; struct fn_hash { struct fn_zone *fn_zones[33]; struct fn_zone *fn_zone_list; }; /**************************************************************/ static void print_default_gw(void) { struct fib_table *local_table; struct fn_hash *fn; struct hlist_head *hhead; struct list_head *head; struct fib_node *f; struct hlist_node *node; struct fib_alias *fa; hhead = &init_net.ipv4.fib_table_hash[TABLE_LOCAL_INDEX]; local_table = hlist_entry(hhead->first, struct fib_table, tb_hlist); fn = (struct fn_hash *)&local_table->tb_data[0]; hhead = &fn->fn_zones[0]->fz_hash[0]; hlist_for_each_entry(f, node, hhead, fn_hash) { head = (struct list_head *)&f->fn_alias; list_for_each_entry(fa, head, fa_list) { struct fib_info *fi; struct net_device * ndev; fi = fa->fa_info; ndev = fi->fib_nh[0].nh_dev; printk("dev: %s \n",ndev->name); /*打印出网卡*/ printk("default gw ip: %d.%d.%d.%d\n", /*打印出默认网关*/ ((unsigned char *)(&fi->fib_nh[0].nh_gw))[0], \ ((unsigned char *)(&fi->fib_nh[0].nh_gw))[1], \ ((unsigned char *)(&fi->fib_nh[0].nh_gw))[2], \ ((unsigned char *)(&fi->fib_nh[0].nh_gw))[3]); } } } static int gw_init(void) { print_default_gw(); return 0; } static void gw_exit( void ) { printk( KERN_ALERT "Goodbye \n" ); } module_init(gw_init ); module_exit(gw_exit )
上一篇:802.1Q标准中TAG字段简单说明
下一篇:vs code
登录 注册