📄 ethernet.h
字号:
/******************************************************************************
*
* File Name : ethernet.h
* Description : Ethernet Frame Header type definition
*
*
******************************************************************************/
#include "MOTTYPES.h"
#ifndef ETHERNET_H
#define ETHERNET_H
/* Symbolic constants */
#define ETH_ADDRESS_LEN 6
/* Protocol Constants */
#define ETH_HEADER_LEN 14
#define PROTOCOL_IP 0x0800 /**< IP over Ethernet */
#define PROTOCOL_ARP 0x0806 /**< ARP over Ethernet */
/** \struct ethernet_frame
* \brief Ethernet packet header
*
* Ethernet Frame Header type
*/
typedef struct
{
tU08 destination[ETH_ADDRESS_LEN]; /**< destination hardware address */
tU08 source[ETH_ADDRESS_LEN]; /**< source hardware address*/
tU16 frame_size; /**< size of the received packet */
tU16 protocol; /**< protocol field of Ethernet header */
tU16 buf_index; /**< Address in the controllers buffer for data */
}ethernet_frame;
typedef union uMACADUnion
{
tU16 Word[3]; /* MAC Address bits 47 to 0 */
tU08 Byte[6];
} tMACADStr;
typedef union uMCHASHUnion
{
tU16 Word[4]; /* Multicast Hash Table bits 63 to 0 */
tU08 Byte[8];
}tMCHASHStr;
/* Ethernet Frame Header type */
/** \struct tFRHEAD
* \brief Ethernet Frame Header type
*
* Ethernet Frame Header type
*/
typedef struct
{
tU08 da[6]; /**< destination address */
tU08 sa[6]; /**< source address */
tU16 ft; /**< frame type */
}tFRHEAD;
typedef tFRHEAD * pFRHEAD;
#define HA_SIZE 6 /**< hardware address size */
#define PA_SIZE 4 /**< protocol address size */
/*****************************declare the ip head used in files************************************/
/******************************* ip.h **************************************************/
typedef struct _eth_Header {
eth_HwAddress destination;
eth_HwAddress source;
tU16 type;
} eth_Header;
typedef struct _in_Header {
tU16 vht;
tU16 length;
tU16 identification;
tU16 frag;
tU16 ttlProtocol;
tU16 checksum;
in_HwAddress source;
in_HwAddress destination;
} in_Header;
#define in_GetVersion(ip) (((ip)->vht >> 12) & 0xf)
#define in_GetHdrlen(ip) (((ip)->vht >> 8) & 0xf)
#define in_GetHdrlenBytes(ip) (((ip)->vht >> 6) & 0x3c)
#define in_GetTos(ip) ((ip)->vht & 0xff)
#define in_GetTTL(ip) ((ip)->ttlProtocol >> 8)
#define in_GetProtocol(ip) ((ip)->ttlProtocol & 0xff)
#define ip_prot_icmp 0x01
#define ip_prot_tcp 0x06
#define ip_prot_egp 0x08
#define ip_prot_udp 0x11
void ip_daemon(void);
tU16 checksum(tU16 *dp, tU16 length);
tU08 sed_CheckPacket( tU08 *BufLocation, tU16 expectedType );
/*****************************declare the arp head used in files************************************/
/*********************************** arp.h **************************************************/
#define arp_TypeEther 1 /* ARP type of Ethernet address */
/* harp op codes */
#define ARP_REQUEST 1
#define ARP_REPLY 2
/*
* Arp header
*/
typedef struct _arp_Header {
tU16 hwType;
tU16 protType;
tU16 hwProtAddrLen; /* hw and prot addr len */
tU16 opcode;
eth_HwAddress srcEthAddr;
in_HwAddress srcIPAddr;
eth_HwAddress dstEthAddr;
in_HwAddress dstIPAddr;
} arp_Header;
tU08 sar_CheckPacket(arp_Header *ap);
/*****************************declare the icmp head used in files************************************/
/***********************************icmp.h***********************************************************/
#define ICMP_ECHOREPLY 0 /* Echo Reply */
#define ICMP_DEST_UNREACH 3 /* Destination Unreachable */
#define ICMP_SOURCE_QUENCH 4 /* Source Quench */
#define ICMP_REDIRECT 5 /* Redirect (change route) */
#define ICMP_ECHO 8 /* Echo Request */
#define ICMP_TIME_EXCEEDED 11 /* Time Exceeded */
#define ICMP_PARAMETERPROB 12 /* Parameter Problem */
#define ICMP_TIMESTAMP 13 /* Timestamp Request */
#define ICMP_TIMESTAMPREPLY 14 /* Timestamp Reply */
#define ICMP_INFO_REQUEST 15 /* Information Request */
#define ICMP_INFO_REPLY 16 /* Information Reply */
#define ICMP_ADDRESS 17 /* Address Mask Request */
#define ICMP_ADDRESSREPLY 18 /* Address Mask Reply */
#define NR_ICMP_TYPES 18
/* Codes for UNREACH. */
#define ICMP_NET_UNREACH 0 /* Network Unreachable */
#define ICMP_HOST_UNREACH 1 /* Host Unreachable */
#define ICMP_PROT_UNREACH 2 /* Protocol Unreachable */
#define ICMP_PORT_UNREACH 3 /* Port Unreachable */
#define ICMP_FRAG_NEEDED 4 /* Fragmentation Needed/DF set */
#define ICMP_SR_FAILED 5 /* Source Route failed */
#define ICMP_NET_UNKNOWN 6
#define ICMP_HOST_UNKNOWN 7
#define ICMP_HOST_ISOLATED 8
#define ICMP_NET_ANO 9
#define ICMP_HOST_ANO 10
#define ICMP_NET_UNR_TOS 11
#define ICMP_HOST_UNR_TOS 12
#define ICMP_PKT_FILTERED 13 /* Packet filtered */
#define ICMP_PREC_VIOLATION 14 /* Precedence violation */
#define ICMP_PREC_CUTOFF 15 /* Precedence cut off */
#define NR_ICMP_UNREACH 15 /* instead of hardcoding immediate value */
/* Codes for REDIRECT. */
#define ICMP_REDIR_NET 0 /* Redirect Net */
#define ICMP_REDIR_HOST 1 /* Redirect Host */
#define ICMP_REDIR_NETTOS 2 /* Redirect Net for TOS */
#define ICMP_REDIR_HOSTTOS 3 /* Redirect Host for TOS */
/* Codes for TIME_EXCEEDED. */
#define ICMP_EXC_TTL 0 /* TTL count exceeded */
#define ICMP_EXC_FRAGTIME 1 /* Fragment Reass time exceeded */
typedef struct _icmphdr {
tU08 icmp_type;
tU08 icmp_code;
tU16 icmp_checksum;
union{
tU08 ih_pptr;
struct echo{
tU16 icmp_id;
tU16 icmp_sequence;
} echo;
tU16 ih_void;
struct icmp_pmtu {
tU16 ipm_void;
tU16 ipm_nextmtu;
}icmp_pmtu;
}icmp_un;
} icmphdr;
/*
* constants for (set|get)sockopt
*/
#define ICMP_FILTER 1
void icmp_in(in_Header *ip_icmp,tU16 ip_len);
void icmp_echo(in_Header *ip,tU16 icmp_len) ;
/*****************************declare the udp head used in files************************************/
/****************************************udp.h**************************************/
typedef struct _tcpudp_PseudoHeader {
tU08 mbz;
tU08 protocol;
tU16 length;
in_HwAddress source;
in_HwAddress destination;
} tcpudp_PseudoHeader;
typedef struct _udp_Header {
tU16 sport;
tU16 dport;
tU16 length;
tU16 checksum;
} udp_Header;
typedef struct _udp_cks_int {
tcpudp_PseudoHeader tuph;
udp_Header uh;
} udp_cks_int;
typedef struct _udpsocket{ //added for udp store
eth_HwAddress des_ethaddr;
tU32 des_ip;
tU16 des_port;
} udpsocket;
typedef struct _udppacket{
eth_Header ethhead;
in_Header iphead;
udp_Header udphead;
} udppacket;
void udp_receive(in_Header *ip);
void udp_init(void);
void udp_store(tU08 * ip);
void Out_chars(tU08 * charpoint, tU16 charlength);
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -