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

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

?? raw.c

?? STM32F107_ETH_LwIP_V1.0.0.rar
?? 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 */

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
91视视频在线观看入口直接观看www| 97精品久久久久中文字幕| 亚洲欧洲99久久| 91精品国产综合久久久蜜臀粉嫩| 国产成人综合亚洲91猫咪| 亚洲午夜视频在线| 国产天堂亚洲国产碰碰| 欧美视频在线不卡| 成人少妇影院yyyy| 日韩av一级电影| 亚洲素人一区二区| 精品国产乱码久久久久久影片| 色噜噜狠狠色综合欧洲selulu| 精品亚洲成a人| 午夜精品久久久久久久久久久 | 亚洲午夜电影在线观看| 国产欧美日韩精品在线| 91精品国产乱| 欧美午夜精品一区二区三区| 成人手机在线视频| 国产永久精品大片wwwapp| 亚洲电影视频在线| 综合久久给合久久狠狠狠97色| 久久中文字幕电影| 日韩一区二区三区观看| 欧美性猛交一区二区三区精品| heyzo一本久久综合| 国产精品 欧美精品| 国产一区二区伦理| 久久精品久久99精品久久| 日韩高清在线电影| 五月天网站亚洲| 亚洲已满18点击进入久久| 亚洲欧美在线高清| 国产精品国产馆在线真实露脸| 国产亚洲午夜高清国产拍精品| 日韩欧美一区在线| 欧美一区三区二区| 日韩欧美国产综合| 日韩一区二区精品在线观看| 91麻豆精品国产91久久久久| 欧美日韩一本到| 在线综合视频播放| 欧美tk—视频vk| 久久女同性恋中文字幕| 精品久久人人做人人爰| 精品1区2区在线观看| 精品99久久久久久| 国产欧美日韩一区二区三区在线观看| 精品国内二区三区| 久久综合久久久久88| 久久久久成人黄色影片| 久久久久国产精品麻豆| 国产精品久久久久久久浪潮网站| 国产精品美日韩| 亚洲欧美自拍偷拍| 亚洲午夜在线视频| 美女一区二区在线观看| 国内欧美视频一区二区| 国产一区中文字幕| 不卡一卡二卡三乱码免费网站| 色综合久久精品| 欧美一区二区视频网站| 久久久无码精品亚洲日韩按摩| 国产三级一区二区三区| 亚洲丝袜另类动漫二区| 无码av免费一区二区三区试看| 日本大胆欧美人术艺术动态 | 蜜臀av一区二区在线观看 | 成人av影视在线观看| 成人三级伦理片| 欧美日韩国产一级| 精品久久国产老人久久综合| 国产精品色哟哟网站| 亚洲欧美国产77777| 午夜一区二区三区视频| 美女精品一区二区| av不卡一区二区三区| 欧美日韩中文另类| 26uuu精品一区二区| 国产精品美日韩| 香蕉久久一区二区不卡无毒影院 | 亚洲图片欧美视频| 激情图片小说一区| 色综合天天狠狠| 日韩一级二级三级精品视频| 国产精品久久久久天堂| 免费在线观看日韩欧美| av资源网一区| 欧美一级电影网站| 樱花影视一区二区| 国产麻豆精品久久一二三| 色吧成人激情小说| 久久精品人人做| 午夜私人影院久久久久| 99久久免费国产| 欧美电影免费观看高清完整版在| 亚洲激情图片一区| 久久精品久久综合| 精品污污网站免费看| 国产欧美日产一区| 日韩电影网1区2区| 一本色道久久综合精品竹菊| 亚洲精品在线观看网站| 亚洲一二三四区不卡| 高清在线观看日韩| 日韩视频在线观看一区二区| 一区二区三区欧美在线观看| 国产精品一区二区无线| 欧美一区二区三区日韩| 伊人婷婷欧美激情| 成人av在线看| 国产片一区二区三区| 久久99精品网久久| 欧美三级韩国三级日本三斤| 中文字幕一区二区在线观看| 国产一区二区久久| 欧美一区2区视频在线观看| 夜夜嗨av一区二区三区| 91香蕉国产在线观看软件| 欧美激情一区在线| 国产美女av一区二区三区| 日韩亚洲欧美高清| 日韩av中文在线观看| 欧美日韩国产影片| 亚洲图片欧美视频| 欧美在线制服丝袜| 一区二区不卡在线播放 | 日韩一级免费观看| 日本成人中文字幕在线视频| 欧美日韩精品电影| 亚洲大片一区二区三区| 色噜噜狠狠成人网p站| 亚洲视频每日更新| 91亚洲永久精品| 亚洲欧洲99久久| 色久优优欧美色久优优| 一区二区三区国产精华| 色婷婷国产精品| 亚洲国产日韩在线一区模特| 欧美视频一区二区三区四区| 一区二区三区影院| 欧美综合久久久| 亚洲成人中文在线| 91精品国产麻豆| 久久国内精品视频| 久久综合九色综合97_久久久 | 91视视频在线观看入口直接观看www| 国产精品久久久久久久久果冻传媒| 高清视频一区二区| 日韩一区欧美一区| 欧洲国内综合视频| 婷婷综合另类小说色区| 91精品国产欧美一区二区18 | 国产一区在线看| 国产精品看片你懂得| 99久久精品99国产精品| 亚洲一级二级三级在线免费观看| 欧美日本一道本| 黑人巨大精品欧美黑白配亚洲| 国产拍欧美日韩视频二区| av一区二区不卡| 亚洲成a人v欧美综合天堂| 欧美xxxxx裸体时装秀| 成人禁用看黄a在线| 又紧又大又爽精品一区二区| 欧美一区二区啪啪| 成人综合婷婷国产精品久久| 亚洲乱码国产乱码精品精可以看 | 51精品国自产在线| 国产精品一区不卡| 亚洲精选免费视频| 日韩一区二区三区电影在线观看 | 日韩欧美一级二级三级| eeuss鲁一区二区三区| 亚洲午夜av在线| 国产亚洲精品aa午夜观看| 99国产一区二区三精品乱码| 亚洲成人动漫精品| 国产日韩一级二级三级| 91传媒视频在线播放| 精品在线播放午夜| 亚洲精品五月天| 久久麻豆一区二区| 欧日韩精品视频| 国模一区二区三区白浆 | 高清国产一区二区| 亚洲6080在线| 国产精品丝袜久久久久久app| 欧美系列亚洲系列| 成人黄色一级视频| 男女性色大片免费观看一区二区 | 欧美一区二区在线播放| 91天堂素人约啪| 国产在线精品视频| 亚洲午夜精品网| 自拍偷拍国产亚洲| 国产欧美一区二区精品久导航| 欧美日韩在线亚洲一区蜜芽| 成人免费看片app下载|