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

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

?? raw.c

?? LWIP在STM32裸機上的移植
?? C
字號:
/**
 * @file
 * Implementation of raw protocol PCBs for low-level handling of
 * different types of protocols besides (or overriding) those
 * already available in lwIP.
 *
 */

/*
 * 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: Adam Dunkels <adam@sics.se>
 *
 */

#include "lwip/opt.h"

#if LWIP_RAW /* don't build if not configured for use in lwipopts.h */

#include "lwip/def.h"
#include "lwip/memp.h"
#include "lwip/inet.h"
#include "lwip/ip_addr.h"
#include "lwip/netif.h"
#include "lwip/raw.h"
#include "lwip/stats.h"
#include "lwip/snmp.h"
#include "arch/perf.h"

#include <string.h>

/** The list of RAW PCBs */
static struct raw_pcb *raw_pcbs;

/**
 * Determine if in incoming IP packet is covered by a RAW PCB
 * and if so, pass it to a user-provided receive callback function.
 *
 * Given an incoming IP datagram (as a chain of pbufs) this function
 * finds a corresponding RAW PCB and calls the corresponding receive
 * callback function.
 *
 * @param p pbuf to be demultiplexed to a RAW PCB.
 * @param inp network interface on which the datagram was received.
 * @return - 1 if the packet has been eaten by a RAW PCB receive
 *           callback function. The caller MAY NOT not reference the
 *           packet any longer, and MAY NOT call pbuf_free().
 * @return - 0 if packet is not eaten (pbuf is still referenced by the
 *           caller).
 *
 */
u8_t
raw_input(struct pbuf *p, struct netif *inp)
{
  struct raw_pcb *pcb, *prev;
  struct ip_hdr *iphdr;
  s16_t proto;
  u8_t eaten = 0;

  LWIP_UNUSED_ARG(inp);

  iphdr = p->payload;
  proto = IPH_PROTO(iphdr);

  prev = NULL;
  pcb = raw_pcbs;
  /* loop through all raw pcbs until the packet is eaten by one */
  /* this allows multiple pcbs to match against the packet by design */
  while ((eaten == 0) && (pcb != NULL)) {
    if (pcb->protocol == proto) {
#if IP_SOF_BROADCAST_RECV
      /* broadcast filter? */
      if ((pcb->so_options & SOF_BROADCAST) || !ip_addr_isbroadcast(&(iphdr->dest), inp))
#endif /* IP_SOF_BROADCAST_RECV */
      {
        /* receive callback function available? */
        if (pcb->recv != NULL) {
          /* the receive callback function did not eat the packet? */
          if (pcb->recv(pcb->recv_arg, pcb, p, &(iphdr->src)) != 0) {
            /* receive function ate the packet */
            p = NULL;
            eaten = 1;
            if (prev != NULL) {
            /* move the pcb to the front of raw_pcbs so that is
               found faster next time */
              prev->next = pcb->next;
              pcb->next = raw_pcbs;
              raw_pcbs = pcb;
            }
          }
        }
        /* no receive callback function was set for this raw PCB */
      }
      /* drop the packet */
    }
    prev = pcb;
    pcb = pcb->next;
  }
  return eaten;
}

/**
 * Bind a RAW PCB.
 *
 * @param pcb RAW PCB to be bound with a local address ipaddr.
 * @param ipaddr local IP address to bind with. Use IP_ADDR_ANY to
 * bind to all local interfaces.
 *
 * @return lwIP error code.
 * - ERR_OK. Successful. No error occured.
 * - ERR_USE. The specified IP address is already bound to by
 * another RAW PCB.
 *
 * @see raw_disconnect()
 */
err_t
raw_bind(struct raw_pcb *pcb, struct ip_addr *ipaddr)
{
  ip_addr_set(&pcb->local_ip, ipaddr);
  return ERR_OK;
}

/**
 * Connect an RAW PCB. This function is required by upper layers
 * of lwip. Using the raw api you could use raw_sendto() instead
 *
 * This will associate the RAW PCB with the remote address.
 *
 * @param pcb RAW PCB to be connected with remote address ipaddr and port.
 * @param ipaddr remote IP address to connect with.
 *
 * @return lwIP error code
 *
 * @see raw_disconnect() and raw_sendto()
 */
err_t
raw_connect(struct raw_pcb *pcb, struct ip_addr *ipaddr)
{
  ip_addr_set(&pcb->remote_ip, ipaddr);
  return ERR_OK;
}


