⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 arp.c

📁 ATmega103、ATmega128做的开发板web server源码
💻 C
字号:
/******************************************************************
* arp.c:	Address resolution protocol
* 
* Copyright (c) 2001 Atmel Corporation.
* All Rights Reserved.
*
* You are autorized to use, copy and distribute this software only at 
* a single site (the term "site" meaning a single company location). 
* This copyright notice must be included in any copy, modification 
* or portion of this software merged into another program.
* 
* This software is licenced solely for use with Atmel AVR micro 
* controller family. The software may not be modified to execute on 
* any other microcontroller architectures
*
* This software is provided "as is"; Without warranties either express
* or implied, including any warranty regarding merchantability, 
* fitness for a particular purpose or noninfringement. 
*
* In no event shall Atmel or its suppliers be liable for any special, 
* indirect,incidential or concequential damages resulting from the 
* use or inability to use this software.
*
* Revision history:
*
* January 17, 2001:   Version 1.0   Created by JB
* July 13, 2001		  Version 1.2     JB
* 					- Changed to IAR compiler V2.25
*					- Renamed flash file functions to avoid conflict with 
*					  standard file I/O names	
*					- Bug fixes in HTTP
*					- Speed optimization in TCP 
*
*******************************************************************/

#include "ethernet.h"
#include "arp.h" 
#include "ip.h"

extern unsigned int frame[FRAME_SIZE];
extern config_type ID;
 
/*The frame received is an ARP request, fill out header and send frame*/
void receiveARP( void )
{
  unsigned int *frameptr = &frame[ARP_HARDTYPE];
  unsigned int *frameptr2 = &frame[ARP_OPCODE];
  unsigned int *IDptr;
  unsigned char i;
      
  if ( *frameptr++ == 1 )                   //Check hardware type
  {
    if ( *frameptr++ == 0x0800 )            //Check protocol type
    {
      if ( *frameptr++ == 0x0604 )            //Check address length
      {
        if ( *frameptr++ == 0x0001 )          //Check if it is a request
        {
          frameptr = &frame[ARP_TARGET_IP0];
          if ( *frameptr++ == ID.IP0 )       
          {
            if ( *frameptr++ == ID.IP1 )     //Check IP address
            {
      	      frameptr = &frame[ARP_TARGET_MAC0];
              /*Make reply header*/
		      *frameptr2++ = 0x0002;                	//OPCODE
              i = 5;
              do
              {
                *frameptr++ = *frameptr2++;         //TARGET = SENDER
              } while(--i);
              frameptr = &frame[ARP_SENDER_MAC0];
              IDptr = (unsigned int *)&ID;
		      i = 5;
              do
              {
                *frameptr++ = *IDptr++;
              } while(--i);
              sendFrame(28, 0x0806, frame[ARP_TARGET_IP0], frame[ARP_TARGET_IP1]);
            }
          }
        }
      }
    }
  }   
}

/*This function is used when the ethernet address is unknown.
  ARP sends a request to the IP address given by ip0 and ip*/
void sendARP(unsigned int ip0, unsigned int ip1)
{
  unsigned int *frameptr = &frame[ARP_HARDTYPE];
  unsigned int *IDptr;
  unsigned char i;

  /*Make ARP request header*/
  *frameptr++ = 1;             //HARDTYPE
  *frameptr++ = 0x0800;        //PROTTYPE
  *frameptr++ = 0x0604;        //LENGTH
  *frameptr++ = 1;             //OPCODE
  i = 5;
  IDptr = (unsigned int *)&ID;
  do
  {
    *frameptr++ = *IDptr++;
  } while(--i);

  *frameptr++ = 0;             //TARGET_MAC0
  *frameptr++ = 0;             //TARGET_MAC1
  *frameptr++ = 0;             //TARGET_MAC2
  *frameptr++ = ip0;           //TARGET_IP0
  *frameptr++ = ip1;           //TARGET_IP1
  sendFrame(28, 0x0806, 0xffff, 0xffff);
}











⌨️ 快捷键说明

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