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

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

?? ip_frag.c

?? ucos+lwip在44b0+8019開發(fā)板上跑得比較穩(wěn)定的程序。是ADS的工程
?? C
字號(hào):
/*
 * Copyright (c) 2001-2003 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. The name of the author may not be used to endorse or promote products
 *    derived from this software without specific prior written permission. 
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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 lwIP TCP/IP stack.
 * 
 * Author: Jani Monoses <jani@iv.ro> 
 * original reassembly code by Adam Dunkels <adam@sics.se>
 * 
 */

/*-----------------------------------------------------------------------------------*/
/* ip_frag.c
 *
 * This is the code for IP segmentation and reassembly
 *
 */
/*-----------------------------------------------------------------------------------*/

#include "lwip/opt.h"
#include "lwip/sys.h"
#include "lwip/ip.h"
#include "lwip/ip_frag.h"
#include "lwip/netif.h"

#include "lwip/stats.h"
//added by dy
#include <string.h>

/*
 * Copy len bytes from offset in pbuf to buffer 
 *
 * helper used by both ip_reass and ip_frag
 */
static struct pbuf *
copy_from_pbuf(struct pbuf *p, u16_t * offset,
				   u8_t * buffer, u16_t len)
{
  u16_t l;

  p->payload = (u8_t *)p->payload + *offset;
  p->len -= *offset;
  while (len) {
    l = len < p->len ? len : p->len;
    memcpy(buffer, p->payload, l);
    buffer += l;
    len -= l;
    if (len)
      p = p->next;
    else
      *offset = l;
  }
  return p;
}

#define IP_REASS_BUFSIZE 5760
#define IP_REASS_MAXAGE 30
#define IP_REASS_TMO 1000

static u8_t ip_reassbuf[IP_HLEN + IP_REASS_BUFSIZE];
static u8_t ip_reassbitmap[IP_REASS_BUFSIZE / (8 * 8)];
static const u8_t bitmap_bits[8] = { 0xff, 0x7f, 0x3f, 0x1f,
  0x0f, 0x07, 0x03, 0x01
};
static u16_t ip_reasslen;
static u8_t ip_reassflags;
#define IP_REASS_FLAG_LASTFRAG 0x01

static u8_t ip_reasstmr;

/* Reassembly timer */ 
static void 
ip_reass_timer(void *arg)
{
  if(ip_reasstmr > 1) {
    ip_reasstmr--;
    sys_timeout(IP_REASS_TMO, ip_reass_timer, NULL);
  } else if(ip_reasstmr == 1)
	ip_reasstmr = 0;
}

