📄 netcom.h
字号:
#ifndef _NETCOM_H
#define _NETCOM_H
#include "sys.h"
#define ARP_REQUEST 0x0001
#define ARP_REPLY 0x0002
/*
* These are the defined Ethernet Protocol ID's.
*/
#define ETH_P_LOOP 0x0060 /* Ethernet Loopback packet */
#define ETH_P_PUP 0x0200 /* Xerox PUP packet */
#define ETH_P_PUPAT 0x0201 /* Xerox PUP Addr Trans packet */
#define ETH_P_IP 0x0800 /* Internet Protocol packet */
#define ETH_P_X25 0x0805 /* CCITT X.25 */
#define ETH_P_ARP 0x0806 /* Address Resolution packet */
#define ETH_P_BPQ 0x08FF /* G8BPQ AX.25 Ethernet Packet [ NOT AN OFFICIALLY REGISTERED ID ] */
#define ETH_P_IEEEPUP 0x0a00 /* Xerox IEEE802.3 PUP packet */
#define ETH_P_IEEEPUPAT 0x0a01 /* Xerox IEEE802.3 PUP Addr Trans packet */
#define ETH_P_DEC 0x6000 /* DEC Assigned proto */
#define ETH_P_DNA_DL 0x6001 /* DEC DNA Dump/Load */
#define ETH_P_DNA_RC 0x6002 /* DEC DNA Remote Console */
#define ETH_P_DNA_RT 0x6003 /* DEC DNA Routing */
#define ETH_P_LAT 0x6004 /* DEC LAT */
#define ETH_P_DIAG 0x6005 /* DEC Diagnostics */
#define ETH_P_CUST 0x6006 /* DEC Customer use */
#define ETH_P_SCA 0x6007 /* DEC Systems Comms Arch */
#define ETH_P_RARP 0x8035 /* Reverse Addr Res packet */
#define ETH_P_ATALK 0x809B /* Appletalk DDP */
#define ETH_P_AARP 0x80F3 /* Appletalk AARP */
#define ETH_P_8021Q 0x8100 /* 802.1Q VLAN Extended Header */
#define ETH_P_IPX 0x8137 /* IPX over DIX */
#define ETH_P_IPV6 0x86DD /* IPv6 over bluebook */
#define ETH_P_PPP_DISC 0x8863 /* PPPoE discovery messages */
#define ETH_P_PPP_SES 0x8864 /* PPPoE session messages */
#define ETH_P_ATMMPOA 0x884c /* MultiProtocol Over ATM */
#define ETH_P_ATMFATE 0x8884 /* Frame-based ATM Transport
* over Ethernet
*/
#define PROTO_UDP 0x11
#define ETH_ALEN 6 /* Octets in one ethernet addr */
#define ETH_HLEN 14 /* Total octets in header. */
#define ETH_ZLEN 60 /* Min. octets in frame sans FCS */
#define ETH_DATA_MIN_LEN 46 /* Min */
#define ETH_DATA_MAX_LEN 1500 /* Max. octets in payload */
#define ETH_FRAME_LEN 1514
/* IPADDR: The IP address of this node. */
#define IPADDR0 192
#define IPADDR1 168
#define IPADDR2 123
#define IPADDR3 170
/* DIPADDR: The IP address of destinate node. */
#define DIPADDR0 192
#define DIPADDR1 168
#define DIPADDR2 123
#define DIPADDR3 222
/* NETMASK: The netmask. */
#define NETMASK0 255
#define NETMASK1 255
#define NETMASK2 255
#define NETMASK3 0
/* DRIPADDR: IP address of the default router. */
#define DRIPADDR0 192
#define DRIPADDR1 168
#define DRIPADDR2 123
#define DRIPADDR3 1
/* ETHADDR: The Ethernet address of the node */
#define ETHADDR0 0x01
#define ETHADDR1 0x0a
#define ETHADDR2 0xeb
#define ETHADDR3 0x1c
#define ETHADDR4 0x07
#define ETHADDR5 0x0b
/* ETHADDR: The Ethernet address of the destinate node */
#define DETHADDR0 0x00 //canbaby's notebook NIC's PAR
#define DETHADDR1 0x0a
#define DETHADDR2 0xeb
#define DETHADDR3 0x1c
#define DETHADDR4 0x0c
#define DETHADDR5 0x34
/* UDP source port and destinate port */
#define SRCUDPPORT 0x1200
#define DESTUDPPORT 0x1201
/* length of byte */
#define UDPHDR_LEN 8
#define IPHDR_LEN 20
#define ETHHDR_LEN 14
#define ARPHDR_LEN 28
#define PSEUD_UDPHDR_LEN 12
/* protocol header define */
typedef struct _ethhdr
{
u16_t destaddr0:8,
destaddr1:8,
destaddr2:8,
destaddr3:8,
destaddr4:8,
destaddr5:8; /* destination eth addr */
u16_t srcaddr0:8,
srcaddr1:8,
srcaddr2:8,
srcaddr3:8,
srcaddr4:8,
srcaddr5:8; /* source ether addr */
u16_t proto; /* packet type ID field */
}ethhdr,*pethhdr;
typedef struct _iphdr{
u16_t ver:4,hdrlen:4,tos:8,totlen;
u16_t id,frag_offset;
u16_t ttl:8,proto:8,checksum;
u16_t srcipaddr0:8,srcipaddr1:8,srcipaddr2:8,srcipaddr3:8;
u16_t destipaddr0:8,destipaddr1:8,destipaddr2:8,destipaddr3:8;
/* option start here */
}iphdr,*piphdr;
typedef struct _udphdr{
u16_t srcport,destport;
u16_t len,checksum;
}udphdr,*pudphdr;
typedef struct _arphdr{//28 byte
u16_t hdtype; //0x00 01,10Mb ethnet
u16_t proto; //0x08 00,ip
u16_t hdlen:8,protolen:8;
u16_t opcode;//reuest 1,reply 2
u16_t send_hd_addr0:8,
send_hd_addr1:8,
send_hd_addr2:8,
send_hd_addr3:8,
send_hd_addr4:8,
send_hd_addr5:8;
u16_t send_ip_addr0:8,
send_ip_addr1:8,
send_ip_addr2:8,
send_ip_addr3:8;
u16_t target_hd_addr0:8,
target_hd_addr1:8,
target_hd_addr2:8,
target_hd_addr3:8,
target_hd_addr4:8,
target_hd_addr5:8;
u16_t target_ip_addr0:8,
target_ip_addr1:8,
target_ip_addr2:8,
target_ip_addr3:8;
}arphdr,*parphdr;
typedef struct _eth_arp_hdr{
ethhdr ehdr;
arphdr ahdr;
}eth_arp_hdr,*peth_arp_hdr;
typedef struct _eth_ip_udp_hdr{
ethhdr ehdr;
iphdr ihdr;
udphdr uhdr;
}eth_ip_udp_hdr,*peth_ip_udp_hdr;
#define htons(n) ((((unsigned short)((n) & 0xff)) << 8) | (((n) & 0xff00) >> 8))
#define ntohs(n) htons(n)
#define TOKEN_SEND_DATA 0x0001
#define TOKEN_DATA 0x0002
#define TOKEN_STATUS 0x0004
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -