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

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

?? ip.c

?? 實現(xiàn)了8位單片機的網(wǎng)絡(luò)通信
?? C
字號:
//-----------------------------------------------------------------------------
// Net IP.C
// This module is the IP layer
// Refer to RFC 791, 1122, and RFC 815 (fragmentation)
//-----------------------------------------------------------------------------
#include <string.h>
#include "C8051f.h"
#include "net.h"
#include "cksum.h"
#include "arp.h"
#include "eth.h"
#include "icmp.h"
#include "udp.h"
#include "serial.h"
#include "tcp.h"
#include "ip.h"

extern UCHAR idata debug;
extern ULONG code my_ipaddr;
WAIT xdata wait;


//------------------------------------------------------------------------
// This handles outgoing IP datagrams.  It adds the 20 byte IP header
// and checksum then forwards the IP datagram to the Ethernet layer
// for sending. See "TCP/IP Illustrated, Volume 1" Sect 3.2
//------------------------------------------------------------------------
void ip_send(UCHAR xdata * outbuf, ULONG ipaddr, UCHAR proto_id, UINT len)
{
   IP_HEADER xdata * ip;
   UCHAR xdata * hwaddr;
   static UINT ip_ident = 0;
   
   ip = (IP_HEADER xdata *)(outbuf + 14);
   ip->ver_len = 0x45;          // IPv4 with 20 byte header
   ip->type_of_service = 0;
   ip->total_length = 20 + len;
   ip->identifier = ip_ident++;     // sequential identifier
   ip->fragment_info = 0;           // not fragmented
   ip->time_to_live = 32;           // max hops
   ip->protocol_id = proto_id;      // type of payload
   ip->header_cksum = 0;
   ip->source_ipaddr = my_ipaddr;
   
   // Outgoing IP address
   ip->dest_ipaddr = ipaddr;

   // Compute and insert complement of checksum of ip header
   // Outgoing ip header length is always 20 bytes
   ip->header_cksum = ~cksum(outbuf + 14, 20);
   
   // Use ARP to get hardware address to send this to
   hwaddr = arp_resolve(ip->dest_ipaddr);
	
	// Null means that the ARP resolver did not find the IP address
	// in its cache so had to send an ARP request
	if (hwaddr == NULL)
	{
		// Fill in the destination information so ehrn the ARP response
		// arrives we can identify it and know what to do when we get it
      wait.buf = outbuf;
		wait.ipaddr = ip->dest_ipaddr;
		wait.proto_id = proto_id;
		wait.len = len;
		wait.timer = ARP_TIMEOUT; 
      return;
	}	
	
	eth_send(outbuf, hwaddr, IP_PACKET, 20 + len);
}



//------------------------------------------------------------------------
// This handles incoming IP datagrams from the Ethernet layer
// See "TCP/IP Illustrated, Volume 1" Sect 3.2
//------------------------------------------------------------------------
void ip_rcve(UCHAR xdata * inbuf)
{
	IP_HEADER xdata * ip;
	UINT idata header_len, payload_len;
		
   ip = (IP_HEADER xdata *)(inbuf + 14);
            
   // Make sure it is addressed to my IP address
   if (ip->dest_ipaddr != my_ipaddr) return;

   // Validate checksum of ip header
	header_len = 4 * (0x0F & ip->ver_len);
	payload_len = ip->total_length - header_len;
   if (cksum(inbuf + 14, header_len) != 0xFFFF)
	{
	  	if (debug) serial_send("IP:  Error, cksum bad\r");
	   return; 
   }
	
	// Make sure incoming message is IP version 4
	if ((ip->ver_len >> 4) != 0x04)
	{
		if (debug) serial_send("IP:  Error, not IPv4\r");
   	return;
	}

	// Make sure incoming message is not fragmented because
   // we cannot handle fragmented messages
   if ((ip->fragment_info & 0x3FFF) != 0)
   {
      if (debug) serial_send("IP:  Error, fragmented msg rcvd\r");
	   return; 
   }

   // At this point we have received a valid IP datagram addressed
   // to me.  We do not use header options, and do not forward
   // messages, so in the unlikely event there are header options,
   // delete them and shift the data down. The advantage is that
   // layers such as UDP and TCP know where their data starts
	if (header_len > 20)
	{
		if (debug) serial_send("IP: Rcvd header > 20 bytes\r");
   			
      // Use memmove because of overlap
      memmove(inbuf + 34, inbuf + 14 + header_len, payload_len);

		// Adjust info to reflect the move
		header_len = 20;
		ip->ver_len = 0x45;
		ip->total_length = 20 + payload_len;
	}
	
	
	// Look at protocol ID byte and call the appropriate
   // function to handle the received message.  See 
   // "TCP/IP Illustrated, Volume 1" Sect 1.7 and RFC 791
   // for values for various protocols
   switch (ip->protocol_id)
	{
	   case ICMP_TYPE:
      if (debug) serial_send("IP:  ICMP pkt rcvd\r");
      icmp_rcve(inbuf, payload_len);
		break;

      case IGMP_TYPE:
		// We cannot handle IGMP messages
		if (debug) serial_send("IP:  Error, IGMP pkt rcvd\r");
		break;
		  
		case UDP_TYPE:
		if (debug) serial_send("IP:  UDP pkt rcvd\r");
      udp_rcve(inbuf, payload_len);
		break;

		case TCP_TYPE:   
		if (debug) serial_send("IP:  TCP pkt rcvd\r");
      tcp_rcve(inbuf, payload_len);
		break;

      default:
      if (debug) serial_send("IP:  Unknown IP proto id rcvd\r");
      break;
   }
}



?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
欧美大片一区二区| 中文字幕一区在线观看视频| 欧美日韩精品一区二区三区蜜桃| 91亚洲永久精品| 成人美女在线视频| 成人精品视频一区二区三区| 国产福利一区在线观看| 国产精品91一区二区| 国产一区二区三区不卡在线观看| 另类成人小视频在线| 日韩av电影一区| 婷婷国产在线综合| 日产欧产美韩系列久久99| 日韩影院免费视频| 麻豆国产欧美日韩综合精品二区 | 国产精品嫩草影院com| 国产色一区二区| 中文字幕精品—区二区四季| 国产精品妹子av| 亚洲日本青草视频在线怡红院| 中文字幕亚洲成人| 亚洲精品欧美激情| 亚洲自拍欧美精品| 青青草国产精品亚洲专区无| 捆绑紧缚一区二区三区视频| 国产一区三区三区| 成人三级伦理片| 在线观看视频一区二区| 欧美日韩精品高清| 欧美va亚洲va在线观看蝴蝶网| 国产亚洲一区二区三区四区| 亚洲欧洲av色图| 亚洲国产欧美在线| 九九视频精品免费| av电影在线观看一区| 欧美色图12p| 精品久久久久久综合日本欧美| 中文一区一区三区高中清不卡| 亚洲另类在线视频| 秋霞电影一区二区| 成人免费毛片嘿嘿连载视频| 欧美午夜片在线看| 精品国产一区二区精华| 中文在线资源观看网站视频免费不卡| 亚洲精品一二三| 蜜臀久久99精品久久久画质超高清| 国产一区二区伦理| 色狠狠综合天天综合综合| 日韩欧美一卡二卡| 亚洲视频一区二区在线观看| 天天射综合影视| 成人午夜视频在线| 91精品国产综合久久国产大片| 国产婷婷精品av在线| 亚洲制服丝袜av| 国产一区二区三区不卡在线观看| 日本久久一区二区| 久久久精品蜜桃| 亚洲影院免费观看| 国产成人8x视频一区二区| 精品视频免费在线| 国产精品乱人伦中文| 日韩av中文字幕一区二区| 成人国产一区二区三区精品| 欧美大度的电影原声| 一区二区三区中文免费| 国产乱对白刺激视频不卡| 在线观看91av| 亚洲美女免费在线| 国产不卡视频在线播放| 欧美一区二区三区视频免费| 亚洲猫色日本管| 国产成人综合亚洲91猫咪| 欧美一区二区视频免费观看| 亚洲同性gay激情无套| 国产一本一道久久香蕉| 91精品福利在线一区二区三区| 一区二区三区精品视频在线| 国产精品一二三四| 欧美mv和日韩mv国产网站| 亚洲成人福利片| 91精品办公室少妇高潮对白| 欧美激情一区二区三区蜜桃视频| 老司机午夜精品99久久| 在线成人午夜影院| 一区二区三区 在线观看视频| 成人精品小蝌蚪| 国产日韩欧美综合在线| 精品一区二区免费| 日韩一区二区三区在线视频| 亚洲a一区二区| 欧美在线你懂的| 亚洲精品视频在线观看免费| 成人ar影院免费观看视频| 精品国产亚洲在线| 开心九九激情九九欧美日韩精美视频电影 | 久久久亚洲综合| 狠狠色综合色综合网络| 日韩欧美的一区| 久久精品国产99国产精品| 日韩一级二级三级精品视频| 日本午夜精品视频在线观看| 欧美日韩免费电影| 亚洲6080在线| 在线播放中文字幕一区| 亚洲1区2区3区视频| 欧美日韩精品三区| 日韩av在线免费观看不卡| 日韩一区二区免费电影| 蜜桃视频在线一区| 欧美一区午夜视频在线观看| 五月天国产精品| 7799精品视频| 蜜桃视频一区二区| 精品免费一区二区三区| 国产精品911| 国产精品传媒在线| 色噜噜狠狠成人中文综合| 一区二区三区精品视频在线| 777欧美精品| 麻豆精品一区二区av白丝在线| www国产精品av| 国产高清成人在线| 亚洲欧美国产77777| 欧洲人成人精品| 奇米色777欧美一区二区| 久久一区二区视频| 成人av手机在线观看| 亚洲无人区一区| 91精品国产麻豆| 国产毛片精品国产一区二区三区| 国产精品视频免费看| 色综合天天视频在线观看| 亚洲高清三级视频| 欧美tk丨vk视频| 成人av网站免费| 婷婷综合另类小说色区| 欧美xxx久久| 99久久99久久免费精品蜜臀| 亚洲成a人片在线不卡一二三区| 日韩欧美亚洲另类制服综合在线| 国产91精品一区二区麻豆网站| 亚洲精品欧美激情| 日韩精品一区国产麻豆| 不卡的av中国片| 日韩二区三区四区| 国产亚洲午夜高清国产拍精品| 色噜噜狠狠色综合中国| 老司机精品视频线观看86| 国产欧美一区二区精品婷婷| 欧美在线一二三| 国产一区 二区 三区一级| 亚洲综合精品久久| 国产欧美中文在线| 在线观看亚洲精品视频| 国产主播一区二区| 亚洲一区在线观看免费| 久久久久国产精品人| 欧美在线观看18| 国产成人在线免费观看| 一区二区不卡在线播放| 久久亚洲春色中文字幕久久久| 在线免费精品视频| 国模大尺度一区二区三区| 亚洲最新在线观看| 国产欧美精品一区二区三区四区| 欧美日韩免费在线视频| 成人国产免费视频| 久久97超碰国产精品超碰| 亚洲精品自拍动漫在线| 欧美国产日韩一二三区| 日韩一区二区中文字幕| 欧美综合在线视频| 成人影视亚洲图片在线| 日本成人在线看| 亚洲精品一二三四区| 国产午夜一区二区三区| 4438x成人网最大色成网站| 不卡一区二区三区四区| 久久99国产乱子伦精品免费| 视频一区中文字幕| 亚洲三级免费电影| 国产亚洲精品7777| 精品剧情v国产在线观看在线| 欧美三级视频在线观看| 91久久一区二区| 欧美伦理电影网| 91丝袜高跟美女视频| 高清不卡在线观看av| 黄页视频在线91| 青娱乐精品视频在线| 亚洲一区精品在线| 亚洲欧美激情在线| 中文字幕中文在线不卡住| 久久久综合精品| 久久日韩粉嫩一区二区三区| 精品久久人人做人人爽| 精品入口麻豆88视频| 欧美不卡一区二区三区| 欧美mv和日韩mv的网站|