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

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

?? etharp.c

?? 一個輕量tcpip協議在移植在ucOS2系統上運行
?? C
?? 第 1 頁 / 共 2 頁
字號:
/**
 * @file
 * Address Resolution Protocol module for IP over Ethernet
 *
 */

/*
 * Copyright (c) 2001-2003 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>
 *
 */
 
/*
 * TODO:
 *
RFC 3220 4.6          IP Mobility Support for IPv4          January 2002 

      -  A Gratuitous ARP [45] is an ARP packet sent by a node in order 
         to spontaneously cause other nodes to update an entry in their 
         ARP cache.  A gratuitous ARP MAY use either an ARP Request or 
         an ARP Reply packet.  In either case, the ARP Sender Protocol 
         Address and ARP Target Protocol Address are both set to the IP 
         address of the cache entry to be updated, and the ARP Sender 
         Hardware Address is set to the link-layer address to which this 
         cache entry should be updated.  When using an ARP Reply packet, 
         the Target Hardware Address is also set to the link-layer 
         address to which this cache entry should be updated (this field 
         is not used in an ARP Request packet). 

         In either case, for a gratuitous ARP, the ARP packet MUST be 
         transmitted as a local broadcast packet on the local link.  As 
         specified in [36], any node receiving any ARP packet (Request 
         or Reply) MUST update its local ARP cache with the Sender 
         Protocol and Hardware Addresses in the ARP packet, if the 
         receiving node has an entry for that IP address already in its 
         ARP cache.  This requirement in the ARP protocol applies even 
         for ARP Request packets, and for ARP Reply packets that do not 
         match any ARP Request transmitted by the receiving node [36]. 
*
  My suggestion would be to send a ARP request for our newly obtained
  address upon configuration of an Ethernet interface.

*/

#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, (120 * 10) seconds = 20 minutes. */
#define ARP_MAXAGE 120  
/** the time an ARP entry stays pending after first request, (2 * 10) seconds = 20 seconds. */
#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
};

struct etharp_entry {
  struct ip_addr ipaddr;
  struct eth_addr ethaddr;
  enum etharp_state state;
#if ARP_QUEUEING
  struct pbuf *p;
#endif
  u8_t ctime;
};

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

static struct pbuf *update_arp_entry(struct netif *netif, struct ip_addr *ipaddr, struct eth_addr *ethaddr, u8_t flags);
#define ARP_INSERT_FLAG 1

/**
 * 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
  }
}

/**
 * Clears expired entries in the ARP table.
 *
 * This function should be called every ETHARP_TMR_INTERVAL microseconds (10 seconds),
 * in order to expire entries in the ARP table.
 */
void
etharp_tmr(void)
{
  u8_t i;
  
  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++;	  
    if((arp_table[i].state == ETHARP_STATE_STABLE) &&       
       (arp_table[i].ctime >= ARP_MAXAGE)) {
      DEBUGF(ETHARP_DEBUG, ("etharp_timer: expired stable entry %u.\n", i));
      arp_table[i].state = ETHARP_STATE_EMPTY;
#if ARP_QUEUEING
      /* remove any queued packet */
      pbuf_free(arp_table[i].p);      
      arp_table[i].p = NULL;
#endif
    } else if((arp_table[i].state == ETHARP_STATE_PENDING) &&
	      (arp_table[i].ctime >= ARP_MAXPENDING)) {
      arp_table[i].state = ETHARP_STATE_EMPTY;
#if ARP_QUEUEING
      DEBUGF(ETHARP_DEBUG, ("etharp_timer: expired pending entry %u - dequeueing %p.\n", i, (void *)(arp_table[i].p)));
      /* remove any queued packet */
      pbuf_free(arp_table[i].p);      
      arp_table[i].p = NULL;
#else
      DEBUGF(ETHARP_DEBUG, ("etharp_timer: expired pending entry %u.\n", i));
#endif
    }
  }  
}

/**
 * Return an empty ARP entry or, if the table is full, ARP_TABLE_SIZE if all
 * entries are pending, otherwise the oldest entry.
 *
 * @return The ARP entry index that is available, ARP_TABLE_SIZE if no usable
 * entry is found.
 */
static u8_t
find_arp_entry(void)
{
  u8_t i, j, maxtime;
  
  /* Try to find an unused entry in the ARP table. */
  for(i = 0; i < ARP_TABLE_SIZE; ++i) {
    if(arp_table[i].state == ETHARP_STATE_EMPTY) {
      DEBUGF(ETHARP_DEBUG, ("find_arp_entry: found empty entry %u\n", i));
      break;
    }
  }
  
  /* If no unused entry is found, we try to find the oldest entry and
     throw it away. If all entries are new and have 0 ctime drop one  */
  if(i == ARP_TABLE_SIZE) {
    maxtime = 0;
    j = ARP_TABLE_SIZE;
    for(i = 0; i < ARP_TABLE_SIZE; ++i) {
      /* remember entry with oldest stable entry in j*/
      if((arp_table[i].state == ETHARP_STATE_STABLE) &&
#if ARP_QUEUEING /* do not want to re-use an entry with queued packets */
      (arp_table[i].p == NULL) &&
#endif
      (arp_table[i].ctime >= maxtime)) {
        maxtime = arp_table[i].ctime;
	      j = i;
      }
    }
    DEBUGF(ETHARP_DEBUG, ("find_arp_entry: found oldest stable entry %u\n", j));
    i = j;
  }
  DEBUGF(ETHARP_DEBUG, ("find_arp_entry: returning %u, state %u\n", i, arp_table[i].state));
  return i;
}

/**
 * Update (or insert) a IP/MAC address pair in the ARP cache.
 *
 * @param ipaddr IP address of the inserted ARP entry.
 * @param ethaddr Ethernet address of the inserted ARP entry.
 * @param flags Defines behaviour:
 * - ARP_INSERT_FLAG Allows ARP to insert this as a new item. If not specified,
 * only existing ARP entries will be updated.
 *
 * @return pbuf If non-NULL, a packet that was queued on a pending entry.
 * You should sent it and must call pbuf_free() afterwards.
 *
 * @see pbuf_free()
 */
