Windows 7 缺少linux/if.h

Windows 7 缺少linux/if.h,windows-7,cygwin,Windows 7,Cygwin,你好,我在使用cygwin尝试 这是我的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

你好,我在使用cygwin尝试

这是我的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);
}
/*
*/
/*
*tun_dev.c,v 1.1.2.4 2001/09/13 05:02:22 maxk Exp
*/ 
/*#包括“config.h”*/
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括“vtun.h”
#包括“lib.h”
/* 
*分配TUN设备,返回打开的fd。
*将开发人员名称存储在第一个参数中(必须足够大)。
*/  
int tun_open_old(char*dev)
{
char tunname[14];
inti,fd;
如果(*dev){
sprintf(tunname,“/dev/%s”,dev);
返回打开(tunname,O_RDWR);
}
对于(i=0;i<255;i++){
sprintf(tunname,“/dev/tun%d”,i);
/*开放式设备*/
如果((fd=open(tunname,O_RDWR))>0){
sprintf(dev,“tun%d”,i);
返回fd;
}
}
返回-1;
}
#包括
/*2.4.6之前的兼容性*/
#定义otnocsum(('T'Try:

#包括

相反。

Cygwin!=Linux,所以
Linux/if.h
缺失也就不足为奇了……你为什么要在Ubuntu上使用Cygwin?你会怎么做呢?很抱歉没有在Ubuntu的windows 7上使用Cygwin。很抱歉,错误的标签给了我这个错误tun\u dev.c:65:24:致命错误:net/if\tun.h:没有终止这样的文件或目录编译。Makefile:15:目标'tun_dev.o'的配方生成失败:**[tun_dev.o]错误1很明显,您需要安装您试图构建的任何依赖项。您似乎没有这些依赖项。您试图构建的是什么?此->我正确构建了服务器,现在正在尝试在笔记本电脑上创建此依赖项,没有详细的自述文件need@MarkLinus答案确实解决了问题P的问题。
linux/if.h
是特定于linux的。正确的包含是
net/if.h
。这解决了问题中的特定错误消息。但后来发现问题并不是关于整个问题。您只需要在Cygwin中构建(或者不构建,从那里获取垃圾箱),因为此错误清楚地表明您缺少前面提到的unix特定标头。
#include <net/if.h>