免费注册 查看新帖 |

Chinaunix

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

新人问题-想要调用dev_get_by_name改怎么用呢? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-11-06 13:30 |只看该作者 |倒序浏览
我想用dev_get_by_name来看现在网卡的情况

好像不能用阿~~

请大家指点

我的代码:
#include <stdio.h>
#include <linux/netdevice.h>

#include <linux/if_vlan.h>


extern struct net_device *dev_get_by_name(struct net *net, const char *name);
#define VLAN_DEV_INFO(x) ((struct vlan_dev_info *)(x->priv))

int main()
{
        struct net_device *dev ={0};// NULL;
        struct net *net ={0};// NULL;
        //const char *vlan_IF_name = "eth0";
        int ret = 0;


        dev = dev_get_by_name(net, "eth0");//vlan_IF_name);
    ret = (int)dev;
        if (dev) {
                if (dev->priv_flags & IFF_802_1Q_VLAN) {
                       
                        printf("Features=%d\n",VLAN_DEV_INFO(dev)->real_dev->features);
                }
                else
                {
                        printf("ERROR:dev->priv_flags=%d\n",dev->priv_flags);
                }
        }
        else
        {
                printf("ERROR:Get name error\n");
        }
        dev_put(dev);

       
        return ret;
}

论坛徽章:
0
2 [报告]
发表于 2009-11-06 13:31 |只看该作者
报这些错:

In file included from /usr/include/linux/netdevice.h:28,
                 from test.cc:7:
/usr/include/linux/if.h:162: error: field 'ifru_addr' has incomplete type
/usr/include/linux/if.h:163: error: field 'ifru_dstaddr' has incomplete type
/usr/include/linux/if.h:164: error: field 'ifru_broadaddr' has incomplete type
/usr/include/linux/if.h:165: error: field 'ifru_netmask' has incomplete type
/usr/include/linux/if.h:166: error: field 'ifru_hwaddr' has incomplete type
test.cc: In function 'int main()':
test.cc:26: error: invalid use of incomplete type 'struct net_device'
test.cc:12: error: forward declaration of 'struct net_device'
test.cc:39: error: 'dev_put' was not declared in this scope
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP