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

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

?? arp.c

?? c8051f020源代碼39個 使用Silicon Labs IDE 調試器
?? C
字號:
//-----------------------------------------------------------------------------
// Copyright (c) 2002 Jim Brady
// Do not use commercially without author's permission
// Last revised August 2002
// Net ARP.C
//
// This module handles ARP messages and ARP resolution and manages
// the ARP cache. Refer to RFC 826 and RFC 1122
//-----------------------------------------------------------------------------
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include "C8051f.h"
#include "net.h"
#include "eth.h"
#include "serial.h"
#include "ip.h"
#include "arp.h"



extern WAIT xdata wait;
extern UCHAR code my_hwaddr[];
extern UCHAR code broadcast_hwaddr[]; 
extern ULONG code my_ipaddr;
extern ULONG code my_subnet;
extern ULONG code gateway_ipaddr;
extern UCHAR idata debug;
ARP_CACHE xdata arp_cache[CACHESIZE];
UCHAR waiting_for_arp;



void init_arp(void)
{
  	memset(arp_cache, 0, sizeof(arp_cache)); 
	memset(&wait, 0, sizeof(wait));
	waiting_for_arp = FALSE;
}




//------------------------------------------------------------------------
//	This is called every 60 seconds to age the ARP cache
// If an entry times out then it is deleted from the cache
// See "TCP/IP Illustrated, Volume 1" Sect 4.3
//------------------------------------------------------------------------
void age_arp_cache(void)
{
 	UCHAR i;
    	
   for (i=0; i < CACHESIZE; i++)
   {
      if ((arp_cache[i].ipaddr != 0) && (arp_cache[i].timer))
      {
         arp_cache[i].timer--;
			if (arp_cache[i].timer == 0)
         {
				// Timed out so clear out cache entry
				// Do not need to zero hwaddr
				arp_cache[i].ipaddr = 0;
            if (debug) serial_send("ARP: Aged out a cache entry\r");
			}
		}
   }
}




//------------------------------------------------------------------------
// This allocates memory for the entire outgoing message,
// including eth and ip headers, then builds an outgoing
// ARP response message
// See "TCP/IP Illustrated, Volume 1" Sect 4.4
//------------------------------------------------------------------------
void arp_send(UCHAR * hwaddr, ULONG ipaddr, UCHAR msg_type)
{
	UCHAR xdata * outbuf;
	ARP_HEADER xdata * arp;
         
   
   // Allocate memory for entire outgoing message including
   // eth header. Always 42 bytes
   outbuf = (UCHAR xdata *)malloc(42);
   if (outbuf == NULL)
   {
      if (debug) serial_send("ARP: Oops, out of memory\r");
      return;
   }      
     
   // Allow 14 bytes for the ethernet header
   arp = (ARP_HEADER xdata *)(outbuf + 14);
 	
	arp->hardware_type = DIX_ETHERNET; 
   arp->protocol_type = IP_PACKET;
   arp->hwaddr_len = 6;
	arp->ipaddr_len = 4;               
   arp->message_type = (UINT)msg_type;
   
   // My hardware address and IP addresses 
   memcpy(arp->source_hwaddr, my_hwaddr, 6);
   arp->source_ipaddr = my_ipaddr;

   // Destination hwaddr and dest IP addr
   if (msg_type == ARP_REQUEST) memset(arp->dest_hwaddr, 0, 6);
   else memcpy(arp->dest_hwaddr, hwaddr, 6);
   
   arp->dest_ipaddr = ipaddr;
      
   // If request then the message is a brodcast, if a response then
   // send to specified hwaddr
   // ARP payload size is always 28 bytes
	if (msg_type == ARP_REQUEST) eth_send(outbuf, broadcast_hwaddr, ARP_PACKET, 28);
   else eth_send(outbuf, hwaddr, ARP_PACKET, 28);
}



//------------------------------------------------------------------------
// This re-sends an ARP request if there was no response to
// the first one.	 It is called every 0.5 seconds.  If there
// is no response after 2 re-tries, the datagram that IP was 
// trying to send is deleted
//-----------------------------------------------------------------------
void arp_retransmit(void)
{
	static UCHAR idata retries = 0; 
	
	if ((waiting_for_arp) && (wait.timer))
	{
		wait.timer--;
		if (wait.timer == 0)
		{
			retries++;
			if (retries <= 2)
			{
				if (debug) serial_send("ARP: Re-sending ARP broadcast\r");
	 			arp_send(NULL, wait.ipaddr, ARP_REQUEST);
				wait.timer = ARP_TIMEOUT;
			}
			else
			{	
				if (debug) serial_send("ARP: Gave up waiting for response\r");
	 			wait.timer = 0;
				waiting_for_arp = 0;
				free(wait.buf);
			}
		}
	}
}




//------------------------------------------------------------------------
// Find the ethernet hardware address for the given ip address
// If destination IP is on my subnet then we want the eth
// address	of destination, otherwise we want eth addr of gateway. 
// Look in ARP cache first.  If not found there, send ARP request.
// Return pointer to the hardware address or NULL if not found
// See "TCP/IP Illustrated, Volume 1" Sect 4.5
//------------------------------------------------------------------------
UCHAR xdata * arp_resolve(ULONG dest_ipaddr)
{
   UCHAR i;
      
   // If destination IP is not on my subnet then we really want eth addr
	// of gateway, not destination IP
	if ((dest_ipaddr ^ my_ipaddr) & my_subnet)
	{
		if (gateway_ipaddr == 0)
		{
			if (debug) serial_send("ARP: Error, gateway addr not set\r");
			return (NULL);	
	 	}
	 	else dest_ipaddr = gateway_ipaddr;
	}
	
	   
   // See if IP addr of interest is in ARP cache
   for (i=0; i < CACHESIZE; i++)
   {
      if (arp_cache[i].ipaddr == dest_ipaddr)
         return (&arp_cache[i].hwaddr[0]);
   }

	if (debug) serial_send("ARP: IP addr not found in cache\r");
	if (debug) serial_send("ARP: Sending an ARP broadcast\r");
	// Not in cache so broadcast ARP request
  	arp_send(NULL, dest_ipaddr, ARP_REQUEST);
     	   
   // Set a flag to indicate that an IP datagram is waiting
   // to be sent
   waiting_for_arp = TRUE;
				      
   // Null means that we have sent an ARP request
   return (NULL); 
}





//------------------------------------------------------------------------
// This handles incoming ARP messages
// See "TCP/IP Illustrated, Volume 1" Sect 4.4
// Todo:  Resolve problem of trying to add to a full cache
//------------------------------------------------------------------------
void arp_rcve(UCHAR xdata * inbuf)
{
   UCHAR idata i, cached, oldest;
   UINT idata minimum;
   ARP_HEADER xdata * arp;
      
   arp = (ARP_HEADER xdata *)(inbuf + 14);
   cached = FALSE;
   
   // Print message
   if (debug)
   {
      if (arp->message_type == ARP_REQUEST)
         serial_send("ARP: Request rcvd\r");
      else serial_send("ARP: Response rcvd\r");
   }
         
   // Validate incoming frame
   if ((arp->hardware_type != DIX_ETHERNET) ||
       (arp->protocol_type != IP_PACKET)) return;

   // Search ARP cache for senders IP address
   // If found, update entry and restart timer
   for (i=0; i < CACHESIZE; i++)
   {
      if (arp_cache[i].ipaddr == arp->source_ipaddr)
      {
         memcpy(&arp_cache[i].hwaddr[0], &arp->source_hwaddr[0], 6);
         arp_cache[i].timer = CACHETIME;		
         cached = TRUE;
         if (debug) serial_send("ARP: Cache entry updated\r");
                  
         break;  
      }
   }
   
   if (arp->dest_ipaddr != my_ipaddr) return;
   
   // At this point we know the the frame is addressed to me
   // If not already in cache then add entry and start timer
   if (cached == FALSE)
   {
      // Find first blank space and add entry
		// Blank entries are indicated by ip addr = 0
      for (i=0; i < CACHESIZE; i++)
      {
         if (arp_cache[i].ipaddr == 0) 
         {
            arp_cache[i].ipaddr = arp->source_ipaddr;
            memcpy(&arp_cache[i].hwaddr[0], &arp->source_hwaddr[0], 6);   
            arp_cache[i].timer = CACHETIME;
         	if (debug) serial_send("ARP: New cache entry added\r");
         	break;
         }
      }

		// If no blank entries in arp cache	then sort cache
		// to find oldest entry and replace it
		if (i == CACHESIZE)
		{
			// Oldest entry is the one with lowest timer value			
			minimum = 0xFFFF;
			for (i=0; i < CACHESIZE; i++)
      	{
				if (arp_cache[i].timer < minimum) 
				{
					minimum = arp_cache[i].timer;
					oldest = i;
				}
			}
      	
			// "oldest" is now index of oldest entry, so replace it
			arp_cache[oldest].ipaddr = arp->source_ipaddr;
         memcpy(&arp_cache[oldest].hwaddr[0], &arp->source_hwaddr[0], 6);   
         arp_cache[oldest].timer = CACHETIME;
        if (debug) serial_send("ARP: Cache full, so replaced oldest\r");
   	}
	}

   
   // If we are waiting for an arp response and the arp response
  	// that just came in is addressed to me and is from the host
  	// we are waiting for, then send	the message-in-waiting
   if (arp->message_type == ARP_RESPONSE)
   {
   	if ((waiting_for_arp) && (wait.ipaddr == arp->source_ipaddr))
   	{
   		waiting_for_arp = FALSE;
		  	ip_send(wait.buf, wait.ipaddr, wait.proto_id, wait.len);
		}
	}
	else if (arp->message_type == ARP_REQUEST)
   {
    	// Send ARP response 
    	if (debug) serial_send("ARP: Sending response\r");
    	arp_send(arp->source_hwaddr, arp->source_ipaddr, ARP_RESPONSE);
	}
}


