00001 #ifndef IP_H 00002 #define IP_H 00003 00004 #include "ether.h" 00005 00006 #define IP_ADDR_LEN 4 00007 #define IP_VERSION_4 4 00008 #define IP_HEADER_LENGTH 5 //is stored in 32bit units 5byte*32bit/8bit = 20 bytes 00009 /********************************************** 00010 * time to live: Hop-count: Number of surviving 00011 * routing points 00012 *********************************************/ 00013 #define IP_TTL 5 00014 #define IP_PROTO_ICMP 1 00015 #define IP_PROTO_TCP 6 00016 #define IP_PROTO_UDP 17 00017 /********************************************** 00018 * QoS priorities 00019 * Bits 0-5: DSCP (Differentiated Services Code Point) 00020 * - IP_DSCP_LOWEST_PRIORITY = b"000000" 00021 * - IP_DSCP_HIGHEST_PRIORITY = b"101110" 00022 * Bits 6-7: ECN (Explicit Congestion Notification - IP Flusskontrolle) 00023 * - 0 0 Not-ECT 00024 *********************************************/ 00025 #define IP_DSCP_LOWEST_PRIORITY 0 00026 #define IP_DSCP_HIGHEST_PRIORITY 184 00027 //do not allow fragmentation of packets 00028 #define IP_FLAGS 2 00029 00030 struct ip_header { 00031 Xuint8 version : 4; 00032 Xuint8 header_length : 4; 00033 Xuint8 type_of_service; 00034 //ip header + data length 00035 Xuint16 total_length; 00036 Xuint16 packet_number_id; 00037 Xuint16 flags : 3; 00038 Xuint16 fragment_offset : 13; 00039 Xuint8 time_to_live; 00040 Xuint8 proto; 00041 Xuint16 header_chksum; 00042 Xuint8 src[IP_ADDR_LEN]; 00043 Xuint8 dest[IP_ADDR_LEN]; 00044 //max 40 bytes 00045 //xuint8 options; 00046 //has to be padded to a multiple of 32 bits 00047 //Xuint8 pad : X; 00048 }; 00049 00050 #define IP_HEADER_OFFSET ETHER_PAYLOAD_OFFSET 00051 #define IP_PAYLOAD_OFFSET IP_HEADER_OFFSET + sizeof(struct ip_header) 00052 #define MAX_IP_PAYLOAD MAX_ETHER_PAYLOAD - sizeof(struct ip_header) 00053 00054 #define ICMP_TYPE_PING_REQUEST 0x8 00055 #define ICMP_TYPE_PING_REPLY 0x0 00056 00057 struct icmp_header { 00058 // ICMP Message Typ 00059 Xuint8 type; 00060 // Message Interner (Fehler-)Code 00061 Xuint8 code; 00062 // Checksum für das ICMP Paket 00063 Xuint16 chksum; 00064 // ID des Pakets, oft wie Port bei TCP / UDP genutzt 00065 Xuint16 usID; 00066 // Sequenznummer, bei mehreren typgleichen, (sinn-)zusammenhängenden Paketen 00067 Xuint16 usSequence; 00068 // Zeitstempel beim Abesenden 00069 Xuint32 ulTimeStamp; 00070 }; 00071 00072 #define ICMP_HEADER_OFFSET IP_PAYLOAD_OFFSET 00073 00074 #define cpy_ip_addr(dest, src) ( *( (Xuint32*)dest ) = *( (Xuint32*)src ) ) 00075 #define ip_addr_equal(addr1, addr2) ( *((Xuint32*)addr1) == *((Xuint32*)addr2) ) 00076 00077 #endif