/**
 * Set the callback function for received packets that match the
 * raw PCB's protocol and binding. 
 * 
 * The callback function MUST either
 * - eat the packet by calling pbuf_free() and returning non-zero. The
 *   packet will not be passed to other raw PCBs or other protocol layers.
 * - not free the packet, and return zero. The packet will be matched
 *   against further PCBs and/or forwarded to another protocol layers.
 * 
 * @return non-zero if the packet was free()d, zero if the packet remains
 * available for others.
 */
void
raw_recv(struct raw_pcb *pcb,
         u8_t (* recv)(void *arg, struct raw_pcb *upcb, struct pbuf *p,
                      struct ip_addr *addr),
         void *recv_arg)
{
  /* remember recv() callback and user data */
  pcb->recv = recv;
  pcb->recv_arg = recv_arg;
}

/**
 * Send the raw IP packet to the given address. Note that actually you cannot
 * modify the IP headers (this is inconsistent with the receive callback where
 * you actually get the IP headers), you can only specify the IP payload here.
 * It requires some more changes in lwIP. (there will be a raw_send() function
 * then.)
 *
 * @param pcb the raw pcb which to send
 * @param p the IP payload to send
 * @param ipaddr the destination address of the IP packet
 *
 */
err_t
raw_sendto(struct raw_pcb *pcb, struct pbuf *p, struct ip_addr *ipaddr)
{
  err_t err;
  struct netif *netif;
  struct ip_addr *src_ip;
  struct pbuf *q; /* q will be sent down the stack */
  
  LWIP_DEBUGF(RAW_DEBUG | LWIP_DBG_TRACE | 3, ("raw_sendto\n"));
  
  /* not enough space to add an IP header to first pbuf in given p chain? */
  if (pbuf_header(p, IP_HLEN)) {
    /* allocate header in new pbuf */
    q = pbuf_alloc(PBUF_IP, 0, PBUF_RAM);
    /* new header pbuf could not be allocated? */
    if (q == NULL) {
      LWIP_DEBUGF(RAW_DEBUG | LWIP_DBG_TRACE | 2, ("raw_sendto: could not allocate header\n"));
      return ERR_MEM;
    }
    /* chain header q in front of given pbuf p */
    pbuf_chain(q, p);
    /* { first pbuf q points to header pbuf } */
    LWIP_DEBUGF(RAW_DEBUG, ("raw_sendto: added header pbuf %p before given pbuf %p\n", (void *)q, (void *)p));
  }  else {
    /* first pbuf q equals given pbuf */
    q = p;
    if(pbuf_header(q, -IP_HLEN)) {
      LWIP_ASSERT("Can't restore header we just removed!", 0);
      return ERR_MEM;
    }
  }

  if ((netif = ip_route(ipaddr)) == NULL) {
    LWIP_DEBUGF(RAW_DEBUG | 1, ("raw_sendto: No route to 0x%"X32_F"\n", ipaddr->addr));
    /* free any temporary header pbuf allocated by pbuf_header() */
    if (q != p) {
      pbuf_free(q);
    }
    return ERR_RTE;
  }

#if IP_SOF_BROADCAST
  /* broadcast filter? */
  if ( ((pcb->so_options & SOF_BROADCAST) == 0) && ip_addr_isbroadcast(ipaddr, netif) ) {
    LWIP_DEBUGF(RAW_DEBUG | 1, ("raw_sendto: SOF_BROADCAST not enabled on pcb %p\n", (void *)pcb));
    /* free any temporary header pbuf allocated by pbuf_header() */
    if (q != p) {
      pbuf_free(q);
    }
    return ERR_VAL;
  }
#endif /* IP_SOF_BROADCAST */

  if (ip_addr_isany(&pcb->local_ip)) {
    /* use outgoing network interface IP address as source address */
    src_ip = &(netif->ip_addr);
  } else {
    /* use RAW PCB local IP address as source address */
    src_ip = &(pcb->local_ip);
  }

#if LWIP_NETIF_HWADDRHINT
  netif->addr_hint = &(pcb->addr_hint);
#endif /* LWIP_NETIF_HWADDRHINT*/
  err = ip_output_if (q, src_ip, ipaddr, pcb->ttl, pcb->tos, pcb->protocol, netif);
#if LWIP_NETIF_HWADDRHINT
  netif->addr_hint = NULL;
#endif /* LWIP_NETIF_HWADDRHINT*/

  /* did we chain a header earlier? */
  if (q != p) {
    /* free the header */
    pbuf_free(q);
  }
  return err;
}