?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
国产精品资源在线看| 色综合久久综合中文综合网| av一区二区久久| 欧美精品黑人性xxxx| 国产精品国产三级国产aⅴ中文 | 亚洲国产一区二区三区青草影视| 精品写真视频在线观看 | 99久久精品情趣| 精品欧美一区二区久久| 亚洲一二三四区不卡| 99久久免费精品高清特色大片| 欧美一区二区成人| 亚洲制服丝袜在线| eeuss鲁片一区二区三区在线看| 欧美一级艳片视频免费观看| 亚洲一区二区在线免费看| 岛国一区二区三区| 久久久久国产精品免费免费搜索| 五月激情综合婷婷| 欧美调教femdomvk| 怡红院av一区二区三区| 91污在线观看| 国产精品久久久久久亚洲毛片| 国产一区二区三区免费播放| 欧美一二三区在线观看| 日本不卡视频在线观看| 欧美日韩一区不卡| 午夜久久久久久电影| 欧美日韩视频在线一区二区| 亚洲一区二区高清| 欧美三级电影在线观看| 亚洲综合色网站| 欧美日韩激情一区| 免费在线看成人av| 欧美r级在线观看| 黄色精品一二区| 一本大道久久a久久精品综合| 欧美日本韩国一区二区三区视频| 国产91精品一区二区麻豆亚洲| 日韩欧美一区中文| 免费成人小视频| 日韩一二三四区| 国模大尺度一区二区三区| 精品99久久久久久| 国产99久久久国产精品| 久久蜜桃av一区二区天堂| 国产成人久久精品77777最新版本 国产成人鲁色资源国产91色综 | 久久综合精品国产一区二区三区| 激情综合网最新| 国产拍欧美日韩视频二区| 不卡影院免费观看| 亚洲自拍偷拍图区| 欧美白人最猛性xxxxx69交| 久久99国产精品麻豆| 欧美日韩情趣电影| 久久精品男人的天堂| 成人黄色大片在线观看| 夜夜嗨av一区二区三区中文字幕| 欧美日韩三级视频| 精品无人区卡一卡二卡三乱码免费卡 | 国产精品夜夜爽| 国产精品福利电影一区二区三区四区| 91看片淫黄大片一级| 亚洲不卡一区二区三区| 久久综合久久综合久久综合| 成人免费三级在线| 三级一区在线视频先锋 | 国产一区二区不卡老阿姨| 中文文精品字幕一区二区| 在线观看国产精品网站| 免费成人深夜小野草| 综合激情网...| 色综合久久中文综合久久牛| 日韩精品一区二区三区在线 | 国产亚洲欧美一级| 色网站国产精品| 久久国产福利国产秒拍| 中文字幕色av一区二区三区| 欧美撒尿777hd撒尿| 国产成人一区二区精品非洲| 亚洲综合久久久久| 国产亚洲一区字幕| 在线电影一区二区三区| 国产jizzjizz一区二区| 日本不卡免费在线视频| 亚洲欧美另类小说视频| 精品美女在线播放| 777午夜精品免费视频| 97se亚洲国产综合自在线 | 韩国在线一区二区| 日本一区二区三区四区在线视频 | 久久久久久久综合日本| 日本韩国一区二区三区视频| 九一九一国产精品| 日韩激情av在线| 一区二区三区日韩欧美精品| 日本一区二区久久| 国产网站一区二区三区| 精品剧情在线观看| 欧美一区二区三区日韩视频| 欧美在线观看视频在线| 91网站在线播放| jlzzjlzz欧美大全| 成人18视频在线播放| 国产91精品久久久久久久网曝门| 精品一区二区三区免费| 久久精品国内一区二区三区| 丝袜美腿成人在线| 日韩精品一级中文字幕精品视频免费观看| 亚洲激情av在线| 欧美精品第1页| 久久亚洲精华国产精华液 | 日本二三区不卡| 99久久伊人久久99| 成人国产在线观看| av在线不卡免费看| 91麻豆国产香蕉久久精品| 成人av小说网| 91麻豆成人久久精品二区三区| 不卡电影免费在线播放一区| 成人av综合在线| 91丨porny丨户外露出| 一本到不卡精品视频在线观看 | 日韩丝袜情趣美女图片| 日韩欧美精品在线| 久久久久久久久久久99999| 欧美精品一区二区三区蜜桃| 欧美精品一区二区久久婷婷| 国产亚洲va综合人人澡精品| 国产欧美精品一区二区色综合朱莉| 91精品国产全国免费观看 | 国产精品自拍在线| 日本一区二区三区久久久久久久久不| 久久免费偷拍视频| 国产精品毛片久久久久久| 亚洲精品欧美在线| 午夜欧美在线一二页| 青青草国产精品亚洲专区无| 精彩视频一区二区三区| 国产jizzjizz一区二区| 在线观看91视频| 日韩欧美一区中文| 亚洲天堂网中文字| 日韩国产精品久久久| 国产精品自拍网站| 欧美三级中文字| 久久久综合激的五月天| 亚洲人成网站在线| 久久精品国产99国产| 99久久精品99国产精品| 欧美疯狂性受xxxxx喷水图片| 精品999久久久| 亚洲综合色在线| 国产成人在线观看| 欧美丰满美乳xxx高潮www| 欧美激情自拍偷拍| 亚洲国产成人va在线观看天堂| 狠狠狠色丁香婷婷综合久久五月| caoporn国产一区二区| 欧美一区二区福利在线| 亚洲另类春色国产| 国产精品一区2区| 欧美日本韩国一区| 亚洲欧洲国产日韩| 国内久久精品视频| 欧美精品乱码久久久久久| 国产日本欧洲亚洲| 青青草97国产精品免费观看 | 国产精品18久久久| 欧美一卡2卡三卡4卡5免费| 国产精品国产三级国产普通话蜜臀 | 久久亚洲私人国产精品va媚药| 国产亚洲成av人在线观看导航| 99精品国产一区二区三区不卡| 在线不卡中文字幕播放| 国产精品午夜久久| 精品一区二区三区在线播放 | 1000部国产精品成人观看| 久久69国产一区二区蜜臀| 欧美日免费三级在线| 亚洲免费观看高清完整版在线 | 在线观看一区日韩| 国产精品乱子久久久久| 国产一区二区在线观看视频| 337p亚洲精品色噜噜狠狠| 亚洲男人的天堂av| 不卡的av电影在线观看| 久久精品亚洲乱码伦伦中文 | 99re成人在线| 国产精品乱子久久久久| 国产精品66部| 久久久精品影视| 国产福利一区二区三区| 久久丝袜美腿综合| 国产一区二区伦理片| 精品国产免费视频| 国产美女av一区二区三区| 久久久青草青青国产亚洲免观| 狠狠色丁香婷综合久久| 国产亚洲成av人在线观看导航|