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

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

?? raw.c

?? 基于STM32F107的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) {
#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一区二区三区免费野_久草精品视频
五月天一区二区| 日本v片在线高清不卡在线观看| 亚洲另类中文字| 亚瑟在线精品视频| eeuss影院一区二区三区| 欧美日韩国产高清一区二区三区 | 精品一区二区三区免费毛片爱| 国精产品一区一区三区mba桃花 | 成人妖精视频yjsp地址| 欧美三区免费完整视频在线观看| 久久蜜桃av一区精品变态类天堂 | 欧美久久久久久久久中文字幕| 2欧美一区二区三区在线观看视频 337p粉嫩大胆噜噜噜噜噜91av | 亚洲私人影院在线观看| 久久se这里有精品| 欧美日韩色一区| 亚洲欧美视频一区| 99久久精品免费| 久久久国产精品麻豆| 久草精品在线观看| 日韩免费观看高清完整版| 亚洲国产你懂的| 欧美专区日韩专区| 亚洲品质自拍视频| 91猫先生在线| 亚洲三级小视频| av综合在线播放| 中文字幕亚洲精品在线观看 | 91一区二区三区在线观看| 国产亚洲欧洲一区高清在线观看| 日本成人在线不卡视频| 91精品视频网| 美女性感视频久久| 精品日韩在线一区| 狠狠色狠狠色综合日日91app| 日韩欧美一区二区久久婷婷| 免费观看一级特黄欧美大片| 日韩一区二区三区四区五区六区| 香蕉成人啪国产精品视频综合网| 欧美日韩中文精品| 日韩电影在线一区二区| 日韩一本二本av| 韩国毛片一区二区三区| 久久你懂得1024| 成人毛片老司机大片| 中文字幕一区二区三区视频| 色噜噜狠狠色综合中国| 亚洲激情欧美激情| 欧美激情在线看| 成人免费看的视频| 自拍偷拍欧美精品| 欧美色精品天天在线观看视频| 午夜成人免费电影| 精品国产欧美一区二区| 成人精品电影在线观看| 亚洲精品久久7777| 日韩精品中文字幕一区| 成人精品小蝌蚪| 一片黄亚洲嫩模| 91精品午夜视频| 成人一区二区三区| 亚洲午夜国产一区99re久久| 91精品国产麻豆| 成人精品视频一区二区三区尤物| 亚洲一区二区综合| 精品福利一区二区三区| 91网站黄www| 另类综合日韩欧美亚洲| 中文乱码免费一区二区| 欧美人伦禁忌dvd放荡欲情| 国产做a爰片久久毛片| 一区二区三区在线视频观看 | 天天影视涩香欲综合网| 久久综合中文字幕| 欧美主播一区二区三区美女| 韩国成人在线视频| 亚洲一区二区在线播放相泽| 精品国产乱码久久久久久闺蜜| 波多野结衣亚洲| 日本不卡一二三| 悠悠色在线精品| 久久精品欧美日韩| 91精品麻豆日日躁夜夜躁| 99久精品国产| 国产精品亚洲第一区在线暖暖韩国| 亚洲黄色在线视频| 久久综合999| 国产性天天综合网| 欧美一区二区三区免费观看视频| 成人精品视频一区| 极品销魂美女一区二区三区| 亚洲一区二区三区中文字幕| 欧美激情一区二区三区在线| 日韩午夜激情av| 在线看不卡av| 色综合中文字幕| 东方aⅴ免费观看久久av| 喷水一区二区三区| 婷婷久久综合九色国产成人 | 日韩欧美国产三级电影视频| 日本韩国一区二区| av不卡在线播放| 国产精品69毛片高清亚洲| 男人操女人的视频在线观看欧美 | 欧美色网一区二区| 色女孩综合影院| 91美女蜜桃在线| 99久久综合精品| bt欧美亚洲午夜电影天堂| 成人av资源在线观看| 丰满岳乱妇一区二区三区| 国内精品久久久久影院色| 老司机精品视频在线| 免费观看30秒视频久久| 日本一区中文字幕 | 国产精品性做久久久久久| 久久精品72免费观看| 免费成人在线视频观看| 久久精品国产99久久6| 麻豆精品久久久| 国产一区二区导航在线播放| 国产在线视频不卡二| 国产成人av电影在线| 成人综合婷婷国产精品久久蜜臀| 国产成+人+日韩+欧美+亚洲| 大尺度一区二区| 一本一道波多野结衣一区二区| 在线看国产一区| 欧美一区二区三区在线观看| 欧美va亚洲va香蕉在线| 久久久99精品免费观看不卡| 国产精品污www在线观看| 中文字幕一区不卡| 一个色妞综合视频在线观看| 午夜婷婷国产麻豆精品| 九九**精品视频免费播放| 国产精品资源站在线| 97久久精品人人做人人爽| 欧美自拍偷拍午夜视频| 日韩欧美在线网站| 国产精品午夜电影| 亚洲图片欧美综合| 精品一区二区在线视频| 国产成人在线观看| 在线观看日韩av先锋影音电影院| 欧美精品在线一区二区三区| 欧美成人一区二区三区片免费| 国产亚洲一本大道中文在线| 一区二区久久久久久| 麻豆精品国产91久久久久久| 国产成人免费av在线| 在线一区二区三区做爰视频网站| 777午夜精品免费视频| 久久久久一区二区三区四区| 中文字幕在线观看不卡| 亚洲444eee在线观看| 成人精品免费看| 欧美一级高清大全免费观看| 国产欧美日韩在线| 午夜精品久久久| 成人av资源下载| 欧美电视剧免费全集观看| 亚洲免费伊人电影| 国产一区二区三区在线观看免费| 色av成人天堂桃色av| 精品福利视频一区二区三区| 亚洲图片自拍偷拍| 丁香一区二区三区| 欧美一级xxx| 亚洲美女免费视频| 国产成人欧美日韩在线电影| 欧美日韩一区二区三区免费看| 欧美激情在线看| 久久黄色级2电影| 欧美性色aⅴ视频一区日韩精品| 久久久欧美精品sm网站 | 亚洲另类一区二区| 国产酒店精品激情| 欧美一区日本一区韩国一区| 17c精品麻豆一区二区免费| 国产一区二区在线影院| 欧美电影一区二区三区| 国产精品白丝在线| 国产69精品久久久久777| 欧美xxxxxxxx| 日本vs亚洲vs韩国一区三区 | 久久综合999| 秋霞午夜av一区二区三区| 欧美系列亚洲系列| 亚洲美女免费在线| 日本高清视频一区二区| 国产精品久久久久aaaa樱花| 黑人巨大精品欧美一区| 日韩午夜激情视频| 精品中文字幕一区二区| 日韩欧美亚洲一区二区| 另类中文字幕网| 欧美丰满美乳xxx高潮www| 亚洲成人av福利| 欧美精三区欧美精三区|