struct pbuf *
ip_reass(struct pbuf *p)
{
  struct pbuf *q;
  struct ip_hdr *fraghdr, *iphdr;
  u16_t offset, len;
  u16_t i;

#ifdef IP_STATS
  ++lwip_stats.ip_frag.recv;
#endif /* IP_STATS */

  iphdr = (struct ip_hdr *) ip_reassbuf;
  fraghdr = (struct ip_hdr *) p->payload;
  /* If ip_reasstmr is zero, no packet is present in the buffer, so we
     write the IP header of the fragment into the reassembly
     buffer. The timer is updated with the maximum age. */
  if (ip_reasstmr == 0) {
    DEBUGF(IP_REASS_DEBUG, ("ip_reass: new packet\n"));
    memcpy((void*)iphdr, (void*)fraghdr, IP_HLEN);
    ip_reasstmr = IP_REASS_MAXAGE;
    sys_timeout(IP_REASS_TMO, ip_reass_timer, NULL);
    ip_reassflags = 0;
    /* Clear the bitmap. */
    memset(ip_reassbitmap, 0, sizeof(ip_reassbitmap));
  }

  /* Check if the incoming fragment matches the one currently present
     in the reasembly buffer. If so, we proceed with copying the
     fragment into the buffer. */
  if (ip_addr_cmp(&iphdr->src, &fraghdr->src) &&
      ip_addr_cmp(&iphdr->dest, &fraghdr->dest) &&
      IPH_ID(iphdr) == IPH_ID(fraghdr)) {
    DEBUGF(IP_REASS_DEBUG, ("ip_reass: matching old packet\n"));
#ifdef IP_STATS
    ++lwip_stats.ip_frag.cachehit;
#endif /* IP_STATS */
    /* Find out the offset in the reassembly buffer where we should
       copy the fragment. */
    len = ntohs(IPH_LEN(fraghdr)) - IPH_HL(fraghdr) * 4;
    offset = (ntohs(IPH_OFFSET(fraghdr)) & IP_OFFMASK) * 8;

    /* If the offset or the offset + fragment length overflows the
       reassembly buffer, we discard the entire packet. */
    if (offset > IP_REASS_BUFSIZE || offset + len > IP_REASS_BUFSIZE) {
      DEBUGF(IP_REASS_DEBUG,
	     ("ip_reass: fragment outside of buffer (%d:%d/%d).\n", offset,
	      offset + len, IP_REASS_BUFSIZE));
      sys_untimeout(ip_reass_timer, NULL);
      ip_reasstmr = 0;
      goto nullreturn;
    }

    /* Copy the fragment into the reassembly buffer, at the right
       offset. */
    DEBUGF(IP_REASS_DEBUG,
	   ("ip_reass: copying with offset %d into %d:%d\n", offset,
	    IP_HLEN + offset, IP_HLEN + offset + len));
    i = IPH_HL(fraghdr) * 4;
    copy_from_pbuf(p, &i, &ip_reassbuf[IP_HLEN + offset], len);

    /* Update the bitmap. */
    if (offset / (8 * 8) == (offset + len) / (8 * 8)) {
      DEBUGF(IP_REASS_DEBUG,
	     ("ip_reass: updating single byte in bitmap.\n"));
      /* If the two endpoints are in the same byte, we only update
         that byte. */
      ip_reassbitmap[offset / (8 * 8)] |=
	  bitmap_bits[(offset / 8) & 7] &
	  ~bitmap_bits[((offset + len) / 8) & 7];
    } else {
      /* If the two endpoints are in different bytes, we update the
         bytes in the endpoints and fill the stuff inbetween with
         0xff. */
      ip_reassbitmap[offset / (8 * 8)] |= bitmap_bits[(offset / 8) & 7];
      DEBUGF(IP_REASS_DEBUG,
	     ("ip_reass: updating many bytes in bitmap (%d:%d).\n",
	      1 + offset / (8 * 8), (offset + len) / (8 * 8)));
      for (i = 1 + offset / (8 * 8); i < (offset + len) / (8 * 8); ++i) {
	ip_reassbitmap[i] = 0xff;
      }
      ip_reassbitmap[(offset + len) / (8 * 8)] |=
	  ~bitmap_bits[((offset + len) / 8) & 7];
    }

    /* If this fragment has the More Fragments flag set to zero, we
       know that this is the last fragment, so we can calculate the
       size of the entire packet. We also set the
       IP_REASS_FLAG_LASTFRAG flag to indicate that we have received
       the final fragment. */

    if ((ntohs(IPH_OFFSET(fraghdr)) & IP_MF) == 0) {
      ip_reassflags |= IP_REASS_FLAG_LASTFRAG;
      ip_reasslen = offset + len;
      DEBUGF(IP_REASS_DEBUG,
	     ("ip_reass: last fragment seen, total len %d\n",
	      ip_reasslen));
    }

    /* Finally, we check if we have a full packet in the buffer. We do
       this by checking if we have the last fragment and if all bits
       in the bitmap are set. */
    if (ip_reassflags & IP_REASS_FLAG_LASTFRAG) {
      /* Check all bytes up to and including all but the last byte in
         the bitmap. */
      for (i = 0; i < ip_reasslen / (8 * 8) - 1; ++i) {
	if (ip_reassbitmap[i] != 0xff) {
	  DEBUGF(IP_REASS_DEBUG,
		 ("ip_reass: last fragment seen, bitmap %d/%d failed (%x)\n",
		  i, ip_reasslen / (8 * 8) - 1, ip_reassbitmap[i]));
	  goto nullreturn;
	}
      }
      /* Check the last byte in the bitmap. It should contain just the
         right amount of bits. */
      if (ip_reassbitmap[ip_reasslen / (8 * 8)] !=
	  (u8_t) ~ bitmap_bits[ip_reasslen / 8 & 7]) {
	DEBUGF(IP_REASS_DEBUG,
	       ("ip_reass: last fragment seen, bitmap %d didn't contain %x (%x)\n",
		ip_reasslen / (8 * 8), ~bitmap_bits[ip_reasslen / 8 & 7],
		ip_reassbitmap[ip_reasslen / (8 * 8)]));
	goto nullreturn;
      }

      /* Pretend to be a "normal" (i.e., not fragmented) IP packet
         from now on. */
      ip_reasslen += IP_HLEN;

      IPH_LEN_SET(iphdr, htons(ip_reasslen));
      IPH_OFFSET_SET(iphdr, 0);
      IPH_CHKSUM_SET(iphdr, 0);
      IPH_CHKSUM_SET(iphdr, inet_chksum((void*)iphdr, IP_HLEN));

      /* If we have come this far, we have a full packet in the
         buffer, so we allocate a pbuf and copy the packet into it. We
         also reset the timer. */
      sys_untimeout(ip_reass_timer, NULL);
      ip_reasstmr = 0;
      pbuf_free(p);
      p = pbuf_alloc(PBUF_LINK, ip_reasslen, PBUF_POOL);
      if (p != NULL) {
	i = 0;
	for (q = p; q != NULL; q = q->next) {
	  /* Copy enough bytes to fill this pbuf in the chain. The
	     available data in the pbuf is given by the q->len
	     variable. */
	  DEBUGF(IP_REASS_DEBUG,
		 ("ip_reass: memcpy from %p (%d) to %p, %d bytes\n",
		  &ip_reassbuf[i], i, q->payload,
		  q->len > ip_reasslen - i ? ip_reasslen - i : q->len));
	  memcpy(q->payload, &ip_reassbuf[i],
		q->len > ip_reasslen - i ? ip_reasslen - i : q->len);
	  i += q->len;
	}
#ifdef IP_STATS
	++lwip_stats.ip_frag.fw;
#endif /* IP_STATS */
      } else {
#ifdef IP_STATS
	++lwip_stats.ip_frag.memerr;
#endif /* IP_STATS */
      }
      DEBUGF(IP_REASS_DEBUG, ("ip_reass: p %p\n", (void*)p));
      return p;
    }
  }

nullreturn:
#ifdef IP_STATS
  ++lwip_stats.ip_frag.drop;
#endif /* IP_STATS */
  pbuf_free(p);
  return NULL;
}

