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

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

?? arp.c

?? embeded websever
?? 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一区二区三区免费野_久草精品视频
欧美视频中文字幕| 欧美丰满高潮xxxx喷水动漫| 免费欧美在线视频| 五月天欧美精品| 亚洲卡通欧美制服中文| 国产精品国产三级国产aⅴ中文| 日韩亚洲欧美高清| 日韩午夜中文字幕| 日韩亚洲欧美中文三级| 欧美日韩免费观看一区二区三区| 在线观看亚洲专区| 色综合天天做天天爱| 91在线一区二区三区| 北岛玲一区二区三区四区| 国产成人免费视频一区| 成人黄色小视频| 成人av一区二区三区| 成人高清视频免费观看| 91在线免费播放| 99视频精品免费视频| 欧美中文字幕一二三区视频| 欧美色手机在线观看| 欧美精品九九99久久| 欧美zozo另类异族| 国产精品色噜噜| 亚洲图片欧美一区| 久久成人久久鬼色| 成人国产精品免费观看动漫| 日本乱人伦aⅴ精品| 欧美丰满嫩嫩电影| 国产精品毛片a∨一区二区三区| 亚洲人妖av一区二区| 亚洲国产成人av网| 国产凹凸在线观看一区二区| 91免费国产视频网站| 欧美刺激午夜性久久久久久久| 中文字幕第一区综合| 丝袜亚洲另类欧美综合| 国产成人免费视频网站| 欧美久久免费观看| 中文字幕一区二区三中文字幕| 五月天国产精品| 91免费观看在线| 日本高清成人免费播放| 99久久er热在这里只有精品66| 欧美男生操女生| 日韩va欧美va亚洲va久久| 欧美亚州韩日在线看免费版国语版| 日韩欧美激情一区| 亚洲国产精品久久久男人的天堂| 成人精品视频一区二区三区| 欧美日韩国产综合草草| 自拍偷自拍亚洲精品播放| 久久精品99国产精品| 欧美综合天天夜夜久久| 国产精品国产三级国产普通话三级 | 亚洲伦理在线精品| 免费av成人在线| 在线免费观看日韩欧美| 欧美经典一区二区| 国产一区二区三区综合| 欧美酷刑日本凌虐凌虐| 亚洲一区二区三区视频在线| 91老师国产黑色丝袜在线| 亚洲国产精品av| 91在线porny国产在线看| 亚洲乱码日产精品bd| 欧洲精品在线观看| 午夜av一区二区| 欧美日韩色一区| 日韩vs国产vs欧美| 欧美本精品男人aⅴ天堂| 韩国成人福利片在线播放| 国产网站一区二区| a亚洲天堂av| 亚洲永久精品国产| 337p亚洲精品色噜噜狠狠| 理论电影国产精品| 国产亚洲欧美在线| 欧美综合天天夜夜久久| 亚洲h在线观看| wwwwxxxxx欧美| 99视频精品免费视频| 亚洲精品成人少妇| 欧美大片日本大片免费观看| 国产一区二区久久| 亚洲视频一区在线观看| 欧美一区二区观看视频| 成人免费高清视频在线观看| 亚洲自拍偷拍av| 日韩欧美国产系列| 99国产精品久久久久久久久久久| 亚洲午夜久久久久中文字幕久| 日韩三级.com| 日本高清不卡一区| 国产成人免费视频精品含羞草妖精| 一二三区精品福利视频| 国产欧美日韩精品在线| 91精品蜜臀在线一区尤物| 91亚洲永久精品| 极品少妇xxxx精品少妇偷拍| 亚洲国产日韩一区二区| 亚洲国产高清aⅴ视频| 精品国内片67194| 欧美精品黑人性xxxx| 在线观看欧美精品| 99久久夜色精品国产网站| 国产在线看一区| 老司机午夜精品| 性久久久久久久久久久久| 日韩毛片精品高清免费| 国产精品久久网站| 国产精品视频免费看| 久久精品亚洲麻豆av一区二区 | 日韩一区二区三区av| 91国偷自产一区二区三区成为亚洲经典 | 成人永久aaa| 国产伦精品一区二区三区免费迷 | 国产精品一品二品| 国产精品一区二区三区乱码| 麻豆精品精品国产自在97香蕉| 亚洲一区av在线| 亚洲精品国产视频| 亚洲精品国产无套在线观| 亚洲欧美乱综合| 亚洲精品一二三| 亚洲欧洲精品成人久久奇米网| 亚洲图片另类小说| 有码一区二区三区| 亚洲超碰精品一区二区| 免费一级片91| 激情欧美一区二区| 成人激情午夜影院| 欧美日韩一区二区三区视频| 欧美精品在线一区二区| 日韩欧美成人一区| 国产精品毛片高清在线完整版| 亚洲精品免费播放| 久久激五月天综合精品| 成人久久18免费网站麻豆| 欧美三级韩国三级日本一级| 精品精品国产高清a毛片牛牛| 亚洲色欲色欲www| 蜜桃91丨九色丨蝌蚪91桃色| 国产成人高清在线| 欧美精品一二三| 亚洲欧洲三级电影| 另类小说色综合网站| 91丨porny丨中文| 国产欧美日韩另类视频免费观看| 亚洲.国产.中文慕字在线| 国产v综合v亚洲欧| 日韩免费观看高清完整版在线观看| 欧美国产日韩a欧美在线观看| 午夜激情综合网| av中文字幕不卡| 久久久久久久性| 麻豆精品在线观看| 欧美日韩精品高清| 亚洲天堂免费在线观看视频| 国产一区二区毛片| 久久中文娱乐网| 免费视频一区二区| 日韩亚洲欧美在线观看| 亚洲国产精品一区二区www在线 | 成人综合婷婷国产精品久久免费| 777欧美精品| 亚洲午夜久久久久久久久电影院| 97精品视频在线观看自产线路二| www国产成人| 国产最新精品免费| 久久综合国产精品| 韩国视频一区二区| 欧美精品一区二区三区在线播放 | 色综合视频在线观看| 亚洲国产精品99久久久久久久久| 国产成人在线视频网址| 国产日产精品1区| 激情综合色综合久久| 久久视频一区二区| 成人av网站大全| 亚洲精品国产品国语在线app| 在线观看日韩av先锋影音电影院| 婷婷开心激情综合| 欧美精品第1页| 国产精品一二三| 有坂深雪av一区二区精品| 欧美日韩精品久久久| 免费观看一级特黄欧美大片| www日韩大片| 在线亚洲一区观看| 日韩av一区二| 国产日韩av一区二区| av不卡在线播放| 毛片av一区二区三区| 国产精品高潮呻吟| 日韩欧美一区二区久久婷婷| 99在线精品一区二区三区| 青青草国产精品97视觉盛宴| 国产精品成人在线观看|