📄 netheader.h
字号:
#ifndef _PROTOCOL_H#define _PROTOCOL_H#include <types.h>#pragma pack(1)struct ethhdr { uint8 et_dest[6]; // destination mac address uint8 et_src[6]; // source mac address. uint16 et_protlen; // if ethernet header protocol, else length./* uint8 et_dsap; // DSAP. uint8 et_ssap; // SSAP. uint8 et_ctl; // contorl. uint8 et_snap1; // SNAP. uint8 et_snap2; uint8 et_snap3; uint16 et_prot; // protocol.*/};#pragma pack()#define ETHER_HDR_SIZE 14#define E802_HDR_SIZE 22#define PROT_IP 0x0800#define PROT_ARP 0x0806#define PROT_RARP 0x8035#define ETH_ALEN 6 // Octets in one ethernet addr.struct iphdr { uint8 ip_hl_v; // version and header length(version篮 泅犁 4, length绰 4 byte 窜困). uint8 ip_tos; // type of service. uint16 ip_len; // total length (IP Header甫 器窃茄 辨捞). uint16 ip_id; // identification. uint16 ip_off; // fragment offset field. uint8 ip_ttl; // time to live (盔窍绰 蔼, 0x40 or 0xff). uint8 ip_p; // protocol (UDP:17). uint16 ip_chksum; // checksum. uint32 ip_src; // source ip address. uint32 ip_dest; // destination ip address.};#define IP_HDR_SIZE 20#define IP_P_UDP 0x11 // 17#define IP_P_ICMP 0x01 // 1struct udphdr { uint16 udp_src; // udp source port. uint16 udp_dest; // udp destination port. uint16 udp_len; // length of udp packet. uint16 udp_chksum; // checksum.};#define UDP_HDR_SIZE 8// Address Resolution Protocol (ARP) header.struct arphdr { uint16 ar_hrd; // Format of hardware address. uint16 ar_pro; // Format of protocol address. uint8 ar_hln; // Length of hardware address. uint8 ar_pln; // Length of protocol address. uint16 ar_op; // Operation. uint8 ar_data[0];#if 0 uint8 ar_sha[]; // Sender hardware address. uint8 ar_spa[]; // Sender protocol address. uint8 ar_tha[]; // Target hardware address. uint8 ar_tpa[]; // Target protocol address.#endif // 0};#define ARP_HDR_SIZE (8+20) // Size assuming ethernet.// for ar_hrd of ARP_HEADER.#define ARP_ETHER 1 // Ethernet hardware address.// for ar_op of ARP_HEADER.#define ARPOP_REQUEST 1 // Request to resolve address.#define ARPOP_REPLY 2 // Response to previous request.#define RARPOP_REQUEST 3 // Request to resolve address.#define RARPOP_REPLY 4 // Response to previous request.#define ETH_P_IP 0x0800 // Internet Protocol packet.// BOOTP header.struct bootp { uint8 bh_opcode; // Operation. uint8 bh_htype; // Hardware type. uint8 bh_hlen; // Hardware address length. uint8 bh_hops; // Hop count (gateway thing). uint32 bh_tid; // Transaction ID. uint16 bh_secs; // Seconds since boot. uint16 bh_res1; // Reserved(alignment). uint32 bh_ciaddr; // Client IP address. uint32 bh_yiaddr; // Your (client) IP address. uint32 bh_siaddr; // Server IP address(Server啊 setting). uint32 bh_giaddr; // Gateway IP address. uint8 bh_chaddr[16]; // Client hardware address(Mac Address). uint8 bh_sname[64]; // Server host name. uint8 bh_file[128]; // Boot file name. uint8 bh_vend[64]; // Vendor information.};#define BOOTP_HDR_SIZE 300#define BOOTP_SIZE (ETHER_HDR_SIZE + IP_HDR_SIZE + UDP_HDR_SIZE + BOOTP_HDR_SIZE)#define OP_BOOTREQUEST 1#define OP_BOOTREPLY 2#define HWT_ETHER 1#define HWL_ETHER 0x06struct icmphdr { uint8 type; uint8 code; uint16 chksum; // check sum uint16 id; // identifier uint16 seq; // Sequence number};#define ICMP_ECHO_REQUEST (0x08)#define ICMP_ECHO_REPLY (0x00)#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -