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

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

?? arp.c

?? c51和8019實現(xiàn)單片機上網(wǎng)
?? C
字號:
//-----------------------------------------------------------------------------
// 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);
	}
}


?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
一区精品在线播放| 欧美一级精品在线| 中文字幕中文字幕在线一区 | 69堂国产成人免费视频| 亚洲一级二级三级| 欧美人与性动xxxx| 精品亚洲porn| 久久影院视频免费| av中文一区二区三区| 亚洲欧美国产三级| 91精品啪在线观看国产60岁| 精品一二三四在线| 国产精品美女一区二区| 91麻豆国产在线观看| 亚洲午夜久久久久久久久久久| 欧美日韩一区二区在线观看视频 | 国产风韵犹存在线视精品| 中文字幕精品—区二区四季| 91一区二区三区在线播放| 亚洲综合视频在线观看| 欧美大片免费久久精品三p| 成人动漫中文字幕| 亚洲国产精品精华液网站| 日韩一区二区三区电影在线观看| 国产激情91久久精品导航| 日韩综合小视频| 久久综合99re88久久爱| 99麻豆久久久国产精品免费优播| 亚洲国产精品精华液网站| 久久一日本道色综合| 色999日韩国产欧美一区二区| 日本人妖一区二区| 亚洲天堂2016| 精品福利av导航| 欧美综合一区二区| 成人在线视频一区二区| 亚洲激情欧美激情| 亚洲精品一区在线观看| 色婷婷久久久亚洲一区二区三区| 美女国产一区二区三区| 成人免费视频在线观看| 日韩丝袜情趣美女图片| 色av成人天堂桃色av| 国产精品亚洲午夜一区二区三区 | 日本免费在线视频不卡一不卡二| 欧美激情一区二区三区在线| 欧美人妇做爰xxxⅹ性高电影| 国产福利91精品一区| 亚洲国产成人va在线观看天堂 | 国产精品嫩草影院com| 欧美在线观看禁18| 成人动漫视频在线| 韩国视频一区二区| 日本在线不卡视频| 亚洲成人免费在线观看| 亚洲人成网站色在线观看| 国产欧美在线观看一区| 欧美一区午夜视频在线观看| 日本高清视频一区二区| www.欧美色图| 丰满少妇久久久久久久| 国产成人在线观看| 国产综合色精品一区二区三区| 日本网站在线观看一区二区三区| 亚洲一区日韩精品中文字幕| 国产精品久久久久影视| 国产日韩v精品一区二区| 日韩欧美一区二区免费| 欧美一区二区三区在线观看视频| 精品视频一区三区九区| 91久久久免费一区二区| 色综合色综合色综合| 91丝袜美女网| 国产成人免费视频一区| 国产成人综合亚洲网站| 国产揄拍国内精品对白| 免费人成精品欧美精品| 秋霞影院一区二区| 免费欧美在线视频| 久久狠狠亚洲综合| 精品亚洲欧美一区| 国产一区二区三区高清播放| 国产一区二区不卡在线| 国产成人精品亚洲777人妖| 麻豆高清免费国产一区| 免费欧美在线视频| 精品一区二区在线看| 国产露脸91国语对白| 国产一区二区三区高清播放| 国产精品一级片在线观看| 欧美精品成人一区二区三区四区| 欧美日韩激情在线| 538在线一区二区精品国产| 91精品国产综合久久精品| 日韩丝袜美女视频| 精品国精品国产尤物美女| 26uuu国产一区二区三区| 久久精品一级爱片| 日韩美女视频一区| 五月婷婷久久综合| 美国三级日本三级久久99| 国产99一区视频免费| 99久久精品国产精品久久| 欧美性猛交一区二区三区精品| 777色狠狠一区二区三区| 2022国产精品视频| 国产欧美日韩视频在线观看| 国产精品女主播av| 亚洲激情图片qvod| 麻豆精品在线观看| k8久久久一区二区三区 | 亚洲欧洲美洲综合色网| 亚洲一区二区三区视频在线播放| 日本一道高清亚洲日美韩| 国产精品77777| 91久久免费观看| 精品国产一二三| 亚洲男人的天堂一区二区| 免播放器亚洲一区| 91在线porny国产在线看| 欧美一二三区精品| 亚洲欧美电影一区二区| 久久成人麻豆午夜电影| 色一区在线观看| 精品成人a区在线观看| 亚洲一区在线观看免费观看电影高清 | 国产精品全国免费观看高清| 亚洲国产毛片aaaaa无费看| 国产一区三区三区| 91福利国产成人精品照片| 久久久久久毛片| 日韩影视精彩在线| 不卡的电视剧免费网站有什么| 91麻豆精品国产| 亚洲人成网站色在线观看| 国产老女人精品毛片久久| 91麻豆精品国产自产在线| 自拍视频在线观看一区二区| 国产麻豆精品一区二区| 91精品麻豆日日躁夜夜躁| 亚洲欧美偷拍卡通变态| 粉嫩欧美一区二区三区高清影视| 欧美高清性hdvideosex| 亚洲视频免费在线| 国产麻豆91精品| 91精品国产综合久久蜜臀| 亚洲欧洲另类国产综合| 国产一区二区久久| 欧美不卡在线视频| 婷婷成人综合网| 在线观看91精品国产入口| 最新成人av在线| 成人中文字幕电影| 国产欧美精品日韩区二区麻豆天美| 日本免费在线视频不卡一不卡二| 欧美日韩在线播放三区| 一区二区三区四区五区视频在线观看| 成人一区二区三区视频| 久久免费看少妇高潮| 精品亚洲免费视频| 日韩精品在线网站| 香蕉影视欧美成人| 欧美在线影院一区二区| 亚洲免费观看高清| 欧洲激情一区二区| 亚洲综合色区另类av| 91福利国产成人精品照片| 国产精品久久久久一区二区三区 | 欧美日韩精品一区二区| 日韩一区欧美小说| 成人一级黄色片| 国产精品美女视频| 国产a精品视频| 国产精品国产三级国产| 99久久精品费精品国产一区二区| 国产精品家庭影院| 色欲综合视频天天天| 亚洲国产日产av| 日韩一区二区电影网| 久久99精品一区二区三区三区| 日韩免费高清电影| 国产福利不卡视频| 亚洲婷婷综合久久一本伊一区| 色婷婷av久久久久久久| 一区二区三区中文字幕电影| 91国偷自产一区二区三区成为亚洲经典 | 成人免费视频app| 综合自拍亚洲综合图不卡区| 在线亚洲一区二区| 日韩精品色哟哟| 久久亚洲免费视频| 91蜜桃网址入口| 偷拍亚洲欧洲综合| 久久久久免费观看| 色综合天天综合色综合av| 三级久久三级久久久| 久久五月婷婷丁香社区| 91亚洲国产成人精品一区二三 | 一区二区三区色| 欧美一区二区美女|