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

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

?? raw.c

?? lm3s下lwip的udp
?? 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) {
      /* 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_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一区二区三区免费野_久草精品视频
91蜜桃视频在线| 不卡视频在线观看| 亚洲成av人综合在线观看| 国产精品久久久久影院老司| 久久综合久色欧美综合狠狠| 欧美成人午夜电影| 欧美成人video| 欧美精品一区视频| 国产片一区二区| 日韩毛片一二三区| 亚洲欧美日韩国产中文在线| 亚洲美女免费视频| 五月天一区二区三区| 日本成人在线网站| 国产在线日韩欧美| 国产成人av电影在线观看| 99久久精品国产网站| 色婷婷久久久久swag精品| 欧美亚洲免费在线一区| 欧美一级爆毛片| 国产亚洲精品bt天堂精选| 中文字幕一区视频| 亚洲www啪成人一区二区麻豆| 五月开心婷婷久久| 国产传媒欧美日韩成人| 99re成人在线| 欧美一区二区三区日韩| 国产视频一区在线播放| 一区二区成人在线视频| 日本欧美大码aⅴ在线播放| 国产成人一区二区精品非洲| 91麻豆福利精品推荐| 日韩一区二区精品葵司在线| 国产精品网曝门| 亚洲国产综合视频在线观看| 激情六月婷婷综合| 91久久精品一区二区二区| 欧美一区二区精品在线| 中文字幕一区二区三区在线不卡| 亚洲国产精品一区二区www在线 | 蓝色福利精品导航| 成人精品免费视频| 欧美一区二区精品久久911| 中文字幕永久在线不卡| 久久精品国产精品亚洲红杏| 色综合中文字幕| 久久免费美女视频| 一区二区三区不卡视频| 国产馆精品极品| 欧美一级日韩一级| 一区二区三区小说| 丁香一区二区三区| 欧美va在线播放| 婷婷久久综合九色综合绿巨人| 国产成人精品免费在线| 日韩精品综合一本久道在线视频| 亚洲精品一二三| 成年人网站91| 亚洲国产精品成人综合色在线婷婷| 日本免费在线视频不卡一不卡二| 在线视频欧美精品| 一区在线播放视频| 白白色 亚洲乱淫| 国产欧美一区二区精品仙草咪| 日本伊人色综合网| 欧美一区二区三区四区高清| 婷婷成人综合网| 欧美亚洲尤物久久| 亚洲大尺度视频在线观看| 色综合久久综合| 亚洲伦在线观看| 91免费在线视频观看| 中文字幕日韩欧美一区二区三区| 高清在线成人网| 中文字幕不卡在线播放| 成人在线综合网| 亚洲欧美另类综合偷拍| 91蝌蚪porny成人天涯| 亚洲伦在线观看| 欧美日韩中字一区| 天天综合色天天综合色h| 欧美福利电影网| 久久99精品久久只有精品| 欧美成人女星排名| 国产综合色视频| 中文子幕无线码一区tr| 91蜜桃婷婷狠狠久久综合9色| 亚洲激情第一区| 欧美精品色一区二区三区| 蜜桃av噜噜一区| 国产日产欧美一区二区三区| 成人99免费视频| 婷婷一区二区三区| www亚洲一区| 99在线精品视频| 五月婷婷色综合| 国产午夜亚洲精品理论片色戒| 成人永久aaa| 亚洲综合视频网| 久久五月婷婷丁香社区| 99久久精品国产一区| 日韩在线卡一卡二| 久久久久久毛片| 欧洲精品一区二区| 经典三级视频一区| 亚洲欧美激情一区二区| 欧美一二三区精品| www.综合网.com| 人人精品人人爱| 国产精品三级av在线播放| 在线观看日韩电影| 国产毛片精品视频| 一区二区三区蜜桃| 久久久久99精品一区| 欧日韩精品视频| 国产精品中文有码| 天堂影院一区二区| 中文字幕一区日韩精品欧美| 欧美tk丨vk视频| 欧美系列在线观看| 99久久久无码国产精品| 久久精品国内一区二区三区| 亚洲精品免费在线观看| 久久婷婷综合激情| 欧美理论片在线| 91免费在线播放| 国产激情视频一区二区在线观看 | 日韩不卡手机在线v区| 国产精品乱人伦| www激情久久| 欧美一区二区在线免费观看| 色偷偷一区二区三区| 国产激情视频一区二区在线观看| 免费人成精品欧美精品| 亚洲制服欧美中文字幕中文字幕| 国产色爱av资源综合区| 精品国产网站在线观看| 欧美日韩免费高清一区色橹橹| av一二三不卡影片| 国产不卡在线一区| 国产酒店精品激情| 国产麻豆精品久久一二三| 蜜乳av一区二区| 久久精品国产亚洲高清剧情介绍| 亚洲.国产.中文慕字在线| 亚洲人成网站在线| 国产精品理论在线观看| 国产欧美日韩在线观看| 精品福利在线导航| 精品福利一区二区三区免费视频| 日韩一区二区三区视频| 欧美二区在线观看| 欧美另类变人与禽xxxxx| 欧美日韩dvd在线观看| 欧美人妇做爰xxxⅹ性高电影| 91精品1区2区| 欧日韩精品视频| 欧美丰满少妇xxxxx高潮对白 | 国产精品乱码久久久久久 | 欧美亚洲国产一区二区三区va| 成人av中文字幕| 一本色道久久综合亚洲91| 日本高清不卡一区| 欧美色图一区二区三区| 欧美日韩国产另类不卡| 4438x亚洲最大成人网| 精品欧美一区二区在线观看 | 91福利在线免费观看| 在线一区二区三区四区五区| 欧美日韩中文国产| 日韩欧美一区二区免费| 久久免费午夜影院| 亚洲精品中文在线影院| 日韩高清在线观看| 国产精一品亚洲二区在线视频| 懂色一区二区三区免费观看| 成a人片国产精品| 欧美区视频在线观看| 欧美精品一区二区不卡| 国产精品国产三级国产专播品爱网 | 99精品久久免费看蜜臀剧情介绍| 91麻豆国产自产在线观看| 在线播放亚洲一区| 国产拍揄自揄精品视频麻豆| 一区二区三区电影在线播| 视频在线观看一区| 大胆欧美人体老妇| 欧美日韩精品欧美日韩精品一| 久久综合九色综合欧美98| 亚洲乱码国产乱码精品精的特点 | 欧美系列日韩一区| 欧美mv日韩mv国产网站app| 1区2区3区国产精品| 丝袜亚洲另类丝袜在线| 成人av在线一区二区三区| 欧美一区二区三区在线电影| 亚洲婷婷综合久久一本伊一区| 六月丁香综合在线视频| 91福利资源站| 国产精品家庭影院|