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

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

?? arp.c

?? 51的web服務器
?? 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一区二区三区| 美女任你摸久久| 欧美成人一区二区三区在线观看 | 欧美嫩在线观看| 天堂午夜影视日韩欧美一区二区| 91成人网在线| 麻豆精品一区二区综合av| 欧美日韩精品三区| 亚洲综合精品自拍| 91精品国产综合久久蜜臀| 韩日精品视频一区| 成人免费在线播放视频| 在线免费观看一区| 狠狠色综合播放一区二区| 国产精品美女一区二区在线观看| 成人av在线播放网站| 丝袜美腿亚洲色图| 成人av在线一区二区三区| 欧美一级二级在线观看| 亚洲一区二区三区视频在线播放 | 久久精品综合网| 国产精一品亚洲二区在线视频| 精品少妇一区二区三区在线播放| 97国产一区二区| 欧美国产一区在线| 午夜电影一区二区| 成a人片国产精品| 欧美一区二区三区四区在线观看| 日韩精品一区二区三区在线播放| 国产精品久久久久久妇女6080| 亚洲婷婷国产精品电影人久久| 久久99精品国产麻豆婷婷| 欧美一级高清大全免费观看| 蜜臀99久久精品久久久久久软件| 色婷婷综合久色| 国产日韩亚洲欧美综合| 国产精品一区在线观看乱码| 亚洲天堂成人在线观看| 欧美亚洲国产一卡| 国产福利91精品| 日本最新不卡在线| 国产日韩精品一区| 欧美精品v国产精品v日韩精品| 国内精品国产三级国产a久久 | 国产精品国产馆在线真实露脸| 99国产精品久| 国精产品一区一区三区mba桃花| 亚洲欧美视频在线观看视频| 69堂精品视频| 日韩一区二区在线播放| 国产米奇在线777精品观看| 成人黄色a**站在线观看| 国产精品免费观看视频| 国产盗摄视频一区二区三区| 亚洲一区二区三区美女| 欧美视频在线观看一区二区| 综合激情成人伊人| 国产精品沙发午睡系列990531| 欧美精品丝袜中出| 欧美精品在线一区二区| 久久99国产精品久久| 欧美亚洲国产bt| 国产suv精品一区二区三区| 久久理论电影网| av不卡在线播放| 美女视频免费一区| 国产午夜亚洲精品羞羞网站| 国产盗摄精品一区二区三区在线| 日韩高清不卡一区二区三区| 青青青伊人色综合久久| 亚洲最色的网站| 婷婷国产在线综合| 亚洲综合一区在线| 亚洲欧美区自拍先锋| 中文字幕一区二区三区四区不卡 | 亚洲视频一区在线观看| 久久久亚洲午夜电影| 欧美激情在线观看视频免费| 中文字幕一区二区三区四区不卡 | 性感美女极品91精品| 日韩高清一区在线| 91视频免费播放| 精品av久久707| 日日摸夜夜添夜夜添国产精品| 激情六月婷婷综合| 在线精品观看国产| 国产精品免费人成网站| 激情综合网av| 欧美一卡二卡三卡| 亚洲国产成人av| 不卡大黄网站免费看| 欧美精品一区二区精品网| 亚洲免费在线电影| 99精品视频在线免费观看| 国产亚洲欧洲一区高清在线观看| 亚洲v中文字幕| 欧美性色黄大片手机版| 亚洲欧美日韩一区| 91麻豆自制传媒国产之光| 国产精品天美传媒| 国产超碰在线一区| 国产精品美女久久久久久久久久久| 国产成人亚洲精品狼色在线| 欧美成人女星排名| 国产精品18久久久| 国产精品网站在线播放| av午夜一区麻豆| 一区二区国产盗摄色噜噜| 在线中文字幕一区二区| 亚洲在线中文字幕| 91精品国产全国免费观看| 精品一区二区三区视频在线观看| 在线播放视频一区| 精品一区二区三区的国产在线播放| 日韩一区二区三区在线视频| 国产一区欧美日韩| 亚洲精选视频免费看| 日韩亚洲欧美高清| 国产福利电影一区二区三区| 亚洲黄网站在线观看| 91精品婷婷国产综合久久| 国产精品66部| 一级特黄大欧美久久久| 精品久久一二三区| 91亚洲精品久久久蜜桃| 久久不见久久见免费视频1 | 欧美日韩一区二区不卡| 麻豆国产欧美一区二区三区| 中文字幕色av一区二区三区| 欧美一区日韩一区| 色狠狠色噜噜噜综合网| 国产精品一品二品| 亚洲国产日韩a在线播放性色| 日韩三区在线观看| 欧美视频第二页| 在线观看免费亚洲| 丝袜a∨在线一区二区三区不卡| 中文字幕欧美激情| 国产三级欧美三级| 26uuu精品一区二区三区四区在线| 在线精品视频一区二区三四| 国产精品一线二线三线| 麻豆精品视频在线观看视频| 亚洲精品中文在线| 国产精品日日摸夜夜摸av| 2023国产精品| 欧美精品一区二区三区蜜桃视频 | 成人教育av在线| 国产精品亚洲一区二区三区妖精 | 精品一区二区三区视频在线观看| 亚洲18色成人| 视频在线观看一区| 日韩不卡免费视频| 日本aⅴ免费视频一区二区三区 | 成人性视频网站| 国产成人av影院| av一区二区不卡| 欧美自拍偷拍一区| 欧美日韩国产一级| 欧美电影精品一区二区| 久久久高清一区二区三区| 欧美国产日韩一二三区| 亚洲欧美一区二区久久| 午夜伦欧美伦电影理论片| 蜜臀av性久久久久蜜臀aⅴ流畅| 久久爱www久久做| 国产成人精品亚洲日本在线桃色| 不卡电影免费在线播放一区| 欧美午夜一区二区三区免费大片| 日韩一级高清毛片| 亚洲欧美一区二区三区孕妇| 日日夜夜精品视频天天综合网| 国产精品一区二区在线观看网站| 成人一级黄色片| 91精品国产综合久久精品app| 亚洲精品一区二区三区99| 一区二区三区欧美激情| 精品一区二区三区免费视频| 色婷婷亚洲婷婷| 中文av字幕一区| 国产精品一区二区在线播放| 7777精品伊人久久久大香线蕉超级流畅 | 亚洲精品在线一区二区| 亚洲国产一区二区a毛片| jlzzjlzz亚洲日本少妇| 精品国产露脸精彩对白 | 欧美极品美女视频| 精品一区二区精品| 欧美一区二区观看视频| 亚洲国产日韩一区二区| 色菇凉天天综合网| 亚洲美女在线国产| 一本色道久久综合亚洲91| 国产精品毛片久久久久久久| 国产激情精品久久久第一区二区| 精品国产制服丝袜高跟| 日本视频在线一区| 精品粉嫩aⅴ一区二区三区四区| 亚洲午夜三级在线| 欧美无砖专区一中文字|