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

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

?? etharp.c

?? FreeRtos Source code Version 4.04
?? C
?? 第 1 頁 / 共 3 頁
字號:
/**
 * @file
 * Address Resolution Protocol module for IP over Ethernet
 *
 * Functionally, ARP is divided into two parts. The first maps an IP address
 * to a physical address when sending a packet, and the second part answers
 * requests from other machines for our physical address.
 *
 * This implementation complies with RFC 826 (Ethernet ARP). It supports
 * Gratuitious ARP from RFC3220 (IP Mobility Support for IPv4) section 4.6
 * if an interface calls etharp_query(our_netif, its_ip_addr, NULL) upon
 * address change.
 */

/*
 * Copyright (c) 2001-2003 Swedish Institute of Computer Science.
 * Copyright (c) 2003-2004 Leon Woestenberg <leon.woestenberg@axon.tv>
 * Copyright (c) 2003-2004 Axon Digital Design B.V., The Netherlands.
 * 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.
 *
 */

#include "lwip/opt.h"
#include "lwip/inet.h"
#include "netif/etharp.h"
#include "lwip/ip.h"
#include "lwip/stats.h"

/* ARP needs to inform DHCP of any ARP replies? */
#if (LWIP_DHCP && DHCP_DOES_ARP_CHECK)
#  include "lwip/dhcp.h"
#endif

/** the time an ARP entry stays valid after its last update,
 * (240 * 5) seconds = 20 minutes.
 */
#define ARP_MAXAGE 240
/** the time an ARP entry stays pending after first request,
 * (2 * 5) seconds = 10 seconds.
 * 
 * @internal Keep this number at least 2, otherwise it might
 * run out instantly if the timeout occurs directly after a request.
 */
#define ARP_MAXPENDING 2

#define HWTYPE_ETHERNET 1

/** ARP message types */
#define ARP_REQUEST 1
#define ARP_REPLY 2

#define ARPH_HWLEN(hdr) (ntohs((hdr)->_hwlen_protolen) >> 8)
#define ARPH_PROTOLEN(hdr) (ntohs((hdr)->_hwlen_protolen) & 0xff)

#define ARPH_HWLEN_SET(hdr, len) (hdr)->_hwlen_protolen = htons(ARPH_PROTOLEN(hdr) | ((len) << 8))
#define ARPH_PROTOLEN_SET(hdr, len) (hdr)->_hwlen_protolen = htons((len) | (ARPH_HWLEN(hdr) << 8))

enum etharp_state {
  ETHARP_STATE_EMPTY,
  ETHARP_STATE_PENDING,
  ETHARP_STATE_STABLE,
  /** @internal transitional state used in etharp_tmr() for convenience*/
  ETHARP_STATE_EXPIRED
};

struct etharp_entry {
#if ARP_QUEUEING
  /** 
   * Pointer to queue of pending outgoing packets on this ARP entry.
   */
   struct pbuf *p;
#endif
  struct ip_addr ipaddr;
  struct eth_addr ethaddr;
  enum etharp_state state;
  u8_t ctime;
};

static const struct eth_addr ethbroadcast = {{0xff,0xff,0xff,0xff,0xff,0xff}};
static struct etharp_entry arp_table[ARP_TABLE_SIZE];

/**
 * Try hard to create a new entry - we want the IP address to appear in
 * the cache (even if this means removing an active entry or so). */
#define ETHARP_TRY_HARD 1

static s8_t find_entry(struct ip_addr *ipaddr, u8_t flags);
static err_t update_arp_entry(struct netif *netif, struct ip_addr *ipaddr, struct eth_addr *ethaddr, u8_t flags);
/**
 * Initializes ARP module.
 */
void
etharp_init(void)
{
  u8_t i;
  /* clear ARP entries */
  for(i = 0; i < ARP_TABLE_SIZE; ++i) {
    arp_table[i].state = ETHARP_STATE_EMPTY;
#if ARP_QUEUEING
    arp_table[i].p = NULL;
#endif
    arp_table[i].ctime = 0;
  }
}

/**
 * Clears expired entries in the ARP table.
 *
 * This function should be called every ETHARP_TMR_INTERVAL microseconds (5 seconds),
 * in order to expire entries in the ARP table.
 */