/**
 * Send the raw IP packet to the address given by raw_connect()
 *
 * @param pcb the raw pcb which to send
 * @param p the IP payload to send
 *
 */
err_t
raw_send(struct raw_pcb *pcb, struct pbuf *p)
{
  return raw_sendto(pcb, p, &pcb->remote_ip);
}

/**
 * Remove an RAW PCB.
 *
 * @param pcb RAW PCB to be removed. The PCB is removed from the list of
 * RAW PCB's and the data structure is freed from memory.
 *
 * @see raw_new()
 */
void
raw_remove(struct raw_pcb *pcb)
{
  struct raw_pcb *pcb2;
  /* pcb to be removed is first in list? */
  if (raw_pcbs == pcb) {
    /* make list start at 2nd pcb */
    raw_pcbs = raw_pcbs->next;
    /* pcb not 1st in list */
  } else {
    for(pcb2 = raw_pcbs; pcb2 != NULL; pcb2 = pcb2->next) {
      /* find pcb in raw_pcbs list */
      if (pcb2->next != NULL && pcb2->next == pcb) {
        /* remove pcb from list */
        pcb2->next = pcb->next;
      }
    }
  }
  memp_free(MEMP_RAW_PCB, pcb);
}

/**
 * Create a RAW PCB.
 *
 * @return The RAW PCB which was created. NULL if the PCB data structure
 * could not be allocated.
 *
 * @param proto the protocol number of the IPs payload (e.g. IP_PROTO_ICMP)
 *
 * @see raw_remove()
 */
struct raw_pcb *
raw_new(u8_t proto) {
  struct raw_pcb *pcb;

  LWIP_DEBUGF(RAW_DEBUG | LWIP_DBG_TRACE | 3, ("raw_new\n"));

  pcb = memp_malloc(MEMP_RAW_PCB);
  /* could allocate RAW PCB? */
  if (pcb != NULL) {
    /* initialize PCB to all zeroes */
    memset(pcb, 0, sizeof(struct raw_pcb));
    pcb->protocol = proto;
    pcb->ttl = RAW_TTL;
    pcb->next = raw_pcbs;
    raw_pcbs = pcb;
  }
  return pcb;
}