static struct pbuf *
update_arp_entry(struct netif *netif, struct ip_addr *ipaddr, struct eth_addr *ethaddr, u8_t flags)
{
  u8_t i, k;
#if ARP_QUEUEING
  struct pbuf *p;
  struct eth_hdr *ethhdr;
#endif
  DEBUGF(ETHARP_DEBUG | DBG_TRACE | 3, ("update_arp_entry()\n"));
  DEBUGF(ETHARP_DEBUG | DBG_TRACE, ("update_arp_entry: %u.%u.%u.%u - %02x:%02x:%02x:%02x:%02x:%02x\n", ip4_addr1(ipaddr), ip4_addr2(ipaddr), ip4_addr3(ipaddr), ip4_addr4(ipaddr),
  ethaddr->addr[0], ethaddr->addr[1], ethaddr->addr[2], ethaddr->addr[3], ethaddr->addr[4], ethaddr->addr[5]));
  /* do not update for 0.0.0.0 addresses */
  if (ipaddr->addr == 0) {
    DEBUGF(ETHARP_DEBUG | DBG_TRACE, ("update_arp_entry: will not add 0.0.0.0 to ARP cache\n"));
    return NULL;
  }
  /* Walk through the ARP mapping table and try to find an entry to
  update. If none is found, the IP -> MAC address mapping is
  inserted in the ARP table. */
  for(i = 0; i < ARP_TABLE_SIZE; ++i) {
    /* Check if the source IP address of the incoming packet matches
    the IP address in this ARP table entry. */
    if(ip_addr_cmp(ipaddr, &arp_table[i].ipaddr)) {
      /* pending entry? */
      if(arp_table[i].state == ETHARP_STATE_PENDING) {
        DEBUGF(ETHARP_DEBUG | DBG_TRACE, ("update_arp_entry: pending entry %u goes stable\n", i));
        /* A pending entry was found, mark it stable */
        arp_table[i].state = ETHARP_STATE_STABLE;
        /* fall-through to next if */
      }
      /* stable entry? (possible just marked to become stable) */
      if(arp_table[i].state == ETHARP_STATE_STABLE) {
        DEBUGF(ETHARP_DEBUG | DBG_TRACE, ("update_arp_entry: updating stable entry %u\n", i));
        /* An old entry found, update this and return. */
        for(k = 0; k < netif->hwaddr_len; ++k) {
          arp_table[i].ethaddr.addr[k] = ethaddr->addr[k];
        }
        /* reset time stamp */
        arp_table[i].ctime = 0;
#if ARP_QUEUEING
        /* queued packet present? */
        if((p = arp_table[i].p) != NULL) {
          /* Null out attached buffer immediately */
          arp_table[i].p = NULL;
          /* fill-in Ethernet header */
          ethhdr = p->payload;
          for(k = 0; k < netif->hwaddr_len; ++k) {
            ethhdr->dest.addr[k] = ethaddr->addr[k];
          }
          ethhdr->type = htons(ETHTYPE_IP);	  	 	  
          DEBUGF(ETHARP_DEBUG | DBG_TRACE, ("update_arp_entry: sending queued IP packet.\n"));
          /* send the queued IP packet */
          netif->linkoutput(netif, p);
          /* free the queued IP packet */
          pbuf_free(p);
        }
#endif
        return NULL;
      }
    } /* if */
  } /* for */

  /* no matching ARP entry was found */
  LWIP_ASSERT("update_arp_entry: i == ARP_TABLE_SIZE", i == ARP_TABLE_SIZE);

  DEBUGF(ETHARP_DEBUG | DBG_TRACE, ("update_arp_entry: IP address not yet in table\n"));
  /* allowed to insert an entry? */
  if ((ETHARP_ALWAYS_INSERT) || (flags & ARP_INSERT_FLAG))
  {
    DEBUGF(ETHARP_DEBUG | DBG_TRACE, ("update_arp_entry: adding entry to table\n"));
    /* find an empty or old entry. */
    i = find_arp_entry();
    if(i == ARP_TABLE_SIZE) {
      DEBUGF(ETHARP_DEBUG | DBG_TRACE, ("update_arp_entry: no available entry found\n"));
      return NULL;
    }
    /* see if find_arp_entry() gave us an old stable, or empty entry to re-use */
    if (arp_table[i].state == ETHARP_STATE_STABLE) {
      DEBUGF(ETHARP_DEBUG | DBG_TRACE, ("update_arp_entry: overwriting old stable entry %u\n", i));
      /* stable entries should have no queued packets (TODO: allow later) */
#if ARP_QUEUEING
      LWIP_ASSERT("update_arp_entry: arp_table[i].p == NULL", arp_table[i].p == NULL);
#endif
    } else {
      DEBUGF(ETHARP_DEBUG | DBG_TRACE | DBG_STATE, ("update_arp_entry: filling empty entry %u with state %u\n", i, arp_table[i].state));
      LWIP_ASSERT("update_arp_entry: arp_table[i].state == ETHARP_STATE_EMPTY", arp_table[i].state == ETHARP_STATE_EMPTY);
    }
    /* set IP address */  
    ip_addr_set(&arp_table[i].ipaddr, ipaddr);
    /* set Ethernet hardware address */  
    for(k = 0; k < netif->hwaddr_len; ++k) {
      arp_table[i].ethaddr.addr[k] = ethaddr->addr[k];
    }
    /* reset time-stamp */  
    arp_table[i].ctime = 0;
    /* mark as stable */  
    arp_table[i].state = ETHARP_STATE_STABLE;
    /* no queued packet */  
#if ARP_QUEUEING
    arp_table[i].p = NULL;
#endif
  }
  else
  {
    DEBUGF(ETHARP_DEBUG | DBG_TRACE, ("update_arp_entry: no matching stable entry to update\n"));
  }
  return NULL;
}

/**
 * Updates the ARP table using the given packet.
 *
 * Uses the incoming IP packet's source address to update the
 * ARP cache for the local network. The function does not alter
 * or free the packet. This function must be called before the
 * packet p is passed to the IP layer.
 *
 * @param netif The lwIP network interface on which the IP packet pbuf arrived.
 * @param pbuf The IP packet that arrived on netif.
 * 
 * @return NULL
 *
 * @see pbuf_free()
 */