void
etharp_tmr(void)
{
  u8_t i;

  LWIP_DEBUGF(ETHARP_DEBUG, ("etharp_timer\n"));
  /* remove expired entries from the ARP table */
  for (i = 0; i < ARP_TABLE_SIZE; ++i) {
    arp_table[i].ctime++;
    /* stable entry? */
    if ((arp_table[i].state == ETHARP_STATE_STABLE) &&
         /* entry has become old? */
        (arp_table[i].ctime >= ARP_MAXAGE)) {
      LWIP_DEBUGF(ETHARP_DEBUG, ("etharp_timer: expired stable entry %u.\n", i));
      arp_table[i].state = ETHARP_STATE_EXPIRED;
    /* pending entry? */
    } else if (arp_table[i].state == ETHARP_STATE_PENDING) {
      /* entry unresolved/pending for too long? */
      if (arp_table[i].ctime >= ARP_MAXPENDING) {
        LWIP_DEBUGF(ETHARP_DEBUG, ("etharp_timer: expired pending entry %u.\n", i));
        arp_table[i].state = ETHARP_STATE_EXPIRED;
#if ARP_QUEUEING
      } else if (arp_table[i].p != NULL) {
        /* resend an ARP query here */
#endif
      }
    }
    /* clean up entries that have just been expired */
    if (arp_table[i].state == ETHARP_STATE_EXPIRED) {
#if ARP_QUEUEING
      /* and empty packet queue */
      if (arp_table[i].p != NULL) {
        /* remove all queued packets */
        LWIP_DEBUGF(ETHARP_DEBUG, ("etharp_timer: freeing entry %u, packet queue %p.\n", i, (void *)(arp_table[i].p)));
        pbuf_free(arp_table[i].p);
        arp_table[i].p = NULL;
      }
#endif
      /* recycle entry for re-use */      
      arp_table[i].state = ETHARP_STATE_EMPTY;
    }
  }
}

/**
 * Search the ARP table for a matching or new entry.
 * 
 * If an IP address is given, return a pending or stable ARP entry that matches
 * the address. If no match is found, create a new entry with this address set,
 * but in state ETHARP_EMPTY. The caller must check and possibly change the
 * state of the returned entry.
 * 
 * If ipaddr is NULL, return a initialized new entry in state ETHARP_EMPTY.
 * 
 * In all cases, attempt to create new entries from an empty entry. If no
 * empty entries are available and ETHARP_TRY_HARD flag is set, recycle
 * old entries. Heuristic choose the least important entry for recycling.
 *
 * @param ipaddr IP address to find in ARP cache, or to add if not found.
 * @param flags
 * - ETHARP_TRY_HARD: Try hard to create a entry by allowing recycling of
 * active (stable or pending) entries.
 *  
 * @return The ARP entry index that matched or is created, ERR_MEM if no
 * entry is found or could be recycled.
 */
