2012-10-22 51 views
0

你好,我用的cygwin的時候儘量讓我得到這個錯誤,缺少Linux/if.h中

這是我的makefile

flags=-g 

all: icmptx 

icmptx: it.o icmptx.o tun_dev.o 
    gcc $(flags) -o icmptx icmptx.o it.o tun_dev.o 

it.o: it.c 
    gcc $(flags) -c it.c 

icmptx.o: icmptx.c 
    gcc $(flags) -c icmptx.c 

tun_dev.o: tun_dev.c 
    gcc $(flags) -c tun_dev.c 

clean: 
    rm -f tun_dev.o it.o icmptx.o icmptx 

誤差

$ make 
gcc -g -c tun_dev.c 
tun_dev.c:35:22: fatal error: linux/if.h: No such file or directory 
compilation terminated. 
Makefile:15: recipe for target `tun_dev.o' failed 
make: *** [tun_dev.o] Error 1 

這裏我的tun_dev.c文件

/* 

*/ 

/* 
* tun_dev.c,v 1.1.2.4 2001/09/13 05:02:22 maxk Exp 
*/ 

/* #include "config.h" */ 

#include <unistd.h> 
#include <fcntl.h> 
#include <stdlib.h> 
#include <stdio.h> 
#include <string.h> 
#include <syslog.h> 
#include <errno.h> 

#include <sys/ioctl.h> 
#include <sys/socket.h> 
#include <linux/if.h> 

#include "vtun.h" 
#include "lib.h" 

/* 
* Allocate TUN device, returns opened fd. 
* Stores dev name in the first arg(must be large enough). 
*/ 
int tun_open_old(char *dev) 
{ 
    char tunname[14]; 
    int i, fd; 

    if(*dev) { 
     sprintf(tunname, "/dev/%s", dev); 
     return open(tunname, O_RDWR); 
    } 

    for(i=0; i < 255; i++){ 
     sprintf(tunname, "/dev/tun%d", i); 
     /* Open device */ 
     if((fd=open(tunname, O_RDWR)) > 0){ 
      sprintf(dev, "tun%d", i); 
      return fd; 
     } 
    } 
    return -1; 
} 

#include <linux/if_tun.h> 

/* pre 2.4.6 compatibility */ 
#define OTUNSETNOCSUM (('T'<< 8) | 200) 
#define OTUNSETDEBUG (('T'<< 8) | 201) 
#define OTUNSETIFF  (('T'<< 8) | 202) 
#define OTUNSETPERSIST (('T'<< 8) | 203) 
#define OTUNSETOWNER (('T'<< 8) | 204) 

int tun_open(char *dev) 
{ 
    struct ifreq ifr; 
    int fd; 

    if ((fd = open("/dev/net/tun", O_RDWR)) < 0) 
     return tun_open_old(dev); 

    memset(&ifr, 0, sizeof(ifr)); 
    ifr.ifr_flags = IFF_TUN | IFF_NO_PI; 
    if (*dev) 
     strncpy(ifr.ifr_name, dev, IFNAMSIZ); 

    if (ioctl(fd, TUNSETIFF, (void *) &ifr) < 0) { 
     if (errno == EBADFD) { 
     /* Try old ioctl */ 
     if (ioctl(fd, OTUNSETIFF, (void *) &ifr) < 0) 
     goto failed; 
     } else 
      goto failed; 
    } 

    strcpy(dev, ifr.ifr_name); 
    return fd; 

failed: 
    close(fd); 
    return -1; 
} 

int tun_close(int fd, char *dev) 
{ 
    return close(fd); 
} 

/* Read/write frames from TUN device */ 
int tun_write(int fd, char *buf, int len) 
{ 
    return write(fd, buf, len); 
} 

int tun_read(int fd, char *buf, int len) 
{ 
    return read(fd, buf, len); 
} 

任何想法,goog文件顯示什麼

+0

Cygwin的!= Linux的,所以這並不奇怪,'LINUX/if.h'丟失...... – nneonneo

+0

爲什麼你會在Ubuntu上使用Cygwin?你怎麼做呢? –

+0

抱歉,不使用的cygwin在Ubuntu上它的Windows 7對不起錯標籤 –

回答

0

嘗試:

#include <net/if.h> 

代替。

+0

給了我這個錯誤tun_dev.c:65:24:致命錯誤:網/ if_tun.h:沒有這樣的文件或目錄彙編終止。的Makefile:15:配方目標'tun_dev.o」失敗化妝:*** [tun_dev.o]錯誤1 –

+0

顯然,你需要安裝的依賴無論它是你想建立。看來你沒有他們。 *你試圖建立什麼? –

+0

這 - > http://thomer.com/icmptx/我建立正確的服務器,我現在試圖讓這對我的筆記本電腦,目前還沒有詳細自述哪些依賴,我需要 –