亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? uip-fw.c

?? MCS-51的一個(gè)Free小型操作系統(tǒng),在KeilC中下編譯工作
?? C
字號(hào):
/*
 * Copyright (c) 2004, Swedish Institute of Computer Science.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. Neither the name of the Institute nor the names of its contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 * This file is part of the uIP TCP/IP stack
 *
 * Author: Adam Dunkels <adam@sics.se>
 *
 * $Id: uip-fw.c,v 1.2 2006/06/12 08:00:30 adam Exp $
 */
/**
 * \addtogroup uip
 * @{
 */

/**
 * \defgroup uipfw uIP packet forwarding
 * @{
 *
 */

/**
 * \file
 * uIP packet forwarding.
 * \author Adam Dunkels <adam@sics.se>
 *
 * This file implements a number of simple functions which do packet
 * forwarding over multiple network interfaces with uIP.
 *
 */

#include "uip.h"
#include "uip_arch.h"
#include "uip-fw.h"

#include <string.h> /* for memcpy() */

/*
 * The list of registered network interfaces.
 */
static struct uip_fw_netif *netifs = NULL;

/*
 * A pointer to the default network interface.
 */
static struct uip_fw_netif *defaultnetif = NULL;

struct tcpip_hdr {
  /* IP header. */
  u8_t vhl,
    tos;
  u16_t len,
    ipid,
    ipoffset;
  u8_t ttl,
    proto;
  u16_t ipchksum;
  u16_t srcipaddr[2],
    destipaddr[2];
  
  /* TCP header. */
  u16_t srcport,
    destport;
  u8_t seqno[4],
    ackno[4],
    tcpoffset,
    flags,
    wnd[2];
  u16_t tcpchksum;
  u8_t urgp[2];
  u8_t optdata[4];
};

struct icmpip_hdr {
  /* IP header. */
  u8_t vhl,
    tos,
    len[2],
    ipid[2],
    ipoffset[2],
    ttl,
    proto;
  u16_t ipchksum;
  u16_t srcipaddr[2],
    destipaddr[2];
  /* ICMP (echo) header. */
  u8_t type, icode;
  u16_t icmpchksum;
  u16_t id, seqno;
  u8_t payload[1];
};

/* ICMP ECHO. */
#define ICMP_ECHO 8

/* ICMP TIME-EXCEEDED. */
#define ICMP_TE 11

/*
 * Pointer to the TCP/IP headers of the packet in the uip_buf buffer.
 */
#define BUF ((struct tcpip_hdr *)&uip_buf[UIP_LLH_LEN])

/*
 * Pointer to the ICMP/IP headers of the packet in the uip_buf buffer.
 */
#define ICMPBUF ((struct icmpip_hdr *)&uip_buf[UIP_LLH_LEN])

/*
 * Certain fields of an IP packet that are used for identifying
 * duplicate packets.
 */
struct fwcache_entry {
  u16_t timer;
  
  u16_t srcipaddr[2];
  u16_t destipaddr[2];
  u16_t ipid;
  u8_t proto;
  u8_t unused;

#if notdef
  u16_t payload[2];
#endif

#if UIP_REASSEMBLY > 0
  u16_t len, offset;
#endif
};

/*
 * The number of packets to remember when looking for duplicates.
 */
#ifdef UIP_CONF_FWCACHE_SIZE
#define FWCACHE_SIZE UIP_CONF_FWCACHE_SIZE
#else
#define FWCACHE_SIZE 2
#endif


/*
 * A cache of packet header fields which are used for
 * identifying duplicate packets.
 */
static struct fwcache_entry fwcache[FWCACHE_SIZE];

/**
 * \internal
 * The time that a packet cache is active.
 */
#define FW_TIME 20

/*------------------------------------------------------------------------------*/
/**
 * Initialize the uIP packet forwarding module.
 */
/*------------------------------------------------------------------------------*/
void
uip_fw_init(void)
{
  struct uip_fw_netif *t;
  defaultnetif = NULL;
  while(netifs != NULL) {
    t = netifs;
    netifs = netifs->next;
    t->next = NULL;
  }
}
/*------------------------------------------------------------------------------*/
/**
 * \internal
 * Check if an IP address is within the network defined by an IP
 * address and a netmask.
 *
 * \param ipaddr The IP address to be checked.
 * \param netipaddr The IP address of the network.
 * \param netmask The netmask of the network.
 *
 * \return Non-zero if IP address is in network, zero otherwise.
 */
/*------------------------------------------------------------------------------*/
static unsigned char
ipaddr_maskcmp(u16_t *ipaddr, u16_t *netipaddr, u16_t *netmask)
{
  return (ipaddr[0] & netmask [0]) == (netipaddr[0] & netmask[0]) &&
    (ipaddr[1] & netmask[1]) == (netipaddr[1] & netmask[1]);
}
/*------------------------------------------------------------------------------*/
/**
 * \internal
 * Send out an ICMP TIME-EXCEEDED message.
 *
 * This function replaces the packet in the uip_buf buffer with the
 * ICMP packet.
 */
/*------------------------------------------------------------------------------*/
static void
time_exceeded(void)
{
  u16_t tmp16;

  /* We don't send out ICMP errors for ICMP messages. */
  if(ICMPBUF->proto == UIP_PROTO_ICMP) {
    uip_len = 0;
    return;
  }
  /* Copy fields from packet header into payload of this ICMP packet. */
  memcpy(&(ICMPBUF->payload[0]), ICMPBUF, 28);

  /* Set the ICMP type and code. */
  ICMPBUF->type = ICMP_TE;
  ICMPBUF->icode = 0;

  /* Calculate the ICMP checksum. */
  ICMPBUF->icmpchksum = 0;
  ICMPBUF->icmpchksum = ~uip_chksum((u16_t *)&(ICMPBUF->type), 36);

  /* Set the IP destination address to be the source address of the
     original packet. */
  tmp16= BUF->destipaddr[0];
  BUF->destipaddr[0] = BUF->srcipaddr[0];
  BUF->srcipaddr[0] = tmp16;
  tmp16 = BUF->destipaddr[1];
  BUF->destipaddr[1] = BUF->srcipaddr[1];
  BUF->srcipaddr[1] = tmp16;

  /* Set our IP address as the source address. */
  BUF->srcipaddr[0] = uip_hostaddr[0];
  BUF->srcipaddr[1] = uip_hostaddr[1];

  /* The size of the ICMP time exceeded packet is 36 + the size of the
     IP header (20) = 56. */
  uip_len = 56;
  ICMPBUF->len[0] = 0;
  ICMPBUF->len[1] = uip_len;

  /* Fill in the other fields in the IP header. */
  ICMPBUF->vhl = 0x45;
  ICMPBUF->tos = 0;
  ICMPBUF->ipoffset[0] = ICMPBUF->ipoffset[1] = 0;
  ICMPBUF->ttl  = UIP_TTL;
  ICMPBUF->proto = UIP_PROTO_ICMP;
  
  /* Calculate IP checksum. */
  ICMPBUF->ipchksum = 0;
  ICMPBUF->ipchksum = ~(uip_ipchksum());


}
/*------------------------------------------------------------------------------*/
/**
 * \internal
 * Register a packet in the forwarding cache so that it won't be
 * forwarded again.
 */
/*------------------------------------------------------------------------------*/
static void
fwcache_register(void)
{
  struct fwcache_entry *fw;
  int i, oldest;

  oldest = FW_TIME;
  fw = NULL;
  
  /* Find the oldest entry in the cache. */
  for(i = 0; i < FWCACHE_SIZE; ++i) {
    if(fwcache[i].timer == 0) {
      fw = &fwcache[i];
      break;
    } else if(fwcache[i].timer <= oldest) {
      fw = &fwcache[i];
      oldest = fwcache[i].timer;
    }
  }

  fw->timer = FW_TIME;
  fw->ipid = BUF->ipid;
  fw->srcipaddr[0] = BUF->srcipaddr[0];
  fw->srcipaddr[1] = BUF->srcipaddr[1];
  fw->destipaddr[0] = BUF->destipaddr[0];
  fw->destipaddr[1] = BUF->destipaddr[1];
  fw->proto = BUF->proto;
#if notdef
  fw->payload[0] = BUF->srcport;
  fw->payload[1] = BUF->destport;
#endif
#if UIP_REASSEMBLY > 0
  fw->len = BUF->len;
  fw->offset = BUF->ipoffset;
#endif
}
/*------------------------------------------------------------------------------*/
/**
 * \internal
 * Find a network interface for the IP packet in uip_buf.
 */
/*------------------------------------------------------------------------------*/
static struct uip_fw_netif *
find_netif(void)
{
  struct uip_fw_netif *netif;
  
  /* Walk through every network interface to check for a match. */
  for(netif = netifs; netif != NULL; netif = netif->next) {
    if(ipaddr_maskcmp(BUF->destipaddr, netif->ipaddr,
		      netif->netmask)) {
      /* If there was a match, we break the loop. */
      return netif;
    }
  }
  
  /* If no matching netif was found, we use default netif. */
  return defaultnetif;
}
/*------------------------------------------------------------------------------*/
/**
 * Output an IP packet on the correct network interface.
 *
 * The IP packet should be present in the uip_buf buffer and its
 * length in the global uip_len variable.
 *
 * \retval UIP_FW_ZEROLEN Indicates that a zero-length packet
 * transmission was attempted and that no packet was sent.
 *
 * \retval UIP_FW_NOROUTE No suitable network interface could be found
 * for the outbound packet, and the packet was not sent.
 *
 * \return The return value from the actual network interface output
 * function is passed unmodified as a return value.
 */
/*------------------------------------------------------------------------------*/
u8_t
uip_fw_output(void)
{
  struct uip_fw_netif *netif;

  if(uip_len == 0) {
    return UIP_FW_ZEROLEN;
  }

  fwcache_register();

#if UIP_BROADCAST
  /* Link local broadcasts go out on all interfaces. */
  if(/*BUF->proto == UIP_PROTO_UDP &&*/
     BUF->destipaddr[0] == 0xffff &&
     BUF->destipaddr[1] == 0xffff) {
    if(defaultnetif != NULL) {
      defaultnetif->output();
    }
    for(netif = netifs; netif != NULL; netif = netif->next) {
      netif->output();
    }
    return UIP_FW_OK;
  }
#endif /* UIP_BROADCAST */
  
  netif = find_netif();
  /*  printf("uip_fw_output: netif %p ->output %p len %d\n", netif,
	 netif->output,
	 uip_len);*/

  if(netif == NULL) {
    return UIP_FW_NOROUTE;
  }
  /* If we now have found a suitable network interface, we call its
     output function to send out the packet. */
  return netif->output();
}
/*------------------------------------------------------------------------------*/
/**
 * Forward an IP packet in the uip_buf buffer.
 *
 *
 *
 * \return UIP_FW_FORWARDED if the packet was forwarded, UIP_FW_LOCAL if
 * the packet should be processed locally.
 */
/*------------------------------------------------------------------------------*/
u8_t
uip_fw_forward(void)
{
  struct fwcache_entry *fw;

  /* First check if the packet is destined for ourselves and return 0
     to indicate that the packet should be processed locally. */
  if(BUF->destipaddr[0] == uip_hostaddr[0] &&
     BUF->destipaddr[1] == uip_hostaddr[1]) {
    return UIP_FW_LOCAL;
  }

  /* If we use ping IP address configuration, and our IP address is
     not yet configured, we should intercept all ICMP echo packets. */
#if UIP_PINGADDRCONF
  if((uip_hostaddr[0] | uip_hostaddr[1]) == 0 &&
     BUF->proto == UIP_PROTO_ICMP &&
     ICMPBUF->type == ICMP_ECHO) {
    return UIP_FW_LOCAL;
  }
#endif /* UIP_PINGADDRCONF */

  /* Check if the packet is in the forwarding cache already, and if so
     we drop it. */

  for(fw = fwcache; fw < &fwcache[FWCACHE_SIZE]; ++fw) {
    if(fw->timer != 0 &&
#if UIP_REASSEMBLY > 0
       fw->len == BUF->len &&
       fw->offset == BUF->ipoffset &&
#endif
       fw->ipid == BUF->ipid &&
       fw->srcipaddr[0] == BUF->srcipaddr[0] &&
       fw->srcipaddr[1] == BUF->srcipaddr[1] &&
       fw->destipaddr[0] == BUF->destipaddr[0] &&
       fw->destipaddr[1] == BUF->destipaddr[1] &&
#if notdef
       fw->payload[0] == BUF->srcport &&
       fw->payload[1] == BUF->destport &&
#endif
       fw->proto == BUF->proto) {
      /* Drop packet. */
      return UIP_FW_FORWARDED;
    }
  }

  /* If the TTL reaches zero we produce an ICMP time exceeded message
     in the uip_buf buffer and forward that packet back to the sender
     of the packet. */
  if(BUF->ttl <= 1) {
    /* No time exceeded for broadcasts and multicasts! */
    if(BUF->destipaddr[0] == 0xffff && BUF->destipaddr[1] == 0xffff) {
      return UIP_FW_LOCAL;
    }
    time_exceeded();
  }
  
  /* Decrement the TTL (time-to-live) value in the IP header */
  BUF->ttl = BUF->ttl - 1;
  
  /* Update the IP checksum. */
  if(BUF->ipchksum >= HTONS(0xffff - 0x0100)) {
    BUF->ipchksum = BUF->ipchksum + HTONS(0x0100) + 1;
  } else {
    BUF->ipchksum = BUF->ipchksum + HTONS(0x0100);
  }

  if(uip_len > 0) {
    uip_appdata = &uip_buf[UIP_LLH_LEN + UIP_TCPIP_HLEN];
    uip_fw_output();
  }

#if UIP_BROADCAST
  if(BUF->destipaddr[0] == 0xffff && BUF->destipaddr[1] == 0xffff) {
    return UIP_FW_LOCAL;
  }
#endif /* UIP_BROADCAST */

  /* Return non-zero to indicate that the packet was forwarded and that no
     other processing should be made. */
  return UIP_FW_FORWARDED;
}
/*------------------------------------------------------------------------------*/
/**
 * Register a network interface with the forwarding module.
 *
 * \param netif A pointer to the network interface that is to be
 * registered.
 */
