linux头文件如何编辑gcc代码

时间:2018-04-26 13:12:30

标签: linux gcc kernel

我的vm系统是ubuntu 16.04,我已下载内核头文件,我已编写代码,但不知道如何编辑gcc代码或Makefile

#include <linux/netdevice.h>
#include <stdio.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in.h>

int main(){
    struct net_device *dev = dev_base;
    struct in_device *mydevice;
    struct in_ifaddr *myifaddr;
    while( dev != NULL ){
        printf("dev name: %s\n", dev->name);
        mydevice = dev->ip_ptr;
        myifaddr = mydevice->ifa_list;
        while(myifaddr != NULL){
            printf("ip: %s\n", inet_ntoa((struct in_addr)(myifaddr->ifa_local)));
            myifaddr = myifaddr->ifa_next;
        }
        dev = dev->next;
    }
    return 0;
}

如果我使用gcc test.c,它会出现像这样的错误

yq@ubuntu:~/test$ gcc test.c 
In file included from /usr/include/linux/netdevice.h:28:0,
                 from test.c:1:
/usr/include/linux/if.h:234:19: error: field ‘ifru_addr’ has incomplete type
   struct sockaddr ifru_addr;
                   ^
......

test.c: In function ‘main’:
test.c:8:27: error: ‘dev_base’ undeclared (first use in this function)
  struct net_device *dev = dev_base;

0 个答案:

没有答案