⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tapif.c.rej

📁 lwIP-Softools-11Jul2002-alpha
💻 REJ
字号:
****************** 30,36 ****   *    * Author: Adam Dunkels <adam@sics.se>   *-  * $Id: tapif.c,v 1.1 2001/12/12 10:02:27 adam Exp $   */    #include <fcntl.h>--- 30,36 ----   *    * Author: Adam Dunkels <adam@sics.se>   *+  * $Id: tapif.c,v 1.9 2002/02/08 13:30:00 adam Exp $   */    #include <fcntl.h>****************** 47,62 ****    #include "lwip/opt.h"  #include "lwip/def.h"  #include "lwip/mem.h"  #include "lwip/pbuf.h"  #include "lwip/sys.h"    #include "netif/arp.h"    #define IFNAME0 't'  #define IFNAME1 'p'  - static const struct eth_addr ethbroadcast = {{0xffff,0xffff,0xffff}};    struct tapif {    struct eth_addr *ethaddr;--- 47,72 ----    #include "lwip/opt.h"  #include "lwip/def.h"+ #include "lwip/ip.h"  #include "lwip/mem.h"  #include "lwip/pbuf.h"  #include "lwip/sys.h"    #include "netif/arp.h"  + #ifdef linux+ #include <sys/ioctl.h>+ #include <linux/if.h>+ #include <linux/if_tun.h>+ #define DEVTAP "/dev/net/tun"+ #else  /* linux */+ #define DEVTAP "/dev/tap0"+ #endif /* linux */+   #define IFNAME0 't'  #define IFNAME1 'p'  + static const struct eth_addr ethbroadcast = {{0xff,0xff,0xff,0xff,0xff,0xff}};    struct tapif {    struct eth_addr *ethaddr;****************** 83,100 ****    /* Obtain MAC address from network interface. */      /* (We just fake an address...) */-   tapif->ethaddr->addr[0] = 0x01;-   tapif->ethaddr->addr[1] = 0x12;-   tapif->ethaddr->addr[2] = 0x23;      /* Do whatever else is needed to initialize interface. */    -   tapif->fd = open("/dev/tap0", O_RDWR);    DEBUGF(TAPIF_DEBUG, ("tapif_init: fd %d\n", tapif->fd));    if(tapif->fd == -1) {      perror("tapif_init");      exit(1);    }    snprintf(buf, sizeof(buf), "ifconfig tap0 inet %d.%d.%d.%d",             ip4_addr1(&(netif->gw)),             ip4_addr2(&(netif->gw)),--- 93,126 ----    /* Obtain MAC address from network interface. */      /* (We just fake an address...) */+   tapif->ethaddr->addr[0] = 0x1;+   tapif->ethaddr->addr[1] = 0x2;+   tapif->ethaddr->addr[2] = 0x3;+   tapif->ethaddr->addr[3] = 0x4;+   tapif->ethaddr->addr[4] = 0x5;+   tapif->ethaddr->addr[5] = 0x6;      /* Do whatever else is needed to initialize interface. */    +   tapif->fd = open(DEVTAP, O_RDWR);    DEBUGF(TAPIF_DEBUG, ("tapif_init: fd %d\n", tapif->fd));    if(tapif->fd == -1) {      perror("tapif_init");      exit(1);    }+ + #ifdef linux+   {+     struct ifreq ifr;+     memset(&ifr, 0, sizeof(ifr));+     ifr.ifr_flags = IFF_TAP|IFF_NO_PI;+     if (ioctl(tapif->fd, TUNSETIFF, (void *) &ifr) < 0) {+       perror(buf);+       exit(1);+     }+   }+ #endif /* Linux */+     snprintf(buf, sizeof(buf), "ifconfig tap0 inet %d.%d.%d.%d",             ip4_addr1(&(netif->gw)),             ip4_addr2(&(netif->gw)),****************** 265,275 ****      dest = (struct eth_addr *)&ethbroadcast;    } else if(ip_addr_ismulticast(ipaddr)) {      /* Hash IP multicast address to MAC address. */-     mcastaddr.addr[0] = HTONS(0x01 << 8);-     mcastaddr.addr[1] = HTONS((0x5e << 8) |- 			      (ip4_addr2(ipaddr) & 0x7f));-     mcastaddr.addr[2] = HTONS((ip4_addr3(ipaddr) << 8) |- 			      ip4_addr4(ipaddr));      dest = &mcastaddr;    } else {      if(ip_addr_maskcmp(ipaddr, &(netif->ip_addr), &(netif->netmask))) {--- 291,302 ----      dest = (struct eth_addr *)&ethbroadcast;    } else if(ip_addr_ismulticast(ipaddr)) {      /* Hash IP multicast address to MAC address. */+     mcastaddr.addr[0] = 0x01;+     mcastaddr.addr[1] = 0x0;+     mcastaddr.addr[2] = 0x5e;+     mcastaddr.addr[3] = ip4_addr2(ipaddr) & 0x7f;+     mcastaddr.addr[4] = ip4_addr3(ipaddr);+     mcastaddr.addr[5] = ip4_addr4(ipaddr);      dest = &mcastaddr;    } else {      if(ip_addr_maskcmp(ipaddr, &(netif->ip_addr), &(netif->netmask))) {****************** 299,305 ****    }    ethhdr = p->payload;    -   for(i = 0; i < 3; i++) {      ethhdr->dest.addr[i] = dest->addr[i];      ethhdr->src.addr[i] = tapif->ethaddr->addr[i];    }--- 326,332 ----    }    ethhdr = p->payload;    +   for(i = 0; i < 6; i++) {      ethhdr->dest.addr[i] = dest->addr[i];      ethhdr->src.addr[i] = tapif->ethaddr->addr[i];    }****************** 343,349 ****      DEBUGF(TAPIF_DEBUG, ("tapif_input: IP packet\n"));      arp_ip_input(netif, p);      pbuf_header(p, -14);-     netif->input(p, netif);      break;    case ETHTYPE_ARP:      DEBUGF(TAPIF_DEBUG, ("tapif_input: ARP packet\n"));--- 370,380 ----      DEBUGF(TAPIF_DEBUG, ("tapif_input: IP packet\n"));      arp_ip_input(netif, p);      pbuf_header(p, -14);+     if(ip_lookup(p->payload, netif)) {+       netif->input(p, netif);+     } else {+       printf("tapif_input: lookup failed!\n");+     }      break;    case ETHTYPE_ARP:      DEBUGF(TAPIF_DEBUG, ("tapif_input: ARP packet\n"));****************** 417,426 ****    netif->name[0] = IFNAME0;    netif->name[1] = IFNAME1;    netif->output = tapif_output;        tapif->ethaddr = (struct eth_addr *)&(netif->hwaddr[0]);        low_level_init(netif);-   arp_init();    }  /*-----------------------------------------------------------------------------------*/--- 455,467 ----    netif->name[0] = IFNAME0;    netif->name[1] = IFNAME1;    netif->output = tapif_output;+   netif->linkoutput = low_level_output;        tapif->ethaddr = (struct eth_addr *)&(netif->hwaddr[0]);        low_level_init(netif);+   arp_init();+   +   sys_timeout(ARP_TMR_INTERVAL, (sys_timeout_handler)arp_timer, NULL);  }  /*-----------------------------------------------------------------------------------*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -