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

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

?? udp.c

?? ARM7的一些試驗程序
?? C
?? 第 1 頁 / 共 2 頁
字號:
/**
 * @file
 * User Datagram Protocol module
 *
 */
/*
 * 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>
 *
 */


/* udp.c
 *
 * The code for the User Datagram Protocol UDP.
 *
 */

#include <string.h>

#include "lwip/opt.h"

#include "lwip/def.h"
#include "lwip/memp.h"
#include "lwip/inet.h"
#include "lwip/ip_addr.h"
#include "lwip/netif.h"
#include "lwip/udp.h"
#include "lwip/icmp.h"

#include "lwip/stats.h"

#include "arch/perf.h"
#include "lwip/snmp.h"

/* The list of UDP PCBs */
#if LWIP_UDP
/* was static, but we may want to access this from a socket layer */
struct udp_pcb *udp_pcbs = NULL;

static struct udp_pcb *pcb_cache = NULL;


void
udp_init(void)
{
  udp_pcbs = pcb_cache = NULL;
}

/**
 * Process an incoming UDP datagram.
 *
 * Given an incoming UDP datagram (as a chain of pbufs) this function
 * finds a corresponding UDP PCB and
 *
 * @param pbuf pbuf to be demultiplexed to a UDP PCB.
 * @param netif network interface on which the datagram was received.
 *
 */
void
udp_input(struct pbuf *p, struct netif *inp)
{
  struct udp_hdr *udphdr;
  struct udp_pcb *pcb;
  struct ip_hdr *iphdr;
  u16_t src, dest;

#if SO_REUSE
  struct udp_pcb *pcb_temp;
  int reuse = 0;
  int reuse_port_1 = 0;
  int reuse_port_2 = 0;
#endif /* SO_REUSE */
  
  PERF_START;

  UDP_STATS_INC(udp.recv);

  iphdr = p->payload;

  if (pbuf_header(p, -((s16_t)(UDP_HLEN + IPH_HL(iphdr) * 4)))) {
    /* drop short packets */
    LWIP_DEBUGF(UDP_DEBUG, ("udp_input: short UDP datagram (%u bytes) discarded\n", p->tot_len));
    UDP_STATS_INC(udp.lenerr);
    UDP_STATS_INC(udp.drop);
    snmp_inc_udpinerrors();
    pbuf_free(p);
    goto end;
  }

  udphdr = (struct udp_hdr *)((u8_t *)p->payload - UDP_HLEN);

  LWIP_DEBUGF(UDP_DEBUG, ("udp_input: received datagram of length %u\n", p->tot_len));

  src = ntohs(udphdr->src);
  dest = ntohs(udphdr->dest);

  udp_debug_print(udphdr);

  /* print the UDP source and destination */
  LWIP_DEBUGF(UDP_DEBUG, ("udp (%u.%u.%u.%u, %u) <-- (%u.%u.%u.%u, %u)\n",
    ip4_addr1(&iphdr->dest), ip4_addr2(&iphdr->dest),
    ip4_addr3(&iphdr->dest), ip4_addr4(&iphdr->dest), ntohs(udphdr->dest),
    ip4_addr1(&iphdr->src), ip4_addr2(&iphdr->src),
    ip4_addr3(&iphdr->src), ip4_addr4(&iphdr->src), ntohs(udphdr->src)));

#if SO_REUSE
  pcb_temp = udp_pcbs;
  
 again_1:
  
  /* Iterate through the UDP pcb list for a fully matching pcb */
  for (pcb = pcb_temp; pcb != NULL; pcb = pcb->next) {
#else  /* SO_REUSE */ 
  /* Iterate through the UDP pcb list for a fully matching pcb */
  for (pcb = udp_pcbs; pcb != NULL; pcb = pcb->next) {
#endif  /* SO_REUSE */ 
    /* print the PCB local and remote address */
    LWIP_DEBUGF(UDP_DEBUG, ("pcb (%u.%u.%u.%u, %u) --- (%u.%u.%u.%u, %u)\n",
      ip4_addr1(&pcb->local_ip), ip4_addr2(&pcb->local_ip),
      ip4_addr3(&pcb->local_ip), ip4_addr4(&pcb->local_ip), pcb->local_port,
      ip4_addr1(&pcb->remote_ip), ip4_addr2(&pcb->remote_ip),
      ip4_addr3(&pcb->remote_ip), ip4_addr4(&pcb->remote_ip), pcb->remote_port));

       /* PCB remote port matches UDP source port? */
    if ((pcb->remote_port == src) &&
       /* PCB local port matches UDP destination port? */
       (pcb->local_port == dest) &&
       /* accepting from any remote (source) IP address? or... */
       (ip_addr_isany(&pcb->remote_ip) ||
       /* PCB remote IP address matches UDP source IP address? */
        ip_addr_cmp(&(pcb->remote_ip), &(iphdr->src))) &&
       /* accepting on any local (netif) IP address? or... */
       (ip_addr_isany(&pcb->local_ip) ||
       /* PCB local IP address matches UDP destination IP address? */
        ip_addr_cmp(&(pcb->local_ip), &(iphdr->dest)))) {
#if SO_REUSE
      if (pcb->so_options & SOF_REUSEPORT) {
        if(reuse) {
          /* We processed one PCB already */
          LWIP_DEBUGF(UDP_DEBUG, ("udp_input: second or later PCB and SOF_REUSEPORT set.\n"));
        } else {
          /* First PCB with this address */
          LWIP_DEBUGF(UDP_DEBUG, ("udp_input: first PCB and SOF_REUSEPORT set.\n"));
          reuse = 1;
        }
        
        reuse_port_1 = 1; 
        p->ref++;
        LWIP_DEBUGF(UDP_DEBUG, ("udp_input: reference counter on PBUF set to %i\n", p->ref));
      } else {
        if (reuse) {
          /* We processed one PCB already */
          LWIP_DEBUGF(UDP_DEBUG, ("udp_input: second or later PCB but SOF_REUSEPORT not set !\n"));
        }
      }
#endif /* SO_REUSE */
      break;
    }
  }
  /* no fully matching pcb found? then look for an unconnected pcb */
  if (pcb == NULL) {
    /* Iterate through the UDP PCB list for a pcb that matches
       the local address. */

#if SO_REUSE
    pcb_temp = udp_pcbs;
    
  again_2:

    for (pcb = pcb_temp; pcb != NULL; pcb = pcb->next) {
#else  /* SO_REUSE */ 
    for (pcb = udp_pcbs; pcb != NULL; pcb = pcb->next) {
#endif  /* SO_REUSE */ 
      LWIP_DEBUGF(UDP_DEBUG, ("pcb (%u.%u.%u.%u, %u) --- (%u.%u.%u.%u, %u)\n",
        ip4_addr1(&pcb->local_ip), ip4_addr2(&pcb->local_ip),
        ip4_addr3(&pcb->local_ip), ip4_addr4(&pcb->local_ip), pcb->local_port,
        ip4_addr1(&pcb->remote_ip), ip4_addr2(&pcb->remote_ip),
        ip4_addr3(&pcb->remote_ip), ip4_addr4(&pcb->remote_ip), pcb->remote_port));
      /* unconnected? */
      if (((pcb->flags & UDP_FLAGS_CONNECTED) == 0) &&
         /* destination port matches? */
        (pcb->local_port == dest) &&
        /* not bound to a specific (local) interface address? or... */
        (ip_addr_isany(&pcb->local_ip) ||
        /* ...matching interface address? */
        ip_addr_cmp(&(pcb->local_ip), &(iphdr->dest)))) {
#if SO_REUSE
        if (pcb->so_options & SOF_REUSEPORT) {
          if (reuse) {
            /* We processed one PCB already */
            LWIP_DEBUGF(UDP_DEBUG, ("udp_input: second or later PCB and SOF_REUSEPORT set.\n"));
          } else {
            /* First PCB with this address */
            LWIP_DEBUGF(UDP_DEBUG, ("udp_input: first PCB and SOF_REUSEPORT set.\n"));
            reuse = 1;
          }
          
          reuse_port_2 = 1; 
          p->ref++;
          LWIP_DEBUGF(UDP_DEBUG, ("udp_input: reference counter on PBUF set to %i\n", p->ref));
        } else {
          if (reuse) {
            /* We processed one PCB already */
            LWIP_DEBUGF(UDP_DEBUG, ("udp_input: second or later PCB but SOF_REUSEPORT not set !\n"));
          }
        }
#endif /* SO_REUSE */
        break;
      }
    }
  }

  /* Check checksum if this is a match or if it was directed at us. */
  if (pcb != NULL  || ip_addr_cmp(&inp->ip_addr, &iphdr->dest))
    {
    LWIP_DEBUGF(UDP_DEBUG | DBG_TRACE, ("udp_input: calculating checksum\n"));
    pbuf_header(p, UDP_HLEN);
#ifdef IPv6
    if (iphdr->nexthdr == IP_PROTO_UDPLITE) {
#else
    if (IPH_PROTO(iphdr) == IP_PROTO_UDPLITE) {
#endif /* IPv4 */
      /* Do the UDP Lite checksum */
#if CHECKSUM_CHECK_UDP
      if (inet_chksum_pseudo(p, (struct ip_addr *)&(iphdr->src),
         (struct ip_addr *)&(iphdr->dest),
         IP_PROTO_UDPLITE, ntohs(udphdr->len)) != 0) {
  LWIP_DEBUGF(UDP_DEBUG | 2, ("udp_input: UDP Lite datagram discarded due to failing checksum\n"));
  UDP_STATS_INC(udp.chkerr);
  UDP_STATS_INC(udp.drop);
  snmp_inc_udpinerrors();
  pbuf_free(p);
  goto end;
      }
#endif
    } else {
#if CHECKSUM_CHECK_UDP
      if (udphdr->chksum != 0) {
  if (inet_chksum_pseudo(p, (struct ip_addr *)&(iphdr->src),
       (struct ip_addr *)&(iphdr->dest),
        IP_PROTO_UDP, p->tot_len) != 0) {
    LWIP_DEBUGF(UDP_DEBUG | 2, ("udp_input: UDP datagram discarded due to failing checksum\n"));

    UDP_STATS_INC(udp.chkerr);
    UDP_STATS_INC(udp.drop);
    snmp_inc_udpinerrors();
    pbuf_free(p);
    goto end;
  }
      }
#endif
    }
    pbuf_header(p, -UDP_HLEN);
    if (pcb != NULL) {
      snmp_inc_udpindatagrams();
      pcb->recv(pcb->recv_arg, pcb, p, &(iphdr->src), src);
#if SO_REUSE
      /* First socket should receive now */
      if(reuse_port_1 || reuse_port_2) {
        /* We want to search on next socket after receiving */
        pcb_temp = pcb->next;
        
        if(reuse_port_1) {
          /* We are searching connected sockets */
          reuse_port_1 = 0;
          reuse_port_2 = 0;
          goto again_1;
        } else {
          /* We are searching unconnected sockets */
          reuse_port_1 = 0;
          reuse_port_2 = 0;
          goto again_2;
        }
      }
#endif /* SO_REUSE */ 
    } else {
#if SO_REUSE
      if(reuse) {
        LWIP_DEBUGF(UDP_DEBUG, ("udp_input: freeing PBUF with reference counter set to %i\n", p->ref));
        pbuf_free(p);
        goto end;
      }
#endif /* SO_REUSE */
      LWIP_DEBUGF(UDP_DEBUG | DBG_TRACE, ("udp_input: not for us.\n"));

      /* No match was found, send ICMP destination port unreachable unless
      destination address was broadcast/multicast. */

      if (!ip_addr_isbroadcast(&iphdr->dest, inp) &&
          !ip_addr_ismulticast(&iphdr->dest)) {

  /* adjust pbuf pointer */
  p->payload = iphdr;
  icmp_dest_unreach(p, ICMP_DUR_PORT);
      }
      UDP_STATS_INC(udp.proterr);
      UDP_STATS_INC(udp.drop);
    snmp_inc_udpnoports();
      pbuf_free(p);
    }
  } else {
    pbuf_free(p);
  }
  end:

  PERF_STOP("udp_input");
}

/**
 * Send data to a specified address using UDP.
 *
 * @param pcb UDP PCB used to send the data.
 * @param pbuf chain of pbuf's to be sent.
 * @param dst_ip Destination IP address.
 * @param dst_port Destination UDP port.
 *
 * If the PCB already has a remote address association, it will
 * be restored after the data is sent.
 * 
 * @return lwIP error code.
 * - ERR_OK. Successful. No error occured.
 * - ERR_MEM. Out of memory.
 * - ERR_RTE. Could not find route to destination address.
 *
 * @see udp_disconnect() udp_send()
 */
err_t
udp_sendto(struct udp_pcb *pcb, struct pbuf *p,
  struct ip_addr *dst_ip, u16_t dst_port)
{
  err_t err;
  /* temporary space for current PCB remote address */
  struct ip_addr pcb_remote_ip;
  u16_t pcb_remote_port;
  /* remember current remote peer address of PCB */
  pcb_remote_ip.addr = pcb->remote_ip.addr;
  pcb_remote_port = pcb->remote_port;
  /* copy packet destination address to PCB remote peer address */
  pcb->remote_ip.addr = dst_ip->addr;
  pcb->remote_port = dst_port;
  /* send to the packet destination address */
  err = udp_send(pcb, p);
  /* restore PCB remote peer address */
  pcb->remote_ip.addr = pcb_remote_ip.addr;
  pcb->remote_port = pcb_remote_port;
  return err;
}

/**
 * Send data using UDP.
 *
 * @param pcb UDP PCB used to send the data.
 * @param pbuf chain of pbuf's to be sent.
 *
 * @return lwIP error code.
 * - ERR_OK. Successful. No error occured.
 * - ERR_MEM. Out of memory.
 * - ERR_RTE. Could not find route to destination address.
 *
 * @see udp_disconnect() udp_sendto()
 */
err_t
udp_send(struct udp_pcb *pcb, struct pbuf *p)
{
  struct udp_hdr *udphdr;
  struct netif *netif;
  struct ip_addr *src_ip;
  err_t err;
  struct pbuf *q; /* q will be sent down the stack */

  LWIP_DEBUGF(UDP_DEBUG | DBG_TRACE | 3, ("udp_send\n"));

  /* if the PCB is not yet bound to a port, bind it here */
  if (pcb->local_port == 0) {

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
五月婷婷久久综合| 老司机午夜精品| 日本sm残虐另类| 精品写真视频在线观看| 91免费国产在线| 精品国产a毛片| 亚洲成人www| 成人va在线观看| 精品91自产拍在线观看一区| 亚洲午夜久久久久| www.亚洲精品| 久久在线免费观看| 亚洲成精国产精品女| 99精品在线观看视频| wwwwxxxxx欧美| 日韩中文字幕亚洲一区二区va在线| 大桥未久av一区二区三区中文| 欧美午夜不卡在线观看免费| 国产精品美女久久久久aⅴ| 韩国成人精品a∨在线观看| 在线不卡免费欧美| 午夜精品一区在线观看| 91老司机福利 在线| 久久五月婷婷丁香社区| 亚洲h精品动漫在线观看| 成人激情av网| www久久精品| 午夜视频一区二区三区| 成人国产精品免费| 2023国产精品| 国产午夜精品一区二区三区视频| 午夜日韩在线观看| 91女神在线视频| 国产调教视频一区| 国内成人精品2018免费看| 欧美日韩国产另类不卡| 亚洲欧美日韩中文播放| 国产成人免费视频一区| 日韩欧美高清一区| 亚洲午夜成aⅴ人片| 懂色中文一区二区在线播放| 欧美大片免费久久精品三p| 无码av中文一区二区三区桃花岛| 99re8在线精品视频免费播放| 久久久久9999亚洲精品| 精品一区中文字幕| 日韩欧美色综合| 日本美女视频一区二区| 99久久99久久精品免费观看| 久久伊人中文字幕| 免费观看30秒视频久久| 26uuu精品一区二区三区四区在线| 免费高清在线一区| 日韩精品一区二区三区中文精品 | 91激情五月电影| 国产精品嫩草99a| 国产91丝袜在线18| 欧美韩国日本一区| 成人av在线资源网站| 国产精品日产欧美久久久久| www.成人网.com| 亚洲欧美日韩一区二区 | 久久亚洲综合色| 裸体歌舞表演一区二区| 精品久久久网站| 狠狠色狠狠色综合系列| 国产亚洲欧美日韩日本| 成人国产精品视频| 亚洲精品伦理在线| 欧美人与禽zozo性伦| 蜜桃av一区二区三区电影| 欧美精品一区男女天堂| 成人小视频在线| 中文字幕第一区二区| 成人在线综合网站| 最新国产精品久久精品| 欧美日韩一区二区三区四区| 秋霞午夜av一区二区三区| 亚洲精品在线观看视频| 成人免费毛片aaaaa**| 亚洲免费在线播放| 日韩一区二区三区免费看 | 亚洲综合激情另类小说区| 欧美视频一区二区在线观看| 日韩电影在线免费| 国产亚洲精品7777| 在线视频一区二区三区| 亚洲成人一二三| 久久一区二区三区四区| 91福利小视频| 激情小说欧美图片| 国产精品久久久久久久久动漫| 日本道色综合久久| 久久国产剧场电影| 中文字幕字幕中文在线中不卡视频| 欧洲国内综合视频| 国产精品一品二品| 性欧美大战久久久久久久久| 国产欧美日韩卡一| 91精品国产综合久久久久久| 成人性生交大片免费| 亚洲国产欧美另类丝袜| 日韩女优毛片在线| 欧美精品久久久久久久久老牛影院| 国产在线视频精品一区| 午夜精品成人在线| 亚洲欧美偷拍卡通变态| 国产午夜精品久久久久久免费视| 精品视频1区2区3区| 不卡在线视频中文字幕| 精品亚洲成a人| 一区二区三区精品视频| 国产欧美日韩在线| xfplay精品久久| 欧美一卡二卡三卡四卡| 欧美性色黄大片| 成人精品视频一区| 国产成人在线网站| 麻豆精品国产传媒mv男同| 亚洲国产中文字幕| 亚洲女与黑人做爰| 国产精品电影院| 国产日产欧美一区二区视频| 日韩精品中午字幕| 欧美日韩综合在线免费观看| 国产91精品一区二区麻豆亚洲| 日韩精品一二三区| 亚洲成人一二三| 一区二区三区久久久| 亚洲黄网站在线观看| 成人欧美一区二区三区1314 | 午夜成人免费视频| 亚洲精品老司机| 中文字幕字幕中文在线中不卡视频| 久久精品夜色噜噜亚洲aⅴ| 亚洲精品在线观看视频| 精品区一区二区| wwww国产精品欧美| 国产女主播视频一区二区| 国产拍揄自揄精品视频麻豆| 国产亚洲一区二区三区四区| 日韩精品一区二区三区视频| 色婷婷综合久色| 欧美性感一类影片在线播放| 欧日韩精品视频| 欧美日韩一区高清| 欧美日本韩国一区二区三区视频| 欧美电影免费提供在线观看| 欧美va亚洲va香蕉在线| 欧美变态tickle挠乳网站| 欧美成人r级一区二区三区| 日韩视频国产视频| 久久久久国色av免费看影院| 国产日本一区二区| 亚洲欧美日韩电影| 无吗不卡中文字幕| 捆绑紧缚一区二区三区视频| 国产一区二区伦理片| 国产成人av影院| 99re6这里只有精品视频在线观看| 色综合色综合色综合色综合色综合| 色悠悠亚洲一区二区| 91丨porny丨蝌蚪视频| 91丨九色丨尤物| 欧美日韩国产a| 亚洲精品一区二区三区在线观看| 国产精品素人一区二区| 亚洲电影一区二区三区| 国内精品国产成人国产三级粉色| 国产99久久久国产精品| 色999日韩国产欧美一区二区| 欧美丰满一区二区免费视频| 久久先锋影音av鲁色资源| 日韩美女啊v在线免费观看| 天堂影院一区二区| 岛国精品在线观看| 欧美日韩二区三区| 国产亚洲va综合人人澡精品| 伊人开心综合网| 国产精品影视在线| av不卡在线播放| 91精品国产色综合久久ai换脸| 亚洲欧美日韩一区二区三区在线观看| 日韩精品高清不卡| 91亚洲精品乱码久久久久久蜜桃| 欧美高清www午色夜在线视频| 国产精品无码永久免费888| 天天色天天操综合| 99这里都是精品| 欧美成人精品1314www| 亚洲一区二区三区四区的| 国产乱淫av一区二区三区| 欧美日韩国产系列| 亚洲天堂福利av| 国产精品69毛片高清亚洲| 欧美日本国产一区| 樱桃视频在线观看一区| 大白屁股一区二区视频| 精品福利一二区| 日本欧美大码aⅴ在线播放|