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

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

?? netarp.c

?? 一個tcp/ip協議棧,帶有PPP、IP、TCP、UDP等協議
?? C
?? 第 1 頁 / 共 2 頁
字號:
/*****************************************************************************
* netarp.c - ARP protocol and cache
*
* portions Copyright (c) 2001 by Cognizant Pty Ltd.
* portions Copyright (c) 2001 by Partner Voxtream A/S.
*
* The authors hereby grant permission to use, copy, modify, distribute,
* and license this software and its documentation for any purpose, provided
* that existing copyright notices are retained in all copies and that this
* notice and the following disclaimer are included verbatim in any 
* distributions. No written agreement, license, or royalty fee is required
* for any of the authorized uses.
*
* THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS *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 CONTRIBUTORS 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.
*
******************************************************************************
* REVISION HISTORY (please don't use tabs!)
*
*(yyyy-mm-dd)
* 2001-05-12 Robert Dickenson <odin@pnc.com.au>, Cognizant Pty Ltd.
*            Original file. Merged with version by Mads in netether.
* 2001-07-05 Robert Dickenson <odin@pnc.com.au>, Cognizant Pty Ltd.
*            Implemented bug fix to arpAlloc (submitted by Mads)
* 2001-01-03 Craig Graham <c_graham@hinge.mistral.co.uk>, Access Devices Ltd.
*            Added inDHCP bodge to inhibit ARP during DHCP negotiations.
*
******************************************************************************
* NOTES (PLEASE READ THIS!)
*
* This is the first release of an ARP impl. for uC/IP.
* In its present form it only supports one gateway.
* It only supports one ethernet interface.
* The way etherConfig() works is NOT the best solution. 
*
* Choose number of ARP cache entries and size of ARP cache table in netether.h
* arpExpire should be set to a value like 300s with etherConfig().
* Call arpCleanup() at least every arpExpire seconds.
* Call etherConfig() AFTER netInit() AND AFTER ipSetDefault().
* 
* You must impl. an etherSend(NBuf *) function!!!
*  
* The time(NULL) is the ANSI time function which returns time elapsed in seconds.
* I have made a small implementation of the time function, which is located
* in os.c. It returns time elapsed since first call to time(NULL). This is
* ofcourse only to be used, if the ANSI time() function is not supported by the OS/COMPILER.
*
* All the arp functions is defined static, which I found to be the best solution.
* This design looks similar to the arp impl. found in earlier versions of BSD. 
*
* Since I'm using uC/IP in a single proces, I'm not sure if the mutex semaphore
* works properly or is impl. correctly. Please verify this! This was added very quickly!
*
* Currently there is no support for static IP adresses, but the code is prepared for it.
* Actually you should just add a function which calls arpAlloc and change the
* state of the entry to ARP_FIXED.
*
* NOTICE, if the ARP cache is full, the oldest entry will be freed upon next arpResolve of
* a new IP. If this is not done we have the possibility of not beeing able to
* communicate with any hosts that are not located in the ARP cache.
* To avoid removing the oldest before it really has expired (BAD PERFORMANCE)
* you should be sure to have the worst case of ARP entries available
* (adjust ARP_ENTRIES in netether.h).
*
* Good luck.
* Mads Christiansen (mads@mogi.dk or mc@voxtream.com).
*/
#include <string.h>
#include "netconf.h"
#include "netaddrs.h"
#include "netbuf.h"
#include "netether.h"
#include "netarp.h"
#include "netsock.h"

//#include <string.h>
#ifdef HAVE_ANSI_TIME
#include <time.h>
#endif
#include <stdio.h>
#include "netdebug.h"

#pragma warning (push)
#pragma warning (disable: 4018) // signed/unsigned mismatch


// External setup variables
extern etherSetup mySetup;

// Public variables (this is made public for debugging purposes)
arpStatistics arpStats;

// Internal prototypes
static arpEntry *arpLookup(u_long ip, int create);
static arpEntry *arpAlloc(u_long ip);
static void arpRemove(u_long index);

// ARP cache tables
static arpEntry arpEntries[ARP_ENTRIES];
static arpEntry *arpTable[ARP_TABLE_SIZE];

int inDHCP = 0;


void arpInit(void)
{
    // Get a lock to the ethernet/arp variables
    etherLock();
    // Cleaning tables ;-)
    memset(arpEntries, 0, sizeof(arpEntries));
    memset(arpTable, 0, sizeof(arpTable));
    // Reset statistics
    memset(&arpStats, 0, sizeof(arpStats));
    etherRelease();
    // Do a Gratuitous ARP
//    arpRequest(htonl(mySetup.localAddr));
}


