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

📄 ip_udp.h

📁 AVR单片机基础上的以太网协议编程
💻 H
字号:
/**************************************************************************
**
**    文件: IP_UDP.h
**    描述: 该文件完成与IP/UDP协议相关的宏定义及报文结构定义
**
*************************************************************************/

#ifndef IP_UDP_h
#define IP_UDP_h

//include user defined file
#include  "Define.h"

//relevant to Ether header
#define Ether_Type_ARP      0x0806  //ARP协议
#define Ether_Type_IP       0x0800  //IP协议

//relevant to ARP message 
#define ARP_REQ             0x0001  //ARP请求
#define ARP_ACK             0x0002  //ARP应答

//relevant to IP message
#define IP_Version          4       //IPv4版本
#define IP_Header_MinLen    20      //没有选项的IP头长度
#define IP_Header_Len       ((R_Pip->IP_VerLen & 0x0f)<<2) //接收到的IP头长度
#define IP_Tos_Value        0       //服务类型为一般服务
#define IP_TTL_Value        255     //生存时间设置为最大
#define IP_ICMP             1       //IP上层协议标识ICMP
#define IP_TCP              6       //IP上层协议标识TCP
#define IP_UDP              17      //IP上层协议标识UDP

//revelant to ICMP message
#define ICMP_Num            32      //Ping测试数据长度
#define ICMP_Type_REQ       8       //Ping请求
#define ICMP_Type_ACK       0       //Ping应答

//revelant to UDP message
#define UDP_Header_Len      8      //UDP报头长度
#define EPA_Port            0x88bc //EPA端口号

//Ether header
struct Ether_Header
{
    uchar Ether_Dest_MAC[6]; //以太网目标MAC地址
    uchar Ether_Sour_MAC[6]; //以太网源MAC地址
    uint  Ether_Type;        //以太网帧类型
};

//ARP message
struct ARP
{
    uint  ARP_Net_Type;     //以太网为0x0001
    uint  ARP_Protocol;     //要转换的协议类型,IP协议为0x0800
    uchar ARP_MAC_Len;      //MAC地址字节长度为0x06
    uchar ARP_IP_Len;       //IP地址字节长度为0x04
    uint  ARP_Operator;     //操作类型ARP_REQ=0x0001,ARP_ACK=0x0002
    uchar ARP_Sour_MAC[6];  //发送方MAC地址
    uchar ARP_Sour_IP[4];   //发送方IP地址
    uchar ARP_Dest_MAC[6];  //接收方MAC地址
    uchar ARP_Dest_IP[4];   //接收方IP地址
};

//IP message
struct IP
{
    uchar IP_VerLen;     //IP版本以及头长度
    uchar IP_Tos;        //服务类型
    uint  IP_Len;        //除去以太网头的包的总长度
    uint  IP_ID;         //IP标识
    uint  IP_FlagOffset; //标志及片偏移
    uchar IP_TTL;        //IP数据报的生存时间,通常用可经过的最大路由器数来表征
    uchar IP_Protocol;   //上层协议标识,1为ICMP,6为TCP,17为UDP
    uint  IP_Check;      //头部校验和
    uchar IP_Sour_IP[4]; //IP源地址
    uchar IP_Dest_IP[4]; //IP目标地址
    uchar IP_Data[1];    //IP数据
};

//ICMP message
struct ICMP
{
    uchar ICMP_Type;           //类型
    uchar ICMP_Code;           //代码
    uint  ICMP_Check;          //整个ICMP报文的校验
    uint  ICMP_ID;             //标识符
    uint  ICMP_Sequence;       //序号
    uchar ICMP_Data[ICMP_Num]; //任选测试数据
};

//UDP message
struct UDP
{
    uint  UDP_Sour_Port;   //源端口号
    uint  UDP_Dest_Port;   //目的端口号
    uint  UDP_Len;         //除去以太网头和IP头的包的总长度 
    uint  UDP_Check;       //UDP校验和
    uchar UDP_Data[1];     //UDP数据
};

#endif

/******************* End Of File **********************/

⌨️ 快捷键说明

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