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

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

?? arp.c

?? 這是一個比較完整的利用C8051F系列單片機開發以太網的程序例程
?? 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一区二区三区免费野_久草精品视频
蜜臀精品一区二区三区在线观看| 制服视频三区第一页精品| 久久综合给合久久狠狠狠97色69| 亚洲国产精品久久久久秋霞影院| 91麻豆成人久久精品二区三区| 国产精品久久99| 色综合天天狠狠| 亚洲欧美精品午睡沙发| 一本色道亚洲精品aⅴ| 亚洲资源中文字幕| 3751色影院一区二区三区| 另类调教123区| 日本一区二区电影| 91网站在线播放| 日韩精品乱码免费| 国产三级三级三级精品8ⅰ区| 成人做爰69片免费看网站| 亚洲青青青在线视频| 欧美日韩久久不卡| 国产乱码精品一区二区三区av | 午夜精品久久一牛影视| 欧美另类z0zxhd电影| 极品少妇xxxx偷拍精品少妇| 欧美国产日韩a欧美在线观看| 91原创在线视频| 麻豆久久一区二区| 中文字幕中文在线不卡住| 欧美三片在线视频观看| 国产一区二区导航在线播放| 国产精品久久久久永久免费观看 | 精品国产一区二区三区久久影院| 91丨porny丨国产入口| 亚洲成人免费在线观看| 国产欧美一区二区三区网站| 色综合久久天天| 黄色精品一二区| 一卡二卡欧美日韩| 久久久高清一区二区三区| 欧美天堂亚洲电影院在线播放| 老司机午夜精品| 一区二区三区日韩欧美| 精品国产成人在线影院| 色播五月激情综合网| 国内偷窥港台综合视频在线播放| 亚洲一区二区美女| 国产偷国产偷亚洲高清人白洁| 欧美性猛片xxxx免费看久爱| 粉嫩av亚洲一区二区图片| 视频在线观看一区二区三区| 亚洲欧洲另类国产综合| 精品国精品国产| 欧美日韩精品欧美日韩精品一综合| 国产成人综合亚洲网站| 免费在线一区观看| 一区二区三区免费| 最新中文字幕一区二区三区| 久久麻豆一区二区| 欧美一区二区三区人| 色婷婷综合视频在线观看| 成人精品视频一区二区三区 | 亚洲日本一区二区三区| 欧美精品一区二区在线观看| 制服丝袜亚洲色图| 在线观看欧美日本| 99r国产精品| 国产精品亚洲午夜一区二区三区| 国产成人高清在线| 欧美电影免费观看高清完整版在线观看| 国产mv日韩mv欧美| 国产最新精品精品你懂的| 性感美女久久精品| 久久综合精品国产一区二区三区| 综合久久久久久| 亚洲精品一区二区三区在线观看| 欧美久久久久久蜜桃| 欧美性色黄大片| 欧美亚州韩日在线看免费版国语版| 91蜜桃传媒精品久久久一区二区| 99热这里都是精品| 91在线国产观看| 色婷婷精品大在线视频| 99re这里只有精品6| av一本久道久久综合久久鬼色| 国产精品一区二区久激情瑜伽| 久久国产精品第一页| 蜜臀av性久久久久蜜臀aⅴ四虎 | 色婷婷国产精品久久包臀| 懂色一区二区三区免费观看| 国产精品一区久久久久| 国产精品影视网| 成人免费视频国产在线观看| 成人午夜免费电影| 99久久99久久精品国产片果冻| 白白色 亚洲乱淫| 91久久线看在观草草青青| 欧洲日韩一区二区三区| 欧美日韩黄色一区二区| 欧美日韩国产乱码电影| 7777女厕盗摄久久久| www精品美女久久久tv| 国产三级精品视频| 136国产福利精品导航| 91麻豆国产福利在线观看| 精品日韩成人av| 欧美日韩电影一区| 日韩亚洲欧美中文三级| 久久综合成人精品亚洲另类欧美 | 日韩欧美你懂的| 色婷婷狠狠综合| 亚洲欧洲一区二区三区| 久久99这里只有精品| 国产精品国产三级国产aⅴ中文| 成人欧美一区二区三区| 亚洲精品一区二区三区四区高清| 综合婷婷亚洲小说| 性久久久久久久久久久久| 午夜私人影院久久久久| 久久精品免费观看| 国产精品综合久久| 欧美视频在线一区二区三区| 精品久久人人做人人爽| 亚洲色图欧洲色图婷婷| 青青国产91久久久久久| 国产精品福利影院| 丰满放荡岳乱妇91ww| 国产目拍亚洲精品99久久精品| 偷拍日韩校园综合在线| 国产一区二区免费视频| 欧美大度的电影原声| 国产在线观看一区二区| 国产宾馆实践打屁股91| 欧美一区二区播放| 麻豆国产精品官网| 国产校园另类小说区| 色婷婷综合中文久久一本| 91精品国产综合久久久蜜臀图片 | 色综合久久久久久久久| 欧美日韩aaa| 国产精品视频一二三| 日韩中文欧美在线| 色婷婷av一区二区三区软件 | 欧美日韩在线精品一区二区三区激情| 欧美成人三级在线| 丝袜美腿一区二区三区| 色哦色哦哦色天天综合| 国产夜色精品一区二区av| 爽好久久久欧美精品| 一本久久精品一区二区| 国产日韩精品一区二区三区在线| 日本成人中文字幕| 欧美午夜免费电影| 成人欧美一区二区三区黑人麻豆| 国产一区二区精品久久99| 欧美一区二区三区公司| 一区二区三区四区在线| 成人在线视频一区| 久久毛片高清国产| 老汉av免费一区二区三区| 欧美区在线观看| 亚洲午夜久久久久中文字幕久| 成人久久18免费网站麻豆| 久久久久久久电影| 久久精品免费看| 日韩午夜三级在线| 无吗不卡中文字幕| 欧美日韩亚洲综合在线| 亚洲一区二区精品3399| 色久优优欧美色久优优| 亚洲图片欧美激情| 91亚洲午夜精品久久久久久| 中文字幕高清一区| 成人激情开心网| 国产精品国产三级国产普通话蜜臀| 国产精品一区久久久久| 国产欧美精品在线观看| 国产精品99久久不卡二区| 久久久一区二区| 国产精品羞羞答答xxdd| 国产亚洲一区二区三区在线观看| 国产在线一区二区| 欧美国产成人精品| 99视频热这里只有精品免费| 亚洲欧美一区二区久久| 色网站国产精品| 亚洲午夜一区二区三区| 91超碰这里只有精品国产| 另类调教123区 | 欧美视频日韩视频在线观看| 亚洲高清久久久| 国产精品久久国产精麻豆99网站| 福利一区二区在线| 亚洲三级免费观看| 欧美男女性生活在线直播观看| 奇米色777欧美一区二区| 精品国一区二区三区| 成人精品电影在线观看| 亚洲免费观看在线视频| 欧美精品精品一区| 激情综合网最新| 国产精品另类一区|