struct pbuf *
etharp_ip_input(struct netif *netif, struct pbuf *p)
{
  struct ethip_hdr *hdr;
  
  /* Only insert an entry if the source IP address of the
     incoming IP packet comes from a host on the local network. */
  hdr = p->payload;
  /* source is on local network? */
  if(!ip_addr_maskcmp(&(hdr->ip.src), &(netif->ip_addr), &(netif->netmask))) {
    /* do nothing */
    return NULL;
  }
  
  DEBUGF(ETHARP_DEBUG | DBG_TRACE, ("etharp_ip_input: updating ETHARP table.\n"));
  /* update ARP table, ask to insert entry */
  update_arp_entry(netif, &(hdr->ip.src), &(hdr->eth.src), ARP_INSERT_FLAG);
  return NULL;
}


/**
 * Responds to ARP requests, updates ARP entries and sends queued IP packets.
 * 
 * Should be called for incoming ARP packets. The pbuf in the argument
 * is freed by this function.
 *
 * @param netif The lwIP network interface on which the ARP packet pbuf arrived.
 * @param pbuf The ARP packet that arrived on netif. Is freed by this function.
 * @param ethaddr Ethernet address of netif.
 *
 * @return NULL
 *
 * @see pbuf_free()
 */
struct pbuf *
etharp_arp_input(struct netif *netif, struct eth_addr *ethaddr, struct pbuf *p)
{
  struct etharp_hdr *hdr;

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
日韩精品一区第一页| 国产欧美日韩一区二区三区在线观看| 成人免费高清在线| 国产米奇在线777精品观看| 美腿丝袜亚洲三区| 久久精品噜噜噜成人88aⅴ| 麻豆91在线播放免费| 日本sm残虐另类| 免费的国产精品| 狠狠狠色丁香婷婷综合激情| 国产伦理精品不卡| www.色精品| 欧美中文字幕亚洲一区二区va在线| 欧美在线一区二区| 91精品国产福利| 久久在线免费观看| 日韩一区在线免费观看| 亚洲一区二区三区四区在线免费观看 | 91老师国产黑色丝袜在线| 国产伦精品一区二区三区免费迷| 国产一区二区三区视频在线播放| 福利91精品一区二区三区| 99久久久无码国产精品| 欧美日韩精品欧美日韩精品一综合 | 久久电影网站中文字幕| 国产黄色成人av| 91久久奴性调教| 欧美一区二区三区电影| 国产女同性恋一区二区| 亚洲一区二区在线观看视频 | 国产精品一区在线观看你懂的| 成人av在线播放网站| 欧美日韩免费视频| 久久久久久久久蜜桃| 亚洲国产精品自拍| 国产九色精品成人porny| 色综合久久久网| 日韩精品一区二区三区蜜臀| 亚洲摸摸操操av| 蜜乳av一区二区| 99r国产精品| 日韩一级二级三级| 一区二区视频免费在线观看| 国产一区二区导航在线播放| 欧美午夜在线一二页| 久久综合九色综合97_久久久| 亚洲激情自拍视频| 国产a精品视频| 欧美一级精品大片| 亚洲一区二区三区在线播放| 成人免费电影视频| 精品成人一区二区| 视频一区在线播放| 在线视频亚洲一区| 中文字幕一区二区三区不卡| 激情五月激情综合网| 欧美日韩和欧美的一区二区| 亚洲人成网站在线| 99在线精品视频| 久久亚洲综合色一区二区三区| 亚洲va在线va天堂| 在线国产亚洲欧美| 综合色天天鬼久久鬼色| 成人激情文学综合网| 久久精品在线免费观看| 韩国精品免费视频| 精品欧美一区二区三区精品久久| 午夜精品久久久久影视| 99国产精品久久久久| 国产精品久久久久久久久免费丝袜| 九九**精品视频免费播放| 9191成人精品久久| 视频一区中文字幕国产| 欧美精选午夜久久久乱码6080| 亚洲一级二级三级在线免费观看| 91在线无精精品入口| 亚洲特黄一级片| 91精彩视频在线| 亚洲成人综合网站| 欧美另类高清zo欧美| 日本免费在线视频不卡一不卡二| 69堂国产成人免费视频| 精品在线一区二区三区| 欧美精品一区二区三区蜜桃视频| 裸体歌舞表演一区二区| 久久久久久亚洲综合影院红桃| 国产一区不卡视频| 国产精品不卡一区| 色猫猫国产区一区二在线视频| 亚洲精品免费视频| 欧美精品123区| 麻豆精品一区二区| 国产欧美精品一区aⅴ影院| 成人成人成人在线视频| 洋洋av久久久久久久一区| 欧美日韩国产综合久久| 国产真实乱子伦精品视频| 中文字幕免费一区| 欧美在线视频你懂得| 久久成人精品无人区| 国产精品情趣视频| 欧亚一区二区三区| 国模无码大尺度一区二区三区| 亚洲欧美一区二区在线观看| 欧美日韩1234| 国产老肥熟一区二区三区| 亚洲免费观看高清| 欧美va在线播放| 91丨九色丨黑人外教| 免费在线看成人av| 综合久久久久综合| 精品少妇一区二区三区日产乱码| proumb性欧美在线观看| 日韩专区一卡二卡| 国产精品久久久久精k8| 欧美区视频在线观看| www.亚洲色图| 精品一区二区三区在线视频| 亚洲视频图片小说| 久久久久99精品一区| 欧美色综合天天久久综合精品| 国产成人亚洲综合a∨婷婷| 天堂影院一区二区| 亚洲美女屁股眼交| 久久精品免视看| 欧美日韩国产在线播放网站| www.亚洲色图| 国产剧情一区二区三区| 日本三级韩国三级欧美三级| 亚洲欧美国产77777| 国产人成亚洲第一网站在线播放| 欧美夫妻性生活| 欧洲精品在线观看| 97久久超碰国产精品电影| 国产在线精品免费| 久久精品国产第一区二区三区| 亚洲免费观看高清完整版在线观看 | 中文字幕av一区二区三区| 欧美一区二区三区免费大片| 在线欧美日韩国产| 成人动漫在线一区| 国产高清在线精品| 国内精品嫩模私拍在线| 日韩极品在线观看| 丝袜美腿亚洲综合| 天天综合天天综合色| 舔着乳尖日韩一区| 亚洲国产精品久久一线不卡| 亚洲综合在线观看视频| 亚洲天堂av一区| 一区二区三区在线观看国产| 亚洲免费在线视频一区 二区| 亚洲欧美日韩小说| 亚洲尤物视频在线| 亚洲最色的网站| 午夜精品久久久久久久99水蜜桃 | 欧美精选一区二区| 欧美军同video69gay| 欧美久久一区二区| 91麻豆精品国产91久久久使用方法 | 91蜜桃在线免费视频| 91美女在线看| 在线看国产一区| 91精品国产丝袜白色高跟鞋| 精品国产乱码久久久久久影片| 欧美xxxxx裸体时装秀| xf在线a精品一区二区视频网站| 久久婷婷色综合| 最新国产精品久久精品| 亚洲综合无码一区二区| 秋霞成人午夜伦在线观看| 国精产品一区一区三区mba桃花| 国产成人啪午夜精品网站男同| 9i看片成人免费高清| 欧美日韩国产精品成人| 精品久久人人做人人爰| 亚洲国产高清在线观看视频| 夜夜亚洲天天久久| 九九**精品视频免费播放| 成人一区在线看| 欧美三级三级三级爽爽爽| 欧美老女人第四色| 国产欧美一二三区| 亚洲综合成人在线视频| 精品一区二区免费| 色噜噜狠狠一区二区三区果冻| 欧美日韩国产一区二区三区地区| 精品sm在线观看| 一区二区三区免费看视频| 国产一区二区三区在线观看免费 | 色婷婷国产精品| 欧美刺激午夜性久久久久久久| 中文字幕+乱码+中文字幕一区| 亚洲一区二区偷拍精品| 国产福利91精品一区| 88在线观看91蜜桃国自产| 中文字幕日韩一区| 精品一区二区三区影院在线午夜| 91久久香蕉国产日韩欧美9色| 亚洲精品一区在线观看|