static s8_t find_entry(struct ip_addr *ipaddr, u8_t flags)
{
  s8_t old_pending = ARP_TABLE_SIZE, old_stable = ARP_TABLE_SIZE;
  s8_t empty = ARP_TABLE_SIZE;
  u8_t i = 0, age_pending = 0, age_stable = 0;
#if ARP_QUEUEING
  /* oldest entry with packets on queue */
  s8_t old_queue = ARP_TABLE_SIZE;
  /* its age */
  u8_t age_queue = 0;
#endif

  /**
   * a) do a search through the cache, remember candidates
   * b) select candidate entry
   * c) create new entry
   */

  /* a) in a single search sweep, do all of this
   * 1) remember the first empty entry (if any)
   * 2) remember the oldest stable entry (if any)
   * 3) remember the oldest pending entry without queued packets (if any)
   * 4) remember the oldest pending entry with queued packets (if any)
   * 5) search for a matching IP entry, either pending or stable
   *    until 5 matches, or all entries are searched for.
   */

  for (i = 0; i < ARP_TABLE_SIZE; ++i) {
    /* no empty entry found yet and now we do find one? */
    if ((empty == ARP_TABLE_SIZE) && (arp_table[i].state == ETHARP_STATE_EMPTY)) {
      LWIP_DEBUGF(ETHARP_DEBUG, ("find_entry: found empty entry %d\n", i));
      /* remember first empty entry */
      empty = i;
    }
    /* pending entry? */
    else if (arp_table[i].state == ETHARP_STATE_PENDING) {
      /* if given, does IP address match IP address in ARP entry? */
      if (ipaddr && ip_addr_cmp(ipaddr, &arp_table[i].ipaddr)) {
        LWIP_DEBUGF(ETHARP_DEBUG | DBG_TRACE, ("find_entry: found matching pending entry %d\n", i));
        /* found exact IP address match, simply bail out */
        return i;
#if ARP_QUEUEING
      /* pending with queued packets? */
      } else if (arp_table[i].p != NULL) {
        if (arp_table[i].ctime >= age_queue) {
          old_queue = i;
          age_queue = arp_table[i].ctime;
        }
#endif
      /* pending without queued packets? */
      } else {
        if (arp_table[i].ctime >= age_pending) {
          old_pending = i;
          age_pending = arp_table[i].ctime;
        }
      }        
    }
    /* stable entry? */
    else if (arp_table[i].state == ETHARP_STATE_STABLE) {
      /* if given, does IP address match IP address in ARP entry? */
      if (ipaddr && ip_addr_cmp(ipaddr, &arp_table[i].ipaddr)) {
        LWIP_DEBUGF(ETHARP_DEBUG | DBG_TRACE, ("find_entry: found matching stable entry %d\n", i));
        /* found exact IP address match, simply bail out */
        return i;
      /* remember entry with oldest stable entry in oldest, its age in maxtime */
      } else if (arp_table[i].ctime >= age_stable) {
        old_stable = i;
        age_stable = arp_table[i].ctime;
      }
    }
  }
  /* { we have no match } => try to create a new entry */
   
  /* no empty entry found and not allowed to recycle? */
  if ((empty == ARP_TABLE_SIZE) && ((flags & ETHARP_TRY_HARD) == 0))
  {

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
国产一区在线看| 亚洲欧美在线视频观看| 久久久久国产免费免费| 综合婷婷亚洲小说| 久久精品国产精品亚洲精品| 丰满少妇久久久久久久| 欧美一区二区三区四区视频 | 久久色.com| 一区二区三区成人| 亚洲丶国产丶欧美一区二区三区| 亚洲久本草在线中文字幕| 精品欧美久久久| 一区二区三区成人| 国产精品亚洲一区二区三区在线| 一本色道久久加勒比精品| 日韩一区二区不卡| 亚洲小说欧美激情另类| 成人av免费观看| 精品国产乱码久久久久久免费| 亚洲一区二区三区四区在线观看 | 亚洲一区二区三区在线看| 国产高清在线精品| 日韩欧美第一区| 亚洲1区2区3区视频| 99re在线视频这里只有精品| 久久亚洲免费视频| 黄页视频在线91| 精品国产露脸精彩对白| 麻豆久久久久久| 91精品国产欧美一区二区| 一区二区三区四区精品在线视频| 国产一本一道久久香蕉| 精品久久久久久久久久久久久久久 | 国产精品久久久久三级| 国产又粗又猛又爽又黄91精品| 制服丝袜亚洲色图| 日韩在线一区二区三区| 欧美疯狂性受xxxxx喷水图片| 亚洲国产一区视频| 欧美日韩一区二区在线观看 | 波多野结衣在线aⅴ中文字幕不卡| 7777精品伊人久久久大香线蕉| 一区二区三区免费| 在线中文字幕一区二区| 亚洲天堂av一区| 色综合一区二区三区| 亚洲一区在线免费观看| 欧美在线制服丝袜| 五月婷婷欧美视频| 在线播放91灌醉迷j高跟美女 | 精品sm在线观看| 国产麻豆精品在线观看| 国产人成一区二区三区影院| 国产成+人+日韩+欧美+亚洲| 国产日韩精品一区二区三区| www.一区二区| 午夜精品福利久久久| 欧美疯狂性受xxxxx喷水图片| 日本欧美肥老太交大片| 337p亚洲精品色噜噜噜| 国产在线观看免费一区| 国产农村妇女精品| 欧美丝袜丝交足nylons| 青椒成人免费视频| 久久免费视频一区| 91女人视频在线观看| 亚洲妇女屁股眼交7| 亚洲精品一区二区精华| www.在线成人| 肉色丝袜一区二区| 久久天天做天天爱综合色| 97se亚洲国产综合自在线观| 三级久久三级久久| 欧美高清在线视频| 在线成人免费视频| 成人午夜私人影院| 日韩综合小视频| 国产精品色在线观看| 欧美日韩高清一区二区| 岛国精品在线播放| 蜜臀av性久久久久av蜜臀妖精| 国产精品毛片久久久久久| 91精品国产综合久久精品麻豆| 国产精品一品视频| 日韩精品欧美成人高清一区二区| 久久久噜噜噜久久中文字幕色伊伊 | 欧美性色综合网| 国产v综合v亚洲欧| 日产国产欧美视频一区精品 | 26uuu精品一区二区三区四区在线| www.亚洲色图.com| 韩国成人精品a∨在线观看| 亚洲国产视频网站| 亚洲欧美国产三级| 国产日韩精品一区| 精品国产乱码久久久久久闺蜜 | 欧美国产1区2区| 精品久久久三级丝袜| 欧美日韩亚洲国产综合| 91免费观看视频在线| 国产sm精品调教视频网站| 看片的网站亚洲| 日本亚洲天堂网| 首页综合国产亚洲丝袜| 一个色综合网站| 中文字幕中文字幕一区| 国产色一区二区| 久久久久久久久97黄色工厂| 日韩限制级电影在线观看| 欧美日本一区二区在线观看| 欧美午夜一区二区三区| 91麻豆精东视频| 色哟哟日韩精品| 91久久精品一区二区二区| 91蜜桃网址入口| 97超碰欧美中文字幕| 一本久道久久综合中文字幕| 99精品视频在线播放观看| aaa国产一区| 色综合久久天天综合网| 日本韩国精品在线| 日本精品裸体写真集在线观看| 91国偷自产一区二区使用方法| 97久久精品人人澡人人爽| 一本大道久久a久久综合| 色屁屁一区二区| 欧美日韩免费一区二区三区视频| 欧美日韩成人综合天天影院| 欧美日韩精品免费观看视频| 欧美日韩一区在线观看| 7777精品伊人久久久大香线蕉超级流畅 | 日韩女优制服丝袜电影| 精品久久一区二区三区| 久久久精品免费免费| 欧美国产精品一区| 亚洲欧美日韩一区二区三区在线观看| 亚洲欧洲99久久| 亚洲自拍偷拍综合| 日本人妖一区二区| 国产精品久久一卡二卡| 一区二区三区中文字幕精品精品| 亚洲激情中文1区| 免费精品视频在线| 国产成人激情av| 欧美性xxxxx极品少妇| 日韩一区二区三区视频| 国产亚洲va综合人人澡精品| 国产精品成人免费在线| 天天操天天干天天综合网| 国产综合色产在线精品| 成人影视亚洲图片在线| 欧美日韩久久一区| 成人深夜福利app| 欧美三级视频在线播放| 久久综合九色综合97婷婷女人 | 日韩毛片在线免费观看| 日韩精品每日更新| yourporn久久国产精品| 欧美一级精品在线| 中文字幕在线一区| 精品一区二区三区在线播放 | 欧美剧在线免费观看网站| 精品一区二区三区免费视频| 99久久国产综合精品色伊| 欧美一区二区免费视频| 亚洲欧美一区二区三区久本道91 | 欧美日韩中文一区| 欧美国产亚洲另类动漫| 日韩一区欧美二区| 成人h精品动漫一区二区三区| 欧美另类z0zxhd电影| 中文字幕视频一区二区三区久| 日韩免费高清av| 亚洲永久免费av| aaa欧美日韩| 国产情人综合久久777777| 日韩国产欧美在线视频| 色天使久久综合网天天| 中文字幕免费不卡在线| 精品中文字幕一区二区| 精品污污网站免费看| 中文字幕国产一区| 国产老肥熟一区二区三区| 7777精品伊人久久久大香线蕉完整版| 中文字幕亚洲区| 成人一区在线看| 成人h精品动漫一区二区三区| 日韩三级中文字幕| 丝袜诱惑制服诱惑色一区在线观看| av在线播放不卡| 欧美国产在线观看| 国产高清不卡一区二区| 精品国产乱码久久久久久免费| 免费成人在线网站| 日韩视频一区二区三区 | 奇米一区二区三区av| 欧美喷潮久久久xxxxx| 一区二区三区色| 99久久99精品久久久久久| 国产精品天干天干在线综合|