/*------------------------------------------------------------------------------*/
void
uip_fw_register(struct uip_fw_netif *netif)
{
  netif->next = netifs;
  netifs = netif;
}
/*------------------------------------------------------------------------------*/
/**
 * Register a default network interface.
 *
 * All packets that don't go out on any of the other interfaces will
 * be routed to the default interface.
 *
 * \param netif A pointer to the network interface that is to be
 * registered.
 */
/*------------------------------------------------------------------------------*/
void
uip_fw_default(struct uip_fw_netif *netif)
{
  defaultnetif = netif;
}
/*------------------------------------------------------------------------------*/
/**
 * Perform periodic processing.
 */
/*------------------------------------------------------------------------------*/
void
uip_fw_periodic(void)
{
  struct fwcache_entry *fw;
  for(fw = fwcache; fw < &fwcache[FWCACHE_SIZE]; ++fw) {
    if(fw->timer > 0) {
      --fw->timer;
    }
  }
}
/*------------------------------------------------------------------------------*/

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號(hào) Ctrl + =
減小字號(hào) Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
日本一区中文字幕| 久久99深爱久久99精品| 国产suv精品一区二区883| 欧美色视频在线| 国产精品久久久一区麻豆最新章节| 日韩在线一区二区| www.亚洲精品| 欧美精品一区二| 亚洲国产视频直播| 99国产精品久| 久久久久久久久久久久电影| 无码av中文一区二区三区桃花岛| 91同城在线观看| 国产欧美日韩精品一区| 精品一区二区三区在线视频| 欧美日韩久久久久久| 中文字幕中文字幕中文字幕亚洲无线| 精品综合久久久久久8888| 欧美天天综合网| 亚洲你懂的在线视频| 丁香亚洲综合激情啪啪综合| 2020国产精品自拍| 久久精工是国产品牌吗| 日韩一级视频免费观看在线| 亚洲国产视频一区二区| 91成人看片片| 亚洲精品国产精华液| 99久久久久免费精品国产| 中文字幕av在线一区二区三区| 国产一区二区网址| 亚洲精品一区二区三区精华液 | 亚洲欧洲www| 国产很黄免费观看久久| 精品99一区二区三区| 麻豆精品国产91久久久久久| 欧美日韩国产成人在线免费| 亚洲成人自拍网| 欧美日韩免费在线视频| 一区二区在线观看免费视频播放| 91同城在线观看| 亚洲女人的天堂| 欧美在线|欧美| 五月天欧美精品| 欧美精品乱码久久久久久按摩| 午夜精品福利久久久| 欧美精品 日韩| 免费高清视频精品| 欧美xingq一区二区| 看电视剧不卡顿的网站| 欧美成人午夜电影| 国产九色sp调教91| 欧美经典一区二区三区| 成人免费高清视频在线观看| 综合久久久久久久| 日本韩国欧美在线| 午夜一区二区三区视频| 911精品国产一区二区在线| 热久久久久久久| 久久蜜臀中文字幕| 成人黄色软件下载| 一区二区三区在线播| 欧美日韩第一区日日骚| 蜜臀av在线播放一区二区三区| 欧美精品一区二区三区视频| 国产福利91精品一区二区三区| 国产精品污污网站在线观看| 色综合视频在线观看| 亚洲风情在线资源站| 日韩亚洲欧美在线| 国产精品亚洲午夜一区二区三区| 国产精品国产三级国产aⅴ无密码 国产精品国产三级国产aⅴ原创 | 亚洲黄色av一区| 欧美精品第1页| 韩国女主播成人在线| 综合久久综合久久| 欧美美女激情18p| 国产麻豆成人精品| 亚洲男人的天堂av| 91精品国产一区二区| 国产一区二区伦理片| 最新国产の精品合集bt伙计| 欧美久久一区二区| 国内精品在线播放| 亚洲精选在线视频| 日韩一区二区三区视频| 成人毛片在线观看| 亚洲va韩国va欧美va| 久久亚洲二区三区| 色综合天天综合在线视频| 免费成人在线观看视频| 欧美韩日一区二区三区| 欧美日韩亚洲国产综合| 国产精品一区二区不卡| 亚洲国产视频a| 久久精品夜夜夜夜久久| 欧美亚洲一区二区三区四区| 精品在线免费视频| 一区二区久久久久久| 久久亚洲精华国产精华液 | 精品亚洲aⅴ乱码一区二区三区| 国产精品乱人伦| 91精品国产手机| 91亚洲男人天堂| 韩日欧美一区二区三区| 一区二区久久久久久| 国产日韩一级二级三级| 在线电影欧美成精品| 99久久伊人精品| 国产揄拍国内精品对白| 亚洲国产cao| 国产精品久久久久久久久久免费看| 制服丝袜亚洲网站| 色综合天天做天天爱| 国产高清不卡二三区| 美女www一区二区| 亚洲第四色夜色| 亚洲欧洲成人精品av97| 久久只精品国产| 欧美一区二区精美| 在线观看视频91| www.99精品| 国产麻豆精品视频| 免费在线观看一区二区三区| 一区二区三区久久| 中文字幕一区二区三区四区不卡| 久久蜜臀中文字幕| 欧美一区二区三区系列电影| 欧美性一区二区| 99re亚洲国产精品| 国产99久久久国产精品潘金| 久久av老司机精品网站导航| 日本欧美一区二区在线观看| 亚洲伊人伊色伊影伊综合网| 成人欧美一区二区三区白人| 久久精品人人爽人人爽| 欧美成人a视频| 日韩精品中午字幕| 欧美一区二区三区系列电影| 欧美丰满一区二区免费视频| 91国产精品成人| 色噜噜狠狠色综合中国| 99精品久久久久久| www.亚洲激情.com| www.在线成人| www.日本不卡| 成人黄色电影在线| 成人小视频免费观看| 粉嫩高潮美女一区二区三区| 国产一区二区91| 国产一区二区在线影院| 国产最新精品精品你懂的| 激情成人午夜视频| 极品少妇xxxx精品少妇| 精品系列免费在线观看| 蜜臀a∨国产成人精品| 美女免费视频一区| 经典三级视频一区| 国产精品一线二线三线精华| 国产一区二区h| 成人免费毛片app| 91在线观看美女| 色婷婷久久综合| 精品视频在线免费| 91精品国产一区二区三区香蕉| 91精品国产日韩91久久久久久| 制服丝袜亚洲精品中文字幕| 欧美成人官网二区| 久久久久国产精品人| 国产免费成人在线视频| 国产精品人妖ts系列视频| 亚洲欧洲综合另类| 亚洲妇女屁股眼交7| 日本免费新一区视频| 精品亚洲porn| 成人教育av在线| 欧美综合色免费| 欧美一级片在线| 久久久国产一区二区三区四区小说| 日本一区二区三区免费乱视频| 国产精品久久综合| 亚洲一区免费视频| 免费日本视频一区| 国产麻豆日韩欧美久久| 99国产精品国产精品毛片| 欧美视频第二页| 日韩欧美第一区| 国产精品精品国产色婷婷| 亚洲一区二区三区影院| 看电视剧不卡顿的网站| 成人毛片在线观看| 欧美色网一区二区| 精品成人在线观看| 18成人在线观看| 丝袜美腿亚洲色图| 国产一区二区中文字幕| 91香蕉视频污| 日韩欧美中文字幕精品| 国产精品精品国产色婷婷| 首页欧美精品中文字幕| 国产一区二区不卡在线|