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

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? ip_frag.c

?? ARM7的一些試驗程序
?? C
字號:
/* @file
 * 
 * This is the IP packet segmentation and reassembly implementation.
 *
 */

/*
 * Copyright (c) 2001-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. 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>
 * 
 */

#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"


/*
 * 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)
{
  (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;

  IPFRAG_STATS_INC(ip_frag.recv);

  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) {
    LWIP_DEBUGF(IP_REASS_DEBUG, ("ip_reass: new packet\n"));
    memcpy(iphdr, 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)) {
    LWIP_DEBUGF(IP_REASS_DEBUG, ("ip_reass: matching old packet\n"));
    IPFRAG_STATS_INC(ip_frag.cachehit);
    /* 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) {
      LWIP_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. */
    LWIP_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)) {
      LWIP_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];
      LWIP_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;
      LWIP_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) {
    LWIP_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]) {
  LWIP_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(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. */
    LWIP_DEBUGF(IP_REASS_DEBUG,
     ("ip_reass: memcpy from %p (%d) to %p, %d bytes\n",
      (void *)&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;
  }
  IPFRAG_STATS_INC(ip_frag.fw);
      } else {
  IPFRAG_STATS_INC(ip_frag.memerr);
      }
      LWIP_DEBUGF(IP_REASS_DEBUG, ("ip_reass: p %p\n", (void*)p));
      return p;
    }
  }

nullreturn:
  IPFRAG_STATS_INC(ip_frag.drop);
  pbuf_free(p);
  return NULL;
}