/* 
 * Go through arpTable and remove any entries that have expired
 * (more than arpExpire time old).
 */
void arpCleanup(void)
{
  u_long index;
  arpEntry **entry;

  etherLock();
  // **** FOR every index in ARP cache table
  for (index = 0; index < ARP_TABLE_SIZE; index++) {
    // Get a pointer to first arpEntry pointer in chain
    entry = &arpTable[index];

    // **** Traverse entries in chain
    while (*entry) {
      // Which state is the found entry in ?
      switch ((*entry)->state) {
        case ARP_RESOLVED:  // **** CASE ARP_RESOLVED
        case ARP_PENDING:   // **** CASE ARP_PENDING
          // Is this entry expired ?
          if ((*entry)->expire < time(NULL)) {
            // Update entries allocated stats
            arpStats.alloc--;
            // Yes it is, so remove it
            (*entry)->state = ARP_EXPIRED;
            // If we have an NBuf chain waiting to be sent free it
            // (unlikely when state is resolved)
            if ((*entry)->packet) nFreeChain((*entry)->packet);
            // Update chain
            *entry = (*entry)->next;
          }
          else
            // **** Go to next entry in chain
            entry = &((*entry)->next);
          break;
        case ARP_FIXED:     // **** CASE ARP_FIXED (pure cosmetic)
        default: 
          // **** Go to next entry in chain
          entry = &((*entry)->next);
      }
    }
  }
  etherRelease();
}


// *************************** INTERNAL FUCTIONS
// ***************** ARP PROTOCOL IMPLEMENTATION
void arpInput(NBuf* pNBuf)
{
    arpPacket* arpPtr;
    arpEntry* entry;

    TRACE("arpInput(%p) chainLen = %u\n", pNBuf, pNBuf->chainLen);
    ASSERT(pNBuf);
    arpPtr = nBUFTOPTR(pNBuf, arpPacket*);

    // Validate ARP packet
//    if ( (pNBuf->chainLen < sizeof(arpPacket) ) ||
    if ( // quickfix by Robert - above test caused ping to fail when introduced ???
         (arpPtr->hwType != htons(1)) ||
         (arpPtr->prType != htons(ETHERTYPE_IP)) ||
         (arpPtr->hwLength != sizeof(mySetup.hardwareAddr)) ||
         (arpPtr->prLength != sizeof(mySetup.localAddr)) ||
         ((arpPtr->operation != htons(ARP_REQUEST)) &&
          (arpPtr->operation != htons(ARP_REPLY))) ) {
      // Update invalid ARP packets received statistics
      arpStats.invalidARPs++;
      nFreeChain(pNBuf);
      return;
    }

    // If Hardware address of sender eq. myHardwareAddr discard packet
    if (!memcmp(arpPtr->ether.src, mySetup.hardwareAddr, sizeof(mySetup.hardwareAddr))) {
//      TRACE("arpInput(%p) - not our IP [%u.%u.%u.%u], dropping\n", pNBuf, pArpPacket->TargetIP.ip1, pArpPacket->TargetIP.ip2, pArpPacket->TargetIP.ip3, pArpPacket->TargetIP.ip4);
      nFreeChain(pNBuf);
      return;
    }

    // If sender IP eq. myIpAddr we have an IP conflict! Log and discard packet.
    if (arpPtr->senderIp == htonl(mySetup.localAddr)) {
      // We have an IP conflict!
      // Update ip conflict statistics
      arpStats.ipConflicts++;
      nFreeChain(pNBuf);
      return;
    }

    // Find senders IP address in ARP cache (with create == TRUE if target IP is our IP)
    entry = arpLookup(htonl(arpPtr->senderIp), (arpPtr->targetIp == htonl(mySetup.localAddr)));
    if (entry) {
    // Update senders HW address in ARP cache
      memcpy(entry->hardware, arpPtr->senderHw, sizeof(entry->hardware));
      // Set ARP host entry to resolved
      entry->state = ARP_RESOLVED;
      // Set new expire time
      entry->expire = time(NULL) + mySetup.arpExpire;
      // **** IF output packet is queued for this host entry THEN
      if (entry->packet) {
      // **** Send it
        etherOutput(entry->packet);
        entry->packet = NULL;
      }
    }

    // If this is not an ARP request discard packet and return
    // If this ARP request is not targeted for us discard packet and return
    if ( (arpPtr->operation != htons(ARP_REQUEST)) ||
         (arpPtr->targetIp  != htonl(mySetup.localAddr)) ) {
      nFreeChain(pNBuf);
      return;
    }

    // We have an ARP request so build an ARP reply with packet and call etherSend
    // ARP
    arpPtr->targetIp = arpPtr->senderIp;
    memcpy(arpPtr->targetHw, arpPtr->senderHw, sizeof(arpPtr->targetHw));
    arpPtr->senderIp = htonl(mySetup.localAddr);
    memcpy(arpPtr->senderHw, mySetup.hardwareAddr, sizeof(arpPtr->senderHw));
    arpPtr->operation = htons(ARP_REPLY);
    // Ether
    memcpy(arpPtr->ether.dst, arpPtr->ether.src, sizeof(arpPtr->ether.dst));
    memcpy(arpPtr->ether.src, mySetup.hardwareAddr, sizeof(arpPtr->ether.src));
  // **** Send ARP request
    etherSend(pNBuf);
}


////////////////////////////////////////////////////////////////////////////////
// Allocate a new ARP cache entry for given IP.
//
static arpEntry *arpAlloc(u_long ip)
{
  u_long traverse;
  u_long index;
  u_long oldest = -1;
  u_long oldestAge = -1;

  // **** FOR every ARP entry (also those that are free) 
  for (traverse = 0; traverse < ARP_ENTRIES; traverse++) {
    // **** IF ARP entry is free THEN
    if (arpEntries[traverse].state == ARP_FREE) {
      // We have a free arp entry, clear it and break;
      memset(&arpEntries[traverse], 0, sizeof(arpEntry));
      // **** BREAK for loop
      break;
    }
  }

  // **** IF we didn't find a free arp entry THEN
  if (traverse >= ARP_ENTRIES) {
    // Update ARP entry needed but not found stat
    arpStats.allocError++;

    // We didn't find any free ARP entry, so we will try to find the oldest one
    // This search for the oldest one is done here, and not in the first for loop 
    // since I wanted to keep the normal succesfull lookup as fast as possible.
    
    // **** Find oldest entry
    for (traverse = 0; traverse < ARP_ENTRIES; traverse++) {

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
亚洲免费av网站| 国产电影精品久久禁18| 91影视在线播放| 国产精品麻豆久久久| 国产精品一级片在线观看| 久久无码av三级| 高清日韩电视剧大全免费| 欧美国产欧美亚州国产日韩mv天天看完整 | 国产成a人亚洲精品| 国产色婷婷亚洲99精品小说| av在线这里只有精品| 亚洲综合男人的天堂| 欧美一级一级性生活免费录像| 韩国v欧美v日本v亚洲v| 国产精品女主播在线观看| 在线一区二区三区四区| 七七婷婷婷婷精品国产| 国产日韩欧美综合在线| 色综合久久久久综合| 日韩福利视频导航| 亚洲国产成人一区二区三区| 欧美视频在线观看一区二区| 美女网站色91| 亚洲三级在线观看| 欧美xxx久久| 成人激情午夜影院| 日韩国产在线观看| 欧美激情一二三区| 制服丝袜亚洲色图| 国产成人精品aa毛片| 亚洲风情在线资源站| 久久精品人人做| 欧美午夜精品一区| 国产成a人亚洲| 首页国产丝袜综合| 国产精品成人免费| 精品奇米国产一区二区三区| 99国产精品久久久| 久久99久久99小草精品免视看| 亚洲码国产岛国毛片在线| 26uuu精品一区二区三区四区在线| 色综合一个色综合| 激情欧美日韩一区二区| 亚洲一线二线三线视频| 中文字幕电影一区| 91精品国产高清一区二区三区蜜臀| www.欧美精品一二区| 久久综合综合久久综合| 亚洲午夜国产一区99re久久| 国产色产综合产在线视频| 日韩一卡二卡三卡四卡| 色哟哟欧美精品| 国产91精品在线观看| 秋霞电影网一区二区| 免费一区二区视频| 亚洲小少妇裸体bbw| 国产精品二区一区二区aⅴ污介绍| 欧美成人激情免费网| 欧美二区乱c少妇| 在线亚洲欧美专区二区| 成人av资源站| 不卡一区中文字幕| 国产精品99久久久久| 国产在线视频一区二区| 青青草国产精品亚洲专区无| 亚洲成人综合视频| 亚洲第一精品在线| 亚洲第一电影网| 亚洲va天堂va国产va久| 亚洲成人自拍偷拍| 亚洲一区在线播放| 亚洲第一福利一区| 天堂va蜜桃一区二区三区| 亚洲午夜成aⅴ人片| 亚洲综合激情网| 亚洲制服丝袜一区| 亚洲午夜久久久久久久久电影网| 一区二区三区四区亚洲| 亚洲一二三四区不卡| 亚洲精品国产无天堂网2021| 亚洲乱码国产乱码精品精可以看 | voyeur盗摄精品| 亚洲综合激情网| 欧美日韩亚洲另类| 欧美日韩另类国产亚洲欧美一级| 色噜噜偷拍精品综合在线| 99国产精品99久久久久久| 一本到不卡精品视频在线观看| 色噜噜狠狠一区二区三区果冻| 色狠狠色狠狠综合| 91精品国产手机| 精品国偷自产国产一区| 久久精品水蜜桃av综合天堂| 中文字幕一区三区| 亚洲综合色婷婷| 日本成人在线电影网| 狠狠色丁香久久婷婷综合_中| 国产一区二区三区四区五区美女| 岛国精品在线观看| 欧美最新大片在线看| 日韩一区二区三区四区| 国产亚洲欧美日韩在线一区| 亚洲三级电影全部在线观看高清| 亚洲国产精品一区二区久久| 日本免费新一区视频| 春色校园综合激情亚洲| 欧美最猛性xxxxx直播| 国产成人av资源| 69堂精品视频| 欧美不卡视频一区| 国产精品午夜在线观看| 亚洲精品高清在线观看| 日本不卡123| 粉嫩aⅴ一区二区三区四区五区| 91免费看`日韩一区二区| 欧美日韩精品一区二区三区四区| 欧美电视剧在线观看完整版| 国产精品国模大尺度视频| 日韩成人伦理电影在线观看| 国产成人av一区二区三区在线| 欧美丝袜丝交足nylons| 久久这里只有精品首页| 日本美女一区二区三区| 国产aⅴ精品一区二区三区色成熟| av不卡免费电影| 日韩午夜激情电影| 亚洲最色的网站| 国产精品一区二区在线观看网站| 欧美三级在线播放| 欧美国产综合色视频| 日本免费新一区视频| 91美女蜜桃在线| 久久久蜜桃精品| 视频在线观看一区二区三区| 裸体在线国模精品偷拍| 日本电影亚洲天堂一区| 国产午夜精品久久久久久免费视 | 欧美在线一区二区| 中文字幕av一区二区三区| 日本中文在线一区| 欧洲中文字幕精品| 国产精品久久免费看| 免费成人在线播放| 欧美日韩一区不卡| 亚洲精品成人悠悠色影视| 国产成人8x视频一区二区| 欧美r级在线观看| 五月天激情综合网| 色成人在线视频| 国产精品白丝在线| 成人永久免费视频| 精品播放一区二区| 美国毛片一区二区三区| 欧美日韩国产一二三| 亚洲靠逼com| 99这里只有精品| 国产日韩欧美不卡在线| 国产揄拍国内精品对白| 日韩精品一区二区三区蜜臀| 五月天网站亚洲| 欧美在线视频全部完| 一区二区三区四区不卡在线| 99re成人在线| 亚洲精品视频免费观看| 91黄色免费网站| 亚洲精品第1页| 欧美手机在线视频| 亚洲18色成人| 这里只有精品99re| 蜜臀91精品一区二区三区| 日韩欧美电影一二三| 久久成人精品无人区| 精品少妇一区二区三区视频免付费 | 激情国产一区二区| 久久久国产午夜精品| 国产99久久久国产精品| 国产精品成人免费在线| 色综合久久中文综合久久牛| 亚洲人亚洲人成电影网站色| 91网页版在线| 亚洲午夜免费视频| 日韩亚洲欧美在线观看| 精久久久久久久久久久| 国产日韩欧美一区二区三区综合| 粗大黑人巨茎大战欧美成人| 日韩毛片一二三区| 欧美日韩免费一区二区三区 | 一区二区三区在线观看国产| 欧美日韩亚洲综合一区 | 日本一区二区三区四区在线视频 | 国产人久久人人人人爽| av影院午夜一区| 亚洲mv在线观看| 久久婷婷色综合| www.色精品| 日韩成人一级片| 国产精品入口麻豆九色| 欧美日韩电影在线播放| 国产精品影视在线观看| 一级做a爱片久久|