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

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

?? etharp.c

?? STR71X源代碼包括例程與各功能的源代碼
?? 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))

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
国产精品久久久久久久久快鸭| 成人黄色小视频| 欧美三级电影在线看| 国产精品1024| 亚洲成人久久影院| 成人99免费视频| 亚洲色图制服丝袜| 欧美在线观看禁18| 丝袜a∨在线一区二区三区不卡| 91美女在线视频| 婷婷国产在线综合| 国产欧美日韩三级| 色女孩综合影院| 蜜桃91丨九色丨蝌蚪91桃色| 精品国产髙清在线看国产毛片| 国产一区 二区 三区一级| 中文字幕亚洲欧美在线不卡| 在线亚洲人成电影网站色www| 成人免费一区二区三区视频| 欧美欧美欧美欧美| 成人性生交大片免费看中文网站| 中文字幕一区二区三区蜜月 | 日韩伦理av电影| 欧美日韩亚洲国产综合| 国产成人夜色高潮福利影视| 亚洲午夜国产一区99re久久| 国产精品理论在线观看| 日韩欧美电影一区| 欧美日韩中文一区| 成人黄色在线看| 国产一区二区三区在线观看免费 | 91精品国产麻豆国产自产在线| 国产成人午夜视频| 亚洲色图欧美激情| 日本一区二区三区国色天香| 欧美电视剧免费全集观看| 欧美三级电影在线观看| 成人av动漫网站| 国产九色精品成人porny | 一区二区三区不卡视频| 国产日韩三级在线| 国产日韩欧美激情| 国产欧美日韩视频一区二区| 精品成a人在线观看| 亚洲精品一区二区三区影院| 91精品国模一区二区三区| 欧美日本精品一区二区三区| 欧美日韩视频专区在线播放| 91.com视频| 精品国产123| 国产精品久久久一本精品| 亚洲欧洲av另类| 亚洲国产精品综合小说图片区| 亚洲一区二区av电影| 日韩国产一二三区| 激情成人午夜视频| 成人精品电影在线观看| 色婷婷av一区二区三区软件| 欧美在线免费视屏| 日韩你懂的电影在线观看| 久久久噜噜噜久噜久久综合| 国产精品国产自产拍在线| 亚洲综合色视频| 国产美女视频一区| 欧美专区在线观看一区| 91精品午夜视频| 中文字幕不卡三区| 免费不卡在线观看| 精品无码三级在线观看视频 | 美女视频黄免费的久久| 国产suv精品一区二区6| 欧美三级电影网| 欧美高清在线精品一区| 亚洲成av人片一区二区| 丰满少妇久久久久久久| 欧美亚州韩日在线看免费版国语版| 日韩午夜在线观看视频| 亚洲另类一区二区| 国产精品一区免费视频| 欧美色爱综合网| 国产精品免费aⅴ片在线观看| 丝袜亚洲另类欧美| 色综合色综合色综合色综合色综合| 日韩欧美一级二级三级| 一区二区高清在线| 97精品国产露脸对白| 久久综合色8888| 蜜臀91精品一区二区三区| 欧美夫妻性生活| 亚洲精品国产一区二区精华液| 国产成人aaa| 久久久久久免费网| 国产电影一区二区三区| 精品国产一区二区在线观看| 美国三级日本三级久久99| 欧美三级电影在线观看| 一区二区三区日韩| 欧美日韩专区在线| 爽好多水快深点欧美视频| 欧美一区二区三区在线视频| 日本欧美加勒比视频| 精品欧美一区二区在线观看| 另类中文字幕网| 久久免费美女视频| 不卡视频在线观看| 亚洲自拍欧美精品| 日韩欧美一区二区三区在线| 国产一区999| 亚洲精品免费在线观看| 欧美高清激情brazzers| 久草在线在线精品观看| 国产精品女人毛片| 欧美性欧美巨大黑白大战| 美女诱惑一区二区| 国产精品久久一级| 欧美精品第1页| 成人免费观看男女羞羞视频| 亚洲主播在线播放| 亚洲国产精品精华液2区45| 在线看不卡av| 国产精品亚洲成人| 日本在线不卡视频一二三区| 国产精品美女久久久久aⅴ| 色嗨嗨av一区二区三区| 美女在线一区二区| 婷婷成人综合网| 亚洲视频在线一区| 日韩限制级电影在线观看| 欧洲精品在线观看| 岛国av在线一区| 国产麻豆一精品一av一免费| 日产精品久久久久久久性色| 中文字幕色av一区二区三区| 久久免费美女视频| 欧美成人性福生活免费看| 91麻豆精品国产91久久久更新时间| 成人av手机在线观看| 国产成人免费视| 国产一区二区三区| 国产裸体歌舞团一区二区| 乱中年女人伦av一区二区| 婷婷久久综合九色综合绿巨人| 亚洲美女屁股眼交| 亚洲在线观看免费| 亚洲一区二区精品久久av| 亚洲一区二区视频| 亚洲国产精品久久久久婷婷884| 亚洲同性同志一二三专区| 国产精品久久久久久一区二区三区 | 久久久久久久综合色一本| 日韩欧美高清一区| 久久久久久久久久久久久女国产乱| 91麻豆精品国产91久久久久| 欧美成人官网二区| 中文一区一区三区高中清不卡| 国产精品久久久久久久久果冻传媒 | 色国产综合视频| 欧美日韩亚洲综合一区二区三区| 欧美日韩国产小视频| 精品国精品自拍自在线| 国产女人水真多18毛片18精品视频 | 成人免费毛片嘿嘿连载视频| 丁香桃色午夜亚洲一区二区三区| 99视频一区二区| 欧美日韩国产高清一区二区| 久久久亚洲精品石原莉奈| **网站欧美大片在线观看| 日韩av电影天堂| 成人免费视频caoporn| 日韩视频在线你懂得| 国产日韩视频一区二区三区| 午夜视频在线观看一区二区| 国产一区欧美二区| 欧美日韩一区二区三区免费看| 欧美sm美女调教| 亚洲一区二区精品3399| www.亚洲国产| 国产亚洲欧美激情| 日韩国产精品久久久久久亚洲| 欧美国产日韩一二三区| 亚洲图片欧美色图| 国产成人免费视频精品含羞草妖精| 亚洲免费在线视频一区 二区| 欧美大片一区二区三区| 国产精品免费视频网站| 久久99久久久久| 91麻豆精品久久久久蜜臀 | 欧美性三三影院| 亚洲午夜精品17c| 欧美中文字幕一二三区视频| 中文字幕一区二区三区不卡在线| 国产一区二区在线观看视频| 欧美视频你懂的| 亚洲自拍偷拍av| 欧美亚洲综合在线| 亚洲一级二级三级在线免费观看| 成人av网站在线观看免费| 国产精品美女久久久久aⅴ| 成人app软件下载大全免费| 自拍偷拍欧美精品|