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

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

?? ip_frag.c

?? lwip在ucos上的移植
?? 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 <string.h>#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 1000static u8_t ip_reassbuf[IP_HLEN + IP_REASS_BUFSIZE];static u8_t ip_reassbitmap[IP_REASS_BUFSIZE / (8 * 8) + 1];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 0x01static u8_t ip_reasstmr;/** * Reassembly timer base function * for both NO_SYS == 0 and 1 (!). * * Should be called every 1000 msec. */voidip_reass_tmr(void){  if (ip_reasstmr > 0) {    ip_reasstmr--;  }}/** * Reassembles incoming IP fragments into an IP datagram. * * @param p points to a pbuf chain of the fragment * @return NULL if reassembly is incomplete, ? otherwise */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;    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 previous fragment ID=%"X16_F"\n",      ntohs(IPH_ID(fraghdr))));    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 (%"S16_F":%"S16_F"/%"S16_F").\n", offset,        offset + len, IP_REASS_BUFSIZE));      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 %"S16_F" into %"S16_F":%"S16_F"\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. */      LWIP_ASSERT("offset / (8 * 8) < sizeof(ip_reassbitmap)",                   offset / (8 * 8) < sizeof(ip_reassbitmap));      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. */      LWIP_ASSERT("offset / (8 * 8) < sizeof(ip_reassbitmap)",                   offset / (8 * 8) < sizeof(ip_reassbitmap));      ip_reassbitmap[offset / (8 * 8)] |= bitmap_bits[(offset / 8) & 7];      LWIP_DEBUGF(IP_REASS_DEBUG,       ("ip_reass: updating many bytes in bitmap (%"S16_F":%"S16_F").\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;      }      LWIP_ASSERT("(offset + len) / (8 * 8) < sizeof(ip_reassbitmap)",                   (offset + len) / (8 * 8) < sizeof(ip_reassbitmap));      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 %"S16_F"\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. */      LWIP_ASSERT("ip_reasslen / (8 * 8) - 1 < sizeof(ip_reassbitmap)",                   ip_reasslen / (8 * 8) - 1 < sizeof(ip_reassbitmap));      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 %"S16_F"/%"S16_F" failed (%"X16_F")\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. */      LWIP_ASSERT("ip_reasslen / (8 * 8) < sizeof(ip_reassbitmap)",                   ip_reasslen / (8 * 8) < sizeof(ip_reassbitmap));      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 %"S16_F" didn't contain %"X16_F" (%"X16_F")\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. */      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 (%"S16_F") to %p, %"S16_F" 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 1500static u8_t buf[MEM_ALIGN_SIZE(MAX_MTU)];/** * Fragment an IP datagram if too large for the netif. * * Chop the datagram 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);  if (rambuf == NULL) {    return ERR_MEM;  }  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);    if (header != NULL) {      pbuf_chain(header, rambuf);      netif->output(netif, header, dest);      IPFRAG_STATS_INC(ip_frag.xmit);      pbuf_free(header);    } else {      pbuf_free(rambuf);            return ERR_MEM;        }    left -= cop;  }  pbuf_free(rambuf);  return ERR_OK;}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
日韩国产欧美视频| 青青草国产精品97视觉盛宴| 亚洲精品乱码久久久久久| 视频精品一区二区| 亚洲国产欧美日韩另类综合| 亚洲一区二区av在线| 亚洲国产视频网站| 成人在线视频一区| 日韩一本二本av| 亚洲午夜精品一区二区三区他趣| 国产乱人伦偷精品视频不卡| 日韩欧美在线观看一区二区三区| 伊人性伊人情综合网| 粉嫩一区二区三区在线看| 欧美一区二区成人| 石原莉奈在线亚洲二区| 欧美三级在线播放| 一区二区三区日韩| 色婷婷综合久久久| 亚洲人亚洲人成电影网站色| 懂色av一区二区在线播放| 精品久久久久久综合日本欧美| 视频一区欧美精品| 777午夜精品免费视频| 亚洲高清视频在线| 欧美亚洲国产怡红院影院| 亚洲综合在线五月| 色综合一个色综合亚洲| 亚洲欧美日韩在线播放| 色哟哟国产精品免费观看| 日韩美女啊v在线免费观看| 成a人片亚洲日本久久| 国产女主播视频一区二区| 日日摸夜夜添夜夜添精品视频| 欧美日韩不卡一区| 天堂va蜜桃一区二区三区漫画版| 欧美激情一区二区三区四区| 国产精品一二三在| 日本一区二区三区四区在线视频| 国产成人免费在线观看| 国产日产欧美精品一区二区三区| 国产福利视频一区二区三区| 国产精品久久久一区麻豆最新章节| 国产麻豆精品在线观看| 国产精品伦理在线| 欧美性xxxxxx少妇| 美女精品一区二区| 久久影院午夜论| av不卡一区二区三区| 亚洲免费观看在线视频| 3d成人动漫网站| 国产福利一区二区三区在线视频| 国产精品久久久久影视| 日本道免费精品一区二区三区| 亚洲一卡二卡三卡四卡无卡久久 | 日韩三级伦理片妻子的秘密按摩| 麻豆国产精品官网| 国产精品短视频| 欧美日韩中文字幕一区二区| 激情综合色综合久久综合| 国产精品久久久久影院亚瑟| 欧美日韩精品一区视频| 国精产品一区一区三区mba视频 | 久久蜜桃av一区二区天堂| 99久久久国产精品免费蜜臀| 三级精品在线观看| 久久久蜜桃精品| 欧美中文字幕亚洲一区二区va在线 | 1000精品久久久久久久久| 91精品国产综合久久婷婷香蕉| 国产成人精品亚洲午夜麻豆| 一区二区三区在线高清| 日韩一区二区电影| 91小视频在线观看| 精品在线观看免费| 亚洲高清不卡在线| 国产精品欧美精品| 欧美成人精品福利| 在线欧美小视频| 国产99久久久国产精品| 日韩电影在线免费| 一区二区三区在线观看国产| 国产无遮挡一区二区三区毛片日本| 欧美亚洲综合久久| 成av人片一区二区| 国产乱理伦片在线观看夜一区| 亚洲综合在线视频| 亚洲婷婷综合久久一本伊一区| 精品国产91久久久久久久妲己| 欧美综合欧美视频| 欧美性色欧美a在线播放| 国产成人免费视频网站高清观看视频| 一区二区三区免费网站| 久久综合九色综合97_久久久| 欧美日韩一区二区三区不卡| 不卡的电影网站| 国产精品99精品久久免费| 婷婷成人综合网| 亚洲一区二区三区在线| 国产精品初高中害羞小美女文| 2021久久国产精品不只是精品| 欧美老年两性高潮| 色狠狠一区二区| 色哟哟一区二区| 91天堂素人约啪| 成人免费高清视频在线观看| 国模冰冰炮一区二区| 韩国精品主播一区二区在线观看 | 国产精品成人网| 国产欧美日韩卡一| 久久五月婷婷丁香社区| 久久亚洲一区二区三区明星换脸| 日韩一区二区在线观看视频| 欧美一区欧美二区| 欧美一区二区三区在线看| 欧美日韩一区久久| 4438亚洲最大| 精品免费国产二区三区| 26uuu另类欧美| 伊人婷婷欧美激情| 婷婷国产在线综合| 蜜臀av性久久久久蜜臀aⅴ四虎| 日韩影视精彩在线| 免费精品视频在线| 国产一区二区三区免费播放| 国产成a人亚洲| 99精品欧美一区二区三区小说| 99久久精品国产网站| 91豆麻精品91久久久久久| 欧美男人的天堂一二区| 69精品人人人人| 2020国产精品| 亚洲免费观看在线观看| 偷拍与自拍一区| 精油按摩中文字幕久久| 福利一区二区在线| 欧美午夜片在线观看| 欧美一区二区大片| 国产精品免费视频观看| 亚洲日本欧美天堂| 日本欧美一区二区在线观看| 狠狠色综合日日| 91蜜桃在线免费视频| 欧美久久久影院| 国产亚洲欧美一区在线观看| 亚洲已满18点击进入久久| 精品一区二区三区在线播放视频 | 亚洲另类中文字| 欧美aⅴ一区二区三区视频| 国产精品亚洲一区二区三区在线| 99久久综合99久久综合网站| 欧美性受xxxx| 久久在线观看免费| 玉米视频成人免费看| 韩国女主播一区| 欧美日本免费一区二区三区| 日本一区二区三区在线不卡| 日韩成人免费看| 91在线国产福利| 久久欧美中文字幕| 亚洲电影第三页| 成人黄色免费短视频| 91精品国产欧美一区二区18| 国产精品国产三级国产aⅴ原创| 日本成人中文字幕在线视频| 成人晚上爱看视频| 欧美成人激情免费网| 一区二区三区四区激情| 懂色av一区二区三区蜜臀| 欧美精品久久99久久在免费线| 国产精品电影院| 国产精品影视在线| 成人午夜电影网站| 92精品国产成人观看免费| 日韩女优毛片在线| 午夜精品视频在线观看| av亚洲精华国产精华精| 精品粉嫩aⅴ一区二区三区四区| 亚洲成人在线免费| 99久久国产综合色|国产精品| 久久精品视频网| 美女一区二区三区| 精品视频一区 二区 三区| 亚洲色图.com| jlzzjlzz亚洲日本少妇| 久久久高清一区二区三区| 麻豆高清免费国产一区| 欧美剧情片在线观看| 亚洲在线视频一区| 91视频国产观看| 国产精品久久久久久久久免费桃花 | 日韩片之四级片| 婷婷综合另类小说色区| 欧美亚洲综合网| 午夜精品影院在线观看| 欧美日韩国产大片| 亚洲国产精品天堂| 欧美精品日韩综合在线| 亚洲一区二区成人在线观看| 欧美日本在线一区|