00001 //EtherNet Packet Header 00002 00003 #pragma pack(push,1) 00004 00005 //6 bytes 00006 struct MAC { 00007 uint8 x[6]; 00008 MAC() {} 00009 MAC(int8 d1, int8 d2, int8 d3, int8 d4, int8 d5, int8 d6) { 00010 x[0] = d1; 00011 x[1] = d2; 00012 x[2] = d3; 00013 x[3] = d4; 00014 x[4] = d5; 00015 x[5] = d6; 00016 } 00017 int operator ==(MAC cmp) { 00018 if (x[0] != cmp.x[0]) return 0; 00019 if (x[1] != cmp.x[1]) return 0; 00020 if (x[2] != cmp.x[2]) return 0; 00021 if (x[3] != cmp.x[3]) return 0; 00022 if (x[4] != cmp.x[4]) return 0; 00023 if (x[5] != cmp.x[5]) return 0; 00024 return 1; 00025 } 00026 }; 00027 00028 //14 bytes + 1500(MTU) = max packet size 00029 struct Ethernet { 00030 MAC dest; 00031 MAC src; 00032 uint16 proto; //ETHERNET_IP,ETHERNET_IPX, etc. 00033 }; 00034 00035 #define ETHERNET_IP 0x0800 00036 #define ETHERNET_IPX 0x???? 00037 00038 //20 bytes 00039 struct IP { 00040 uint8 h_len: 4; // length of the header 00041 uint8 version: 4; // Version of IP 00042 uint8 tos; // Type of service (precedence - usually 0) 00043 uint16 total_len; // total length (including this header) 00044 uint16 ident; // unique identifier 00045 uint16 frag_and_flags; // flags 00046 uint8 ttl; 00047 uint8 protocol; // IPPROTO_... (ICMP(1), TCP(6), UDP(17), etc.) 00048 uint16 checksum; // IP checksum 00049 uint32 sourceIP; 00050 uint32 destIP; 00051 }; 00052 00053 //frag_and_flags 00054 #define IP_FLAG_LAST 0x2000 // Last fragment in datagram 00055 #define IP_FLAG_NOFRAG 0x4000 // Cannot fragment datagram 00056 #define IP_FLAG_UNKWN 0x8000 // ??? 00057 00058 //unique ident 00059 #define IP_ICMP 0x100d //??? 00060 00061 struct ICMP { 00062 uint8 i_type; //Packet type (ICMP_ECHO = 8 (Windows uses 0)) 00063 uint8 i_code; //type sub code (Windows uses 0) 00064 uint16 i_cksum; 00065 /* these fields are not specified @ networksorcery.com */ 00066 uint16 i_id; //Windows uses 0x100 00067 uint16 i_seq; //Windows uses 0x100 00068 /* This is not the std header, but we reserve space for time */ 00069 uint32 timestamp; 00070 }; 00071 00072 //20 bytes (typical) 00073 struct TCP { //size = 00074 uint16 sourceport; 00075 uint16 destport; 00076 uint32 seqnum; //(SYN) seq # of data block being sent 00077 uint32 acknum; //(ACK) value of next seq # that sender wants 00078 00079 uint8 dataoffset: 4; //# of 32bit words in TCP header (data follows) 00080 uint8 reserved: 3; //must be cleared 00081 uint8 ENC: 3; //see RFC#3168 (just leave cleared) 00082 uint8 control: 6; //UAPRSF flags 00083 00084 uint16 window; //# of data bytes 00085 uint16 checksum; //checksum of IP and TCP headers 00086 uint16 urgentptr; //(URG) points to seq # of last byte in a sequnce of urgent data (just leave cleared) 00087 }; 00088 00089 //TCP::control bits 00090 #define TCP_URG 0x01 //urgent??? 00091 #define TCP_ACK 0x02 //once a connection is established this is always set 00092 #define TCP_PSH 0x04 //push??? 00093 #define TCP_RST 0x08 //Reset connection 00094 #define TCP_SYN 0x10 //set only once during a connection handshake 00095 #define TCP_FIN 0x20 //end of data flag 00096 00097 //8 bytes 00098 struct UDP { 00099 uint16 sourceport; 00100 uint16 destport; 00101 uint16 total_len; //including this header 00102 uint16 checksum; 00103 }; 00104 00105 #pragma pack(pop)