亚洲欧美第一页_禁久久精品乱码_粉嫩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一区二区三区免费野_久草精品视频
樱花影视一区二区| 亚洲男人的天堂在线观看| 精品日韩99亚洲| 久久久不卡影院| 一区二区三区在线观看视频| 亚洲免费视频成人| 久久精品国产精品亚洲红杏 | 一本大道av一区二区在线播放| 欧美中文一区二区三区| 日韩一区二区免费在线电影| wwwwxxxxx欧美| 亚洲综合在线视频| 毛片av中文字幕一区二区| 国产亚洲综合在线| 一区二区在线观看免费 | 亚洲国产一区二区视频| 麻豆精品新av中文字幕| 菠萝蜜视频在线观看一区| 欧美精品自拍偷拍动漫精品| 国产午夜亚洲精品不卡| 欧美一二三区精品| 亚洲天堂精品视频| 国内精品国产成人国产三级粉色 | 亚洲午夜视频在线观看| 中文字幕中文乱码欧美一区二区| 一区二区三区在线视频免费| 国产精品一区二区在线观看不卡| 99精品国产热久久91蜜凸| 国产亚洲一区字幕| 精彩视频一区二区三区| 欧美一区二区在线播放| 天天亚洲美女在线视频| 96av麻豆蜜桃一区二区| 国产精品久久久久婷婷二区次| 国产一区二区三区免费观看| 欧美一区国产二区| 国产专区欧美精品| 日韩一区二区高清| 蜜臀91精品一区二区三区| 91麻豆精品国产91久久久使用方法 | 日韩一区二区中文字幕| 肉丝袜脚交视频一区二区| 欧美裸体bbwbbwbbw| 亚洲第一搞黄网站| 欧美日韩国产中文| 天天操天天干天天综合网| 91麻豆精品国产91久久久使用方法 | 欧美国产精品一区二区三区| 国产成人在线视频播放| 国产精品嫩草99a| 99精品视频一区| 一区二区三区小说| 欧美日韩国产一二三| 五月综合激情日本mⅴ| 欧美一区二区福利视频| 蜜臀a∨国产成人精品| 国产精品二三区| 欧洲生活片亚洲生活在线观看| 亚洲图片欧美视频| 91精品国产综合久久久久久| 美女视频黄 久久| 国产精品不卡在线| 在线不卡欧美精品一区二区三区| 久久精品二区亚洲w码| 亚洲欧美日韩国产手机在线| 国产欧美日韩三区| 欧美日韩精品一区二区天天拍小说 | 亚洲伊人色欲综合网| 亚洲成av人片在线观看| 中文字幕精品在线不卡| 欧美国产欧美亚州国产日韩mv天天看完整 | 蜜臀av一区二区在线观看| 久久精品一级爱片| 91麻豆精品国产自产在线| 99久精品国产| 麻豆视频观看网址久久| 亚洲精品高清在线观看| 精品国产一区二区三区忘忧草| 91丨porny丨蝌蚪视频| 国产一区二区三区不卡在线观看| 亚洲国产日产av| 亚洲视频电影在线| 国产精品美女一区二区| 日韩无一区二区| 精品视频色一区| 91国偷自产一区二区三区成为亚洲经典 | 伊人一区二区三区| 自拍偷拍亚洲激情| 亚洲天堂2014| 亚洲日本免费电影| 亚洲美女偷拍久久| 欧美日韩一区精品| 欧美日韩国产首页| 在线成人免费观看| 日韩一区二区三区四区| 日韩免费视频一区二区| 国内精品久久久久影院薰衣草| 美女高潮久久久| 国产最新精品免费| 精品一区二区国语对白| 久国产精品韩国三级视频| 激情综合网av| av中文字幕不卡| 色综合网色综合| 欧美亚洲高清一区| 91精品国产综合久久福利 | 狂野欧美性猛交blacked| 国产九色精品成人porny | 91福利在线免费观看| 99v久久综合狠狠综合久久| 色嗨嗨av一区二区三区| 欧美日韩国产成人在线免费| 国产一区二区三区视频在线播放| 国产精品一区在线| 在线观看亚洲专区| 精品国产1区二区| 一区在线播放视频| 亚洲国产精品影院| 麻豆专区一区二区三区四区五区| 国产在线观看免费一区| zzijzzij亚洲日本少妇熟睡| 欧美日韩国产在线观看| 日本一区二区成人| 国产亚洲一区二区在线观看| 一区二区三区欧美日| 日韩中文字幕av电影| 国产福利一区在线| 777亚洲妇女| 亚洲少妇最新在线视频| 精品影视av免费| 欧美日韩精品久久久| 9人人澡人人爽人人精品| 欧美一区二区三区免费视频 | 国产拍揄自揄精品视频麻豆| 亚洲在线中文字幕| 99久久99久久免费精品蜜臀| 久久精品亚洲乱码伦伦中文| 日韩一区二区三区电影 | 欧美午夜精品电影| 亚洲精品日韩专区silk| 成人蜜臀av电影| 久久久亚洲综合| 精品一区精品二区高清| 欧美男人的天堂一二区| 亚洲日本在线看| 日韩**一区毛片| 欧美日韩黄视频| 午夜av区久久| 日韩欧美一级精品久久| 奇米777欧美一区二区| 欧美日韩午夜在线视频| 亚洲国产精品精华液网站| 91黄色免费版| 午夜精品影院在线观看| 91福利视频久久久久| 91精品国产综合久久小美女| 日本不卡视频在线| 精品卡一卡二卡三卡四在线| 日日欢夜夜爽一区| 日韩精品一区二区三区swag | 亚洲成人av福利| 欧美一区二区三区在线观看| 久久网站热最新地址| 成人国产一区二区三区精品| 综合av第一页| 欧美一区二区三区小说| 极品美女销魂一区二区三区免费| 国产日韩精品一区二区浪潮av| 99久久久久久| 蜜乳av一区二区| 国产欧美一区二区在线| 欧洲亚洲国产日韩| 国产精品一区二区在线看| 三级亚洲高清视频| 亚洲另类中文字| 精品国产髙清在线看国产毛片| 国产成人免费视频网站高清观看视频| 亚洲欧美日韩久久| 久久精品亚洲一区二区三区浴池 | 欧美色倩网站大全免费| 国产精品夜夜爽| 日本午夜精品一区二区三区电影| 久久综合av免费| 欧美另类久久久品| 欧美综合亚洲图片综合区| 国产乱码字幕精品高清av| 亚洲国产中文字幕在线视频综合| 久久久另类综合| 欧美精品乱码久久久久久按摩| 97成人超碰视| 国产精品一区二区91| 蜜臀av亚洲一区中文字幕| 精品视频1区2区3区| 成人激情图片网| 国产suv精品一区二区883| 日本va欧美va欧美va精品| 91精品免费观看| 在线播放一区二区三区| 欧美老女人在线| 欧美性受极品xxxx喷水|