#define MAX_MTU 1500
static u8_t buf[MEM_ALIGN_SIZE(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 = MEM_ALIGN((void *)buf);

  /* Copy the IP header in it */
  iphdr = rambuf->payload;
  memcpy(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(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);
    IPFRAG_STATS_INC(ip_frag.xmit);
    pbuf_free(header);

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

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
亚洲人成人一区二区在线观看| 福利一区福利二区| 从欧美一区二区三区| 久久免费精品国产久精品久久久久| 久久精品国产在热久久| 日韩欧美一级二级三级| 国产毛片精品视频| 中文字幕一区二区三区视频| a级精品国产片在线观看| 一区二区三区欧美在线观看| 欧美精品高清视频| 久久精品免费观看| 日本一区二区三区国色天香| 色屁屁一区二区| 日韩中文字幕麻豆| 国产色91在线| 在线精品视频一区二区| 美国av一区二区| 亚洲欧洲日韩一区二区三区| 欧美欧美欧美欧美首页| 精品一区二区在线免费观看| 日本一区二区综合亚洲| 欧美日韩国产一区| 国产福利视频一区二区三区| 亚洲永久精品大片| 亚洲成人激情av| 欧美日韩日日摸| 精品在线一区二区三区| 国产精品欧美经典| 欧美一级黄色大片| 91网上在线视频| 精品在线播放午夜| 另类小说图片综合网| 自拍偷拍亚洲综合| 欧美电视剧免费全集观看| a亚洲天堂av| 黑人精品欧美一区二区蜜桃| 亚洲欧美国产77777| 精品三级在线观看| 欧美在线观看视频一区二区 | 午夜电影一区二区| 久久久久久久久久久久电影| 色狠狠av一区二区三区| 国产成人综合精品三级| 婷婷国产v国产偷v亚洲高清| 亚洲欧美日韩国产中文在线| 精品精品国产高清一毛片一天堂| 在线一区二区视频| 成人动漫一区二区| 国内精品在线播放| 日本欧美加勒比视频| 一区二区三区在线影院| 亚洲国产精品成人综合 | 国产suv精品一区二区三区| 亚洲一区二区三区国产| 国产精品不卡在线观看| 久久精品一区四区| 91精品国产欧美一区二区| 91老师片黄在线观看| 成人一区二区三区| 国产69精品一区二区亚洲孕妇| 蜜桃91丨九色丨蝌蚪91桃色| 亚洲一二三区不卡| 亚洲精品国产无天堂网2021| 国产精品二区一区二区aⅴ污介绍| 久久久久国色av免费看影院| 精品盗摄一区二区三区| 日韩一区二区精品在线观看| 欧美日韩1234| 欧美日韩你懂得| 欧美日韩免费观看一区三区| 欧美性三三影院| 在线精品观看国产| 欧美日韩视频一区二区| 欧美少妇一区二区| 欧美日韩一级片网站| 在线播放视频一区| 在线不卡a资源高清| 日韩一区二区高清| 欧美成人vr18sexvr| 精品剧情在线观看| 久久久久久久电影| 国产精品久久看| 一区二区三区欧美激情| 亚洲精品成人天堂一二三| 亚洲一区在线观看视频| 亚洲一本大道在线| 日本不卡一区二区三区| 久久成人综合网| 成人做爰69片免费看网站| 99久久er热在这里只有精品66| 91美女蜜桃在线| 欧美乱妇15p| 精品日韩在线观看| 中文字幕av在线一区二区三区| 1000精品久久久久久久久| 一区二区三区在线观看网站| 亚洲电影一区二区| 免费在线观看日韩欧美| 国产麻豆精品95视频| 成人免费视频app| 欧美色图片你懂的| 欧美精品一区二区三区高清aⅴ| 国产日韩欧美激情| 亚洲综合色视频| 紧缚捆绑精品一区二区| av亚洲精华国产精华精华| 欧美综合久久久| 久久久久高清精品| 一区二区三区国产精品| 美脚の诱脚舐め脚责91| 成人h版在线观看| 88在线观看91蜜桃国自产| 久久久久久99久久久精品网站| 亚洲乱码中文字幕| 紧缚奴在线一区二区三区| 色香蕉成人二区免费| 欧美一区国产二区| 专区另类欧美日韩| 蜜臀av在线播放一区二区三区| 成人h动漫精品一区二| 91.xcao| 亚洲国产高清aⅴ视频| 五月综合激情日本mⅴ| 国产精品一区二区x88av| 欧美色偷偷大香| 国产精品沙发午睡系列990531| 首页国产欧美久久| 91蜜桃婷婷狠狠久久综合9色| 欧美成人性福生活免费看| 亚洲精品日韩专区silk| 国产激情一区二区三区四区 | 亚洲无人区一区| 国产乱码精品一品二品| 欧美精选一区二区| 尤物在线观看一区| 国产成人av影院| 精品盗摄一区二区三区| 婷婷综合五月天| 在线欧美日韩精品| 国产精品二区一区二区aⅴ污介绍| 精油按摩中文字幕久久| 欧美女孩性生活视频| 伊人开心综合网| 99在线热播精品免费| 欧美精品一区二区蜜臀亚洲| 日本美女视频一区二区| 欧美偷拍一区二区| 亚洲免费av高清| 99久久精品国产毛片| 中国av一区二区三区| 精品亚洲porn| 精品91自产拍在线观看一区| 麻豆成人综合网| 欧美一级夜夜爽| 日本午夜精品一区二区三区电影| 色吧成人激情小说| 有码一区二区三区| 欧洲精品一区二区| 一区二区三区在线视频观看58| 色婷婷综合视频在线观看| 中文字幕亚洲一区二区av在线| 大胆亚洲人体视频| 中文字幕一区二区三区四区不卡 | 欧美日韩高清在线播放| 亚洲欧美日韩国产中文在线| 色综合天天做天天爱| 亚洲欧美另类久久久精品| 91免费版pro下载短视频| 国产精品久久久久久久久免费桃花| 国产91富婆露脸刺激对白| 亚洲国产精品ⅴa在线观看| 成人中文字幕在线| 国产精品的网站| 色视频欧美一区二区三区| 亚洲尤物在线视频观看| 欧美精品xxxxbbbb| 麻豆精品国产91久久久久久| 久久亚洲私人国产精品va媚药| 国产精品资源网| 中文字幕精品三区| 91毛片在线观看| 亚洲成在人线免费| 日韩视频在线一区二区| 国内精品视频666| 中文字幕字幕中文在线中不卡视频| 一本大道久久a久久综合| 一区二区三区在线免费播放| 欧美日韩国产高清一区二区三区| 日韩高清一区二区| 久久久噜噜噜久久中文字幕色伊伊 | 91麻豆免费观看| 午夜欧美视频在线观看| 日韩精品影音先锋| 大陆成人av片| 日日夜夜免费精品| 久久精品日韩一区二区三区| 色国产综合视频| 黄色小说综合网站| 亚洲蜜臀av乱码久久精品|