#define MAX_MTU 1500
static u8_t buf[MAX_MTU];

/**
 * Fragment an IP packet if too large
 *
 * Chop the packet in mtu sized chunks and send them in order
 * by using a fixed size static memory buffer (PBUF_ROM)
 */
err_t 
ip_frag(struct pbuf *p, struct netif *netif, struct ip_addr *dest)
{
  struct pbuf *rambuf;
  struct pbuf *header;
  struct ip_hdr *iphdr;
  u16_t nfb = 0;
  u16_t left, cop;
  u16_t mtu = netif->mtu;
  u16_t ofo, omf;
  u16_t last;
  u16_t poff = IP_HLEN;
  u16_t tmp;

  /* Get a RAM based MTU sized pbuf */
  rambuf = pbuf_alloc(PBUF_LINK, 0, PBUF_REF);
  rambuf->tot_len = rambuf->len = mtu;
  rambuf->payload = buf;


  /* Copy the IP header in it */
  iphdr = rambuf->payload;
  memcpy((void*)iphdr, p->payload, IP_HLEN);

  /* Save original offset */
  tmp = ntohs(IPH_OFFSET(iphdr));
  ofo = tmp & IP_OFFMASK;
  omf = tmp & IP_MF;

  left = p->tot_len - IP_HLEN;

  while (left) {
    last = (left <= mtu - IP_HLEN);

    /* Set new offset and MF flag */
    ofo += nfb;
    tmp = omf | (IP_OFFMASK & (ofo));
    if (!last)
      tmp = tmp | IP_MF;
    IPH_OFFSET_SET(iphdr, htons(tmp));

    /* Fill this fragment */
    nfb = (mtu - IP_HLEN) / 8;
    cop = last ? left : nfb * 8;

    p = copy_from_pbuf(p, &poff, (u8_t *) iphdr + IP_HLEN, cop);

    /* Correct header */
    IPH_LEN_SET(iphdr, htons(cop + IP_HLEN));
    IPH_CHKSUM_SET(iphdr, 0);
    IPH_CHKSUM_SET(iphdr, inet_chksum((void*)iphdr, IP_HLEN));

    if (last)
      pbuf_realloc(rambuf, left + IP_HLEN);
    /* This part is ugly: we alloc a RAM based pbuf for 
     * the link level header for each chunk and then 
     * free it.A PBUF_ROM style pbuf for which pbuf_header
     * worked would make things simpler.
     */
    header = pbuf_alloc(PBUF_LINK, 0, PBUF_RAM);
    pbuf_chain(header, rambuf);
    netif->output(netif, header, dest);
#ifdef IP_STATS
    ++lwip_stats.ip_frag.xmit;
#endif /* IP_STATS */
    pbuf_free(header);

    left -= cop;
  }
  pbuf_free(rambuf);
  return ERR_OK;
}

