📄 arp.h
字号:
/**************************************************************************
*
* FILENAME VERSION
*
* ARP.H 4.5
*
* DESCRIPTION
*
* This include file will handle ARP .
*
* DATA STRUCTURES
*
* ARP_ENTRY
* ARP_LAYER
* ARP_RESOLVE_ENTRY
* ARP_RESOLVE_LIST
* ARP_MAC_HEADER
*
* DEPENDENCIES
*
* No other file dependencies
*
****************************************************************************/
//#include "ethernet.h"
#ifndef ARP_H
#define ARP_H
/***************************************************************************/
#define DADDLEN 6 // Define the length of the ethernet header in bytes.
#define IP_ADDR_LEN 4 //Ddefine the length of the IP address
/***********************************************************************/
/* ARP cache
* Data structure for saving low-level information until needed
*/
typedef struct ARP_ENTRY_STRUCT
{
UINT8 arp_ip_addr[4]; /* the IP # in question */
UINT8 arp_flags; /* is this a gateway? */
/* Is this a valid entry. For gateways an */
/* entry is created before the HW addr is */
/* known. This flag indicates when the HW */
/* is resolved. */
UINT32 arp_time; /* time information (live time 20 minute) */
UINT8 arp_mac_addr[DADDLEN]; /* hardware address for this IP address */
UINT8 pad[2];
} ARP_ENTRY;
#define ARP_UP 0x1 /* Is this entry valid. */
#define ARP_GATEWAY 0x2 /* Is this entry for a gateway. */
#define ARP_PERMANENT 0x4 /* Is this entry permanent. */
/* This structure defines an ARP packet. */
typedef struct ARP_LAYER_STRUCT
{
UINT16 arp_hrd; /* hardware type, Ethernet = 1 */
UINT16 arp_pro; /* protocol type to resolve for */
UINT8 arp_hln; /* byte length of hardware addr = 6 for ETNET */
UINT8 arp_pln; /* byte length of protocol = 4 for IP */
UINT16 arp_op; /* opcode, request = 1, reply = 2, RARP = 3,4 */
UINT8 arp_sha[6]; /* Source Hardware Address */
UINT8 arp_spa[4]; /* Source protocol address. */
UINT8 arp_tha[6]; /* Target Hardware Address */
UINT8 arp_tpa[4]; /* Target protocol address. */
/*
* the final four fields (contained in 'rest') are:
* sender hardware address: sha hln bytes
* sender protocol address: spa pln bytes
* target hardware address: tha hln bytes
* target protocol address: tpa pln bytes
*/
} ARP_LAYER;
/*************************************************************************/
/* Dave Plummer's Address Resolution Protocol (ARP) (RFC-826) and
* Finlayson, Mann, Mogul and Theimer's Reverse ARP packets.
*
* Note that the 2 byte ints are byte-swapped. The protocols calls for
* in-order bytes, and the PC is lo-hi ordered.
*
*/
#define RARPR 0x0004 /* RARP reply, from host, needs swap */
#define RARPQ 0x0003 /* RARP request, needs swapping */
#define ARPREP 0x0002 /* reply, byte swapped when used */
#define ARPREQ 0x0001 /* request, byte-swapped when used */
#define ARPPRO 0x0800 /* IP protocol, needs swapping */
#define RARP_MAX_ATTEMPTS 5
/* ARP_RESOLVE_STRUCT is used to keep track the resolution of MAC layer
addresses.
*/
/* This structure is used by ARP to build the MAC layer header in before
passing it to the MAC layer send routine. */
//***********************************
#define wait_buffer_num 1
// the buffer save the ip waiting send to ethernet.
typedef struct IP_buffer_struct
{
UINT8 tipnum[4];
UINT8 thardware[6];
UINT16 time;
UINT8 send_packet[1400];
UINT16 send_packet_len;
UINT8 flag; // 0 is blank ,1 is full
}IP_buffer;
/* Function Prototypes */
void ARP_Init();
UINT8 ARP_Find_Entry(UINT8 *dest);
UINT8 ARP_Resolve(UINT8*ip_dest,
UINT8 *mac_dest, UINT8 *buf_ptr,UINT16 buf_len);
void ARP_Request(UINT8 *tip, UINT8 *thardware);
INT16 ARP_Cache_Update(UINT8 * ipn, UINT8 *hrdn, UINT8 flags);
void ARP_Reply(UINT8 *thardware, UINT8 * tipnum);
//VOID ARP_Event(UINT16 id);
void ARP_Interpret(ARP_LAYER *a_pkt);
void ARP_Build_Pkt ( UINT8 * tipnum, ARP_LAYER *arp_packet,
UINT8 *thardware, UINT8 *sipnum, UINT16 pkt_type);
void ARP_Check_Events(ARP_LAYER *a_pkt);
/* Offsets of the ARP header fields. */
#define ARP_HRD_OFFSET 0
#define ARP_PRO_OFFSET 2
#define ARP_HLN_OFFSET 4
#define ARP_PLN_OFFSET 5
#define ARP_OP_OFFSET 6
#define ARP_SHA_OFFSET 8
#define ARP_SPA_OFFSET 14
#define ARP_THA_OFFSET 18
#define ARP_TPA_OFFSET 24
#endif /* ARP_H */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -