原文地址:
http://blog.chinaunix.net/uid-452173-id-3211883.html
Proc file of "/proc/net/ipv6_route" has all configured IPv6 routes
shown in a special format. The example displays for loopback interface
only. The meaning is shown below.
# cat /proc/net/ipv6_route
00000000000000000000000000000000 00 00000000000000000000000000000000 00
+------------------------------+ ++ +------------------------------+ ++
| | | |
1 2 3 4
? 00000000000000000000000000000000 ffffffff 00000001 00000001 00200200 lo
? +------------------------------+ +------+ +------+ +------+ +------+ ++
? | | | | | |
? 5 6 7 8 9 10
1. IPv6 destination network displayed in 32 hexadecimal chars without colons as separator
2. IPv6 destination prefix length in hexadecimal
3. IPv6 source network displayed in 32 hexadecimal chars without colons as separator
4. IPv6 source prefix length in hexadecimal
5. IPv6 next hop displayed in 32 hexadecimal chars without colons as separator
6. Metric in hexadecimal
7. Reference counter
8. Use counter
9. Flags
10. Device name
-
-
struct in6_addr src_addr;
-
int src_prefix;
-
struct in6_addr dst_addr;
-
int dst_prefix;
-
struct in6_addr gw_addr;
-
struct in6_addr any_addr;
-
uint32 metrix;
-
uint32 ref_cnt;
-
uint32 usr_cnt;
-
uint32 flag;
-
char devname[IFNAMESIZE];
-
-
fp = fopen("/proc/net/ipv6_route","r");
-
if(fp!=NULL){
-
memset(&any_addr,0,sizeof(any_addr));
-
while((ret=fscanf(fp,"%s %x %s %x %s %x %x %x %x %s",
-
dst,&dst_prefix,src,&src_prefix,gw,
-
&metrix,&ref_cnt,&usr_cnt,&flag,devname))!=EOF){
-
/*return value must be parameter's number*/
-
if(ret!=10){
-
continue;
-
}
-
/*default route?*/
-
if(memcmp(&dst_addr,&any_addr,sizeof(struct in6_addr))==0){
-
sscanf(gw,"%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx
-
%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx",
-
&gw_addr.s6_addr[ 0], &gw_addr.s6_addr[ 1], &gw_addr.s6_addr[ 2],
-
&gw_addr.s6_addr[ 3],&gw_addr.s6_addr[ 4], &gw_addr.s6_addr[ 5],
-
&gw_addr.s6_addr[ 6], &gw_addr.s6_addr[ 7],&gw_addr.s6_addr[ 8],
-
&gw_addr.s6_addr[ 9], &gw_addr.s6_addr[10], &gw_addr.s6_addr[11],
-
&gw_addr.s6_addr[12], &gw_addr.s6_addr[13], &gw_addr.s6_addr[14],
-
&gw_addr.s6_addr[15]);
-
if(gw_addr.s6_addr16[0]==0xFE80){
-
printf("gw address:%s\n",gw)
-
break;
-
}
-
}
-
}
-
}
-
fclose(fp);
阅读(2155) | 评论(0) | 转发(0) |