?? 快捷鍵說(shuō)明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號(hào) Ctrl + =
減小字號(hào) Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
免费成人性网站| 国产成人免费xxxxxxxx| 国产欧美日韩不卡| 欧美视频精品在线观看| 国产激情一区二区三区| 欧美a级一区二区| 亚洲综合无码一区二区| 国产精品免费久久| 欧美不卡一区二区| 欧美精品在欧美一区二区少妇| 成人午夜在线播放| 久久精品国产久精国产| 亚洲不卡在线观看| 一区二区三区成人| 日韩理论电影院| 久久久久成人黄色影片| 日韩一区二区在线播放| 欧美日韩视频专区在线播放| 91麻豆成人久久精品二区三区| 狠狠色丁香婷综合久久| 免费成人在线视频观看| 五月激情六月综合| 亚洲伦理在线精品| 亚洲人吸女人奶水| 亚洲素人一区二区| 国产精品三级av在线播放| 久久蜜桃av一区二区天堂 | 一本大道久久精品懂色aⅴ| 国产精品66部| 国产麻豆成人精品| 国产原创一区二区三区| 久久成人免费网站| 韩国av一区二区三区| 美国av一区二区| 奇米在线7777在线精品| 男男视频亚洲欧美| 蜜臀av一区二区在线免费观看| 婷婷夜色潮精品综合在线| 亚洲高清在线精品| 亚洲bt欧美bt精品| 日本美女一区二区三区视频| 日韩和欧美一区二区三区| 丝袜美腿亚洲一区二区图片| 日韩在线一区二区| 免费在线看成人av| 久久精品国产99国产| 精品一区二区久久久| 国产在线不卡一区| 国产精品夜夜嗨| 粉嫩高潮美女一区二区三区| www.av亚洲| 91看片淫黄大片一级在线观看| 91麻豆自制传媒国产之光| 色av综合在线| 欧美日韩精品欧美日韩精品| 日韩一区二区三区在线观看| 精品久久久三级丝袜| 国产网站一区二区三区| 国产精品久久免费看| 亚洲精品网站在线观看| 亚洲成a人v欧美综合天堂下载| 美腿丝袜亚洲一区| 国产一区二区三区免费在线观看| 国产99一区视频免费| 99精品1区2区| 欧美精品亚洲一区二区在线播放| 精品国产伦一区二区三区免费 | av激情成人网| 欧美亚洲动漫精品| 精品国产伦一区二区三区观看体验| 国产亚洲综合在线| 亚洲精品日韩一| 美女免费视频一区二区| 成人激情综合网站| 欧日韩精品视频| 精品久久久久一区| 亚洲精品免费视频| 麻豆精品视频在线| 色哟哟国产精品免费观看| 日韩亚洲欧美综合| 国产精品欧美综合在线| 午夜欧美一区二区三区在线播放| 九色综合国产一区二区三区| 99精品在线观看视频| 欧美一区二区日韩| 综合精品久久久| 久久99国产精品久久99果冻传媒| 成人h精品动漫一区二区三区| 在线电影欧美成精品| 国产女主播一区| 日本免费新一区视频| 99精品久久只有精品| 精品日韩在线观看| 亚洲综合一区二区三区| 国产精品白丝av| 欧美一区二区三区四区久久| 亚洲欧洲性图库| 狠狠色综合日日| 欧美人妖巨大在线| 亚洲日韩欧美一区二区在线| 国产一区二区伦理片| 欧美久久久久免费| 亚洲精品美腿丝袜| 成人av资源在线观看| 久久久久久久久久久99999| 日韩电影网1区2区| 日本道色综合久久| 中文一区二区在线观看| 久久99国产精品久久99果冻传媒| 欧美日韩在线不卡| 夜夜操天天操亚洲| 99久久精品国产精品久久| 国产性做久久久久久| 另类综合日韩欧美亚洲| 欧美日本免费一区二区三区| 亚洲狠狠丁香婷婷综合久久久| 国产乱码精品一区二区三区av| 欧美一区二区免费观在线| 亚洲国产成人av网| 欧美曰成人黄网| 亚洲免费在线视频| av日韩在线网站| 国产精品福利影院| zzijzzij亚洲日本少妇熟睡| 久久久www成人免费毛片麻豆| 九九九精品视频| 欧美大片一区二区三区| 日韩精品欧美成人高清一区二区| 欧美视频完全免费看| 亚洲成人黄色小说| 欧美日韩国产美女| 香蕉av福利精品导航| 欧美日韩不卡一区二区| 日韩精品乱码免费| 日韩一卡二卡三卡四卡| 麻豆一区二区三| 日韩精品一区二区三区视频在线观看| 日韩国产欧美在线观看| 日韩午夜精品视频| 国产一区三区三区| 国产日韩欧美综合在线| 国产成人在线视频网站| 国产精品福利一区| 欧洲生活片亚洲生活在线观看| 亚洲一区二区三区四区的| 欧美日韩二区三区| 免费成人小视频| 久久精品水蜜桃av综合天堂| 国产精品18久久久久久久网站| 中文字幕国产一区二区| 99国产欧美久久久精品| 亚洲午夜视频在线| 在线不卡欧美精品一区二区三区| 日韩精品三区四区| 久久久精品国产免费观看同学| 不卡的电影网站| 夜夜精品浪潮av一区二区三区| 欧美日韩成人激情| 国产一区二区三区不卡在线观看| 国产精品久久久久国产精品日日| 日本道精品一区二区三区| 奇米888四色在线精品| 国产亚洲精久久久久久| 色婷婷久久久综合中文字幕| 视频一区二区国产| 国产日韩三级在线| 欧美性淫爽ww久久久久无| 玖玖九九国产精品| 国产精品妹子av| 欧美精选午夜久久久乱码6080| 国产一区福利在线| 亚洲男人的天堂在线aⅴ视频| 欧美精品三级日韩久久| 成人一级黄色片| 亚洲成人免费电影| 国产欧美日韩一区二区三区在线观看 | 久久久久久一级片| 91在线观看成人| 免费高清不卡av| 亚洲少妇最新在线视频| 6080yy午夜一二三区久久| 成人网男人的天堂| 奇米777欧美一区二区| 亚洲欧美国产77777| 欧美变态tickle挠乳网站| 91在线视频网址| 韩国成人精品a∨在线观看| 亚洲精品成人少妇| 久久精品一区二区| 欧美乱妇一区二区三区不卡视频| 丁香一区二区三区| 美女视频免费一区| 一二三区精品视频| 国产精品对白交换视频| 欧美成人官网二区| 欧美日韩精品一区二区三区四区| 成人在线综合网| 韩国女主播成人在线观看| 亚洲高清不卡在线| 亚洲天堂2014|