#endif /* LWIP_RAW */

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
日韩久久一区二区| 欧美日韩美少妇 | 欧美国产日本韩| 久久国产精品72免费观看| 不卡的电影网站| 欧美zozo另类异族| 亚洲人吸女人奶水| 国产精品亚洲一区二区三区妖精| 欧美唯美清纯偷拍| 国产精品视频一二三| 奇米影视一区二区三区| 91一区二区在线观看| 久久天堂av综合合色蜜桃网| 日韩精品视频网站| 色国产精品一区在线观看| 日本一区二区视频在线| 韩国三级中文字幕hd久久精品| 欧美性色黄大片| 亚洲同性同志一二三专区| 国产成人一区在线| 精品欧美黑人一区二区三区| 无码av中文一区二区三区桃花岛| 99免费精品在线| 国产精品无人区| 国产高清在线精品| 久久精品欧美一区二区三区麻豆| 日韩精品91亚洲二区在线观看| 91精彩视频在线观看| 中文字幕一区二区三区乱码在线| 国产美女精品在线| 日本一区二区视频在线观看| 国产精品亚洲视频| 国产欧美一区二区精品性色| 激情小说亚洲一区| 久久久久亚洲蜜桃| 国产福利精品导航| 欧美国产欧美亚州国产日韩mv天天看完整| 激情综合色丁香一区二区| 日韩精品最新网址| 老司机精品视频线观看86| 欧美v日韩v国产v| 韩国成人在线视频| 久久亚洲二区三区| 成人免费看视频| 中文字幕亚洲一区二区av在线| 91视频观看视频| 夜色激情一区二区| 3atv在线一区二区三区| 午夜一区二区三区在线观看| 69堂国产成人免费视频| 麻豆成人91精品二区三区| 久久久久久电影| 成人国产电影网| 伊人夜夜躁av伊人久久| 欧美一区二区在线视频| 久久国产精品免费| 国产精品久久久久天堂| 色伊人久久综合中文字幕| 性感美女久久精品| 亚洲精品在线电影| jvid福利写真一区二区三区| 一区二区三区国产精品| 欧美一级一区二区| 国产91精品在线观看| 亚洲激情图片小说视频| 91精品国产综合久久精品性色| 国产一区在线视频| 中文字幕在线观看一区二区| 欧美剧在线免费观看网站| 国内精品久久久久影院色| 亚洲精品免费在线播放| 精品免费日韩av| 91视频一区二区| 另类综合日韩欧美亚洲| 亚洲欧美成人一区二区三区| 欧美放荡的少妇| 成人av先锋影音| 日韩国产欧美一区二区三区| 国产日韩欧美制服另类| 欧美精品高清视频| 91玉足脚交白嫩脚丫在线播放| 日本亚洲视频在线| 亚洲欧美日韩一区二区| 久久影院电视剧免费观看| 欧美日韩亚洲丝袜制服| 日韩一区二区三区四区五区六区 | 国产欧美日韩在线观看| 国产精品久线在线观看| 蜜臀av性久久久久蜜臀aⅴ四虎| 91久久精品一区二区三| 精品视频一区二区不卡| 亚洲免费视频中文字幕| 久久精品视频在线看| 激情五月婷婷综合| 亚洲成人精品在线观看| 中文字幕va一区二区三区| 911精品国产一区二区在线| 99vv1com这只有精品| 国产一区二区三区在线观看免费 | 国产精品一二二区| 日本色综合中文字幕| 亚洲一二三四久久| 亚洲美女精品一区| 亚洲欧美偷拍卡通变态| 国产精品久久午夜| 国产日本亚洲高清| 精品剧情v国产在线观看在线| 91 com成人网| 欧美嫩在线观看| 欧美性生活大片视频| 在线精品国精品国产尤物884a| jiyouzz国产精品久久| 国产成+人+日韩+欧美+亚洲| 国产精品888| jiyouzz国产精品久久| 91在线视频免费观看| 91在线播放网址| 色综合婷婷久久| 在线观看免费成人| 欧美三级视频在线观看| 欧美日韩电影在线播放| 色综合天天综合网国产成人综合天| caoporn国产精品| 欧美猛男gaygay网站| 国产揄拍国内精品对白| 久久色成人在线| 久久久久国产精品人| 久久久久久久久久电影| 欧美激情一区二区| 中文字幕在线不卡视频| 一区二区三区成人| 午夜视频一区在线观看| 免费在线观看一区| 国产一区二区调教| 白白色 亚洲乱淫| 97久久人人超碰| 欧美日韩你懂的| 日韩免费看网站| 中文字幕av一区二区三区免费看| 国产精品久久久久影院亚瑟 | 激情综合色播五月| 国产成人亚洲精品狼色在线| 99国产精品久久久久久久久久 | 中文字幕第一区| 一区二区三区电影在线播| 日本午夜精品视频在线观看| 国产综合色精品一区二区三区| 波多野结衣精品在线| 欧美视频在线不卡| 欧美精品一区二区在线观看| 中文字幕一区二区三区在线播放 | 欧美成人欧美edvon| 国产日韩精品一区二区三区 | 精品视频在线看| 久久众筹精品私拍模特| 亚洲一区免费在线观看| 九九视频精品免费| 色综合久久综合网欧美综合网| 制服丝袜一区二区三区| 亚洲欧洲精品天堂一级 | 国产91在线|亚洲| 欧美日韩国产另类不卡| 国产精品人妖ts系列视频| 午夜精品久久久久久久久久久 | 黄一区二区三区| 色诱视频网站一区| www国产成人| 亚洲成人av电影| 99久久久国产精品| 日韩欧美综合一区| 亚洲一区二区三区免费视频| 国产99一区视频免费| 欧美肥大bbwbbw高潮| 一区二区三区中文字幕精品精品| 国内欧美视频一区二区| 69av一区二区三区| 亚洲精品少妇30p| www.色综合.com| 国产视频一区二区在线观看| 亚洲国产精品自拍| 一本大道av伊人久久综合| 26uuu亚洲综合色| 日韩av中文在线观看| 欧美亚洲图片小说| 综合久久综合久久| 粉嫩av一区二区三区粉嫩| 26uuu亚洲综合色| 裸体健美xxxx欧美裸体表演| 欧美日韩亚洲综合| 亚洲综合一区二区| 日本福利一区二区| 亚洲人精品午夜| 风间由美中文字幕在线看视频国产欧美| 欧美片在线播放| 亚洲福利视频一区二区| 日本高清无吗v一区| 一区二区三区四区在线播放| 91香蕉国产在线观看软件| 亚洲欧美中日韩| 99视频热这里只有精品免费|