当前位置: 技术问答>linux和unix
100分 求ifconfig源码
来源: 互联网 发布时间:2015-10-12
本文导语: 主要为了弄清ifconfig命令是从哪儿读出errors的数量和内核在什么情况下才会增加errors的计数值了 直接回答清楚更好 先谢了,嫌分少可以再加。 | 想看errors的计数值如何产生的为什么要看ifconf...
主要为了弄清ifconfig命令是从哪儿读出errors的数量和内核在什么情况下才会增加errors的计数值了
直接回答清楚更好
先谢了,嫌分少可以再加。
直接回答清楚更好
先谢了,嫌分少可以再加。
|
想看errors的计数值如何产生的为什么要看ifconfig的源码,ifconfig是通过ioctl从内核读出来的,你要看内核的源码。
内核中有net_device的一个链表,每个节点是一个设备,其中保存了一个status的结构,里面记录了网口的各种数据,ifconfig显示的就是这个,然后你可以在内核的源码里面搜索errors计数的程序片断,可以看明白的。内核收到数据包之后,对sk_buf进行了处理。
内核中有net_device的一个链表,每个节点是一个设备,其中保存了一个status的结构,里面记录了网口的各种数据,ifconfig显示的就是这个,然后你可以在内核的源码里面搜索errors计数的程序片断,可以看明白的。内核收到数据包之后,对sk_buf进行了处理。
|
int ifconfig_main(int argc, char **argv)
{
struct ifreq ifr;
struct sockaddr_in sai;
#ifdef CONFIG_FEATURE_IPV6
struct sockaddr_in6 sai6;
#endif
#ifdef CONFIG_FEATURE_IFCONFIG_HW
struct sockaddr sa;
#endif
const struct arg1opt *a1op;
const struct options *op;
int sockfd; /* socket fd we use to manipulate stuff with */
int goterr;
int selector;
#ifdef CONFIG_FEATURE_IFCONFIG_BROADCAST_PLUS
unsigned int mask;
unsigned int did_flags;
unsigned int sai_hostname, sai_netmask;
#else
unsigned char mask;
unsigned char did_flags;
#endif
char *p;
char host[128];
goterr = 0;
did_flags = 0;
#ifdef CONFIG_FEATURE_IFCONFIG_BROADCAST_PLUS
sai_hostname = 0;
sai_netmask = 0;
#endif
/* skip argv[0] */
++argv;
--argc;
#ifdef CONFIG_FEATURE_IFCONFIG_STATUS
if ((argc > 0) && (((*argv)[0] == '-') && ((*argv)[1] == 'a') && !(*argv)[2])) {
interface_opt_a = 1;
--argc;
++argv;
}
#endif
if (argc name) == 0) { /* If name matches... */
if ((mask &= op->flags)) { /* set the mask and go. */
goto FOUND_ARG;;
}
/* If we get here, there was a valid arg with an */
/* invalid '-' prefix. */
++goterr;
goto LOOP;
}
}
/* We fell through, so treat as possible hostname. */
a1op = Arg1Opt + (sizeof(Arg1Opt) / sizeof(Arg1Opt[0])) - 1;
mask = op->arg_flags;
goto HOSTNAME;
FOUND_ARG:
if (mask & ARG_MASK) {
mask = op->arg_flags;
a1op = Arg1Opt + (op - OptArray);
if (mask & A_NETMASK & did_flags) {
bb_show_usage();
}
if (*++argv == NULL) {
if (mask & A_ARG_REQ) {
bb_show_usage();
} else {
--argv;
mask &= A_SET_AFTER; /* just for broadcast */
}
} else { /* got an arg so process it */
HOSTNAME:
did_flags |= (mask & (A_NETMASK|A_HOSTNAME));
if (mask & A_CAST_HOST_COPY) {
#ifdef CONFIG_FEATURE_IFCONFIG_HW
if (mask & A_CAST_RESOLVE) {
#endif
#ifdef CONFIG_FEATURE_IPV6
char *prefix;
int prefix_len = 0;
#endif
safe_strncpy(host, *argv, (sizeof host));
#ifdef CONFIG_FEATURE_IPV6
if ((prefix = strchr(host, '/'))) {
if (safe_strtoi(prefix + 1, &prefix_len) ||
(prefix_len 128))
{
++goterr;
goto LOOP;
}
*prefix = 0;
}
#endif
sai.sin_family = AF_INET;
sai.sin_port = 0;
if (!strcmp(host, bb_INET_default)) {
/* Default is special, meaning 0.0.0.0. */
sai.sin_addr.s_addr = INADDR_ANY;
#ifdef CONFIG_FEATURE_IFCONFIG_BROADCAST_PLUS
} else if (((host[0] == '+') && !host[1]) && (mask & A_BROADCAST) &&
(did_flags & (A_NETMASK|A_HOSTNAME)) == (A_NETMASK|A_HOSTNAME)) {
/* + is special, meaning broadcast is derived. */
sai.sin_addr.s_addr = (~sai_netmask) | (sai_hostname & sai_netmask);
#endif
#ifdef CONFIG_FEATURE_IPV6
} else if (inet_pton(AF_INET6, host, &sai6.sin6_addr) > 0) {
int sockfd6;
struct in6_ifreq ifr6;
memcpy((char *) &ifr6.ifr6_addr,
(char *) &sai6.sin6_addr,
sizeof(struct in6_addr));
/* Create a channel to the NET kernel. */
if ((sockfd6 = socket(AF_INET6, SOCK_DGRAM, 0))
{
struct ifreq ifr;
struct sockaddr_in sai;
#ifdef CONFIG_FEATURE_IPV6
struct sockaddr_in6 sai6;
#endif
#ifdef CONFIG_FEATURE_IFCONFIG_HW
struct sockaddr sa;
#endif
const struct arg1opt *a1op;
const struct options *op;
int sockfd; /* socket fd we use to manipulate stuff with */
int goterr;
int selector;
#ifdef CONFIG_FEATURE_IFCONFIG_BROADCAST_PLUS
unsigned int mask;
unsigned int did_flags;
unsigned int sai_hostname, sai_netmask;
#else
unsigned char mask;
unsigned char did_flags;
#endif
char *p;
char host[128];
goterr = 0;
did_flags = 0;
#ifdef CONFIG_FEATURE_IFCONFIG_BROADCAST_PLUS
sai_hostname = 0;
sai_netmask = 0;
#endif
/* skip argv[0] */
++argv;
--argc;
#ifdef CONFIG_FEATURE_IFCONFIG_STATUS
if ((argc > 0) && (((*argv)[0] == '-') && ((*argv)[1] == 'a') && !(*argv)[2])) {
interface_opt_a = 1;
--argc;
++argv;
}
#endif
if (argc name) == 0) { /* If name matches... */
if ((mask &= op->flags)) { /* set the mask and go. */
goto FOUND_ARG;;
}
/* If we get here, there was a valid arg with an */
/* invalid '-' prefix. */
++goterr;
goto LOOP;
}
}
/* We fell through, so treat as possible hostname. */
a1op = Arg1Opt + (sizeof(Arg1Opt) / sizeof(Arg1Opt[0])) - 1;
mask = op->arg_flags;
goto HOSTNAME;
FOUND_ARG:
if (mask & ARG_MASK) {
mask = op->arg_flags;
a1op = Arg1Opt + (op - OptArray);
if (mask & A_NETMASK & did_flags) {
bb_show_usage();
}
if (*++argv == NULL) {
if (mask & A_ARG_REQ) {
bb_show_usage();
} else {
--argv;
mask &= A_SET_AFTER; /* just for broadcast */
}
} else { /* got an arg so process it */
HOSTNAME:
did_flags |= (mask & (A_NETMASK|A_HOSTNAME));
if (mask & A_CAST_HOST_COPY) {
#ifdef CONFIG_FEATURE_IFCONFIG_HW
if (mask & A_CAST_RESOLVE) {
#endif
#ifdef CONFIG_FEATURE_IPV6
char *prefix;
int prefix_len = 0;
#endif
safe_strncpy(host, *argv, (sizeof host));
#ifdef CONFIG_FEATURE_IPV6
if ((prefix = strchr(host, '/'))) {
if (safe_strtoi(prefix + 1, &prefix_len) ||
(prefix_len 128))
{
++goterr;
goto LOOP;
}
*prefix = 0;
}
#endif
sai.sin_family = AF_INET;
sai.sin_port = 0;
if (!strcmp(host, bb_INET_default)) {
/* Default is special, meaning 0.0.0.0. */
sai.sin_addr.s_addr = INADDR_ANY;
#ifdef CONFIG_FEATURE_IFCONFIG_BROADCAST_PLUS
} else if (((host[0] == '+') && !host[1]) && (mask & A_BROADCAST) &&
(did_flags & (A_NETMASK|A_HOSTNAME)) == (A_NETMASK|A_HOSTNAME)) {
/* + is special, meaning broadcast is derived. */
sai.sin_addr.s_addr = (~sai_netmask) | (sai_hostname & sai_netmask);
#endif
#ifdef CONFIG_FEATURE_IPV6
} else if (inet_pton(AF_INET6, host, &sai6.sin6_addr) > 0) {
int sockfd6;
struct in6_ifreq ifr6;
memcpy((char *) &ifr6.ifr6_addr,
(char *) &sai6.sin6_addr,
sizeof(struct in6_addr));
/* Create a channel to the NET kernel. */
if ((sockfd6 = socket(AF_INET6, SOCK_DGRAM, 0))
您可能感兴趣的文章:
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
站内导航:
特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!