arp.c

来自「MC9S12NE64串口与网络通信源代码」· C语言 代码 · 共 55 行

C
55
字号
 /*****************************************************************************
 *
 * File Name     : arp.c
 *
 * DESCRIPTION   : Used for ARP Protocol  
 *
 * Written by houlei  @2004.10.10 Tsinghua University 
 * Recently Modified by houlei @2004.12.10
 *****************************************************************************/

#include "ethernet.h"
#include "ne64api.h"
#include "MOTTYPES.h"
#include "etherinit.h"
#include "IO_MAP.h"



extern tU08 sed_Send( tU16 );
extern void Move( tU08 *, tU08 *, tU16 );
extern tU08 *sed_FormatPacket( tU08 *, tU08 *, tU16 );
extern void putb_ser(tU08);
extern eth_HwAddress sed_lclEthAddr;
extern in_HwAddress  sin_lclINAddr;
extern tU08 *EtherPtr;

tU08 sar_CheckPacket(arp_Header *ap)
{
	arp_Header *op;

	if ( ap->hwType != arp_TypeEther || /* have ethernet hardware, */
		ap->protType != 0x800 ||       /* and internet software, */
		ap->opcode != ARP_REQUEST ||   /* and be a resolution req. */
		ap->dstIPAddr != sin_lclINAddr ) /* for my addr. */ 
		{
			return ( 0 );                  /* .... or we ignore it. */
		}
	
	/* format response. */
	op = (arp_Header *)sed_FormatPacket(EtherPtr,ap->srcEthAddr, 0x806);
	op->hwType = arp_TypeEther;
	op->protType = 0x0800;
	op->hwProtAddrLen = (sizeof(eth_HwAddress) << 8) + sizeof(in_HwAddress);
	op->opcode = ARP_REPLY;
	op->dstIPAddr = ap->srcIPAddr;
	op->srcIPAddr = sin_lclINAddr;
	Move(op->dstEthAddr, ap->srcEthAddr, sizeof(eth_HwAddress));
	Move(op->srcEthAddr, sed_lclEthAddr, sizeof(eth_HwAddress));

	sed_Send(sizeof(arp_Header));

	return ( 1 );
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?