40 #include <sys/types.h> 41 #include <arpa/inet.h> 45 #define IP_MAXPACKET 65535 49 #ifndef __LITTLE_ENDIAN 50 #define __LITTLE_ENDIAN 1 54 #define __BIG_ENDIAN 2 59 #define __BYTE_ORDER __LITTLE_ENDIAN 62 #define __BYTE_ORDER __LITTLE_ENDIAN 65 #define __BYTE_ORDER __BIG_ENDIAN 68 #define __BYTE_ORDER __BIG_ENDIAN 71 #define ICMP_DATA_SIZE 28 72 #define ICMP_ZERO_HEADER_SIZE 10 73 #define ICMP_ELEVEN_HEADER_SIZE 36 86 } __attribute__ ((packed)) ;
99 uint16_t data[ICMP_DATA_SIZE/2];
100 } __attribute__ ((packed)) ;
112 uint8_t data[ICMP_DATA_SIZE];
114 } __attribute__ ((packed)) ;
125 uint32_t data[ICMP_DATA_SIZE/4];
126 } __attribute__ ((packed)) ;
134 #if __BYTE_ORDER == __LITTLE_ENDIAN 135 unsigned int ip_hl:4;
137 #elif __BYTE_ORDER == __BIG_ENDIAN 139 unsigned int ip_hl:4;
141 #error "Byte ordering not specified " 150 #define IP_OFFMASK 0x1fff 156 } __attribute__ ((packed)) ;
163 #ifndef ETHER_ADDR_LEN 164 #define ETHER_ADDR_LEN 6 169 } __attribute__ ((packed)) ;
173 #define ICMP_TYPE_ECHO_REPLY 0 174 #define ICMP_TYPE_DEST_UNREACH 3 175 #define ICMP_TYPE_ECHO_REQUEST 8 176 #define ICMP_TYPE_TIME_EXCEEDED 11 179 #define ICMP_CODE_NET_UNREACH 0 180 #define ICMP_CODE_HOST_UNREACH 1 181 #define ICMP_CODE_PROTO_UNREACH 2 182 #define ICMP_CODE_PORT_UNREACH 3 183 #define ICMP_CODE_TTL_EXPIRED 0 186 #define IP_PROTO_ICMP 0x0001 187 #define IPV4_HEADER_LEN 20 188 #define ICMP_HEADER_LEN 8 192 ip_protocol_icmp = 0x0001,
197 ethertype_arp = 0x0806,
198 ethertype_ip = 0x0800,
203 arp_op_request = 0x0001,
204 arp_op_reply = 0x0002,
209 arp_hrd_ethernet = 0x0001,
224 } __attribute__ ((packed)) ;
227 #define sr_IFACE_NAMELEN 32 sr_arp_hrd_fmt
Enumeration of useful hardware format codes for ARP.
Definition: sr_protocol.h:208
Struct of an ARP header.
Definition: sr_protocol.h:213
sr_ip_protocol
Enumeration of useful codes for protocols encapsulated in IP.
Definition: sr_protocol.h:191
uint32_t ip_src
src IP address
Definition: sr_protocol.h:154
uint8_t ip_ttl
time to live
Definition: sr_protocol.h:151
uint16_t icmp_id
icmp identifier, you shouldn't need to use this
Definition: sr_protocol.h:83
uint16_t ip_id
identification
Definition: sr_protocol.h:145
uint16_t ip_off
fragment offset field
Definition: sr_protocol.h:146
uint32_t ar_sip
sender IP address
Definition: sr_protocol.h:221
uint32_t ip_dst
dest IP address
Definition: sr_protocol.h:155
unsigned char ar_sha[ETHER_ADDR_LEN]
sender hardware address
Definition: sr_protocol.h:311
uint16_t ip_sum
IP checksum.
Definition: sr_protocol.h:153
uint8_t ip_tos
type of service
Definition: sr_protocol.h:143
uint16_t icmp_seq
icmp sequence number, you shouldn't need to use this
Definition: sr_protocol.h:84
unsigned char ar_tha[ETHER_ADDR_LEN]
target hardware address
Definition: sr_protocol.h:313
Struct of a Type-11 (TTL exceeded) ICMP header.
Definition: sr_protocol.h:120
sr_arp_opcode
Enumeration of useful codes for ARP operations.
Definition: sr_protocol.h:202
uint16_t ip_len
total length
Definition: sr_protocol.h:144
Struct of an Ethernet Header.
Definition: sr_protocol.h:161
uint8_t icmp_code
icmp code, if needed
Definition: sr_protocol.h:81
General struct of a ICMP header.
Definition: sr_protocol.h:79
unsigned short ar_pro
format of protocol address
Definition: sr_protocol.h:216
sr_ethertype
Enumeration of useful codes for protocols encapsulated in Ethernet.
Definition: sr_protocol.h:196
uint8_t ether_shost[ETHER_ADDR_LEN]
source ethernet address
Definition: sr_protocol.h:310
Struct of an IP header, without options.
Definition: sr_protocol.h:132
unsigned char ar_pln
length of protocol address
Definition: sr_protocol.h:218
uint32_t ar_tip
target IP address
Definition: sr_protocol.h:223
uint16_t icmp_sum
icmp checksum
Definition: sr_protocol.h:82
unsigned char ar_hln
length of hardware address
Definition: sr_protocol.h:217
unsigned short ar_op
ARP opcode (command)
Definition: sr_protocol.h:219
unsigned short ar_hrd
format of hardware address
Definition: sr_protocol.h:215
uint8_t icmp_type
icmp type
Definition: sr_protocol.h:80
Struct of a Type-3 (destination unreachable) ICMP header.
Definition: sr_protocol.h:106
Struct of a Type-0 (echo reply) ICMP header.
Definition: sr_protocol.h:92
uint8_t ether_dhost[ETHER_ADDR_LEN]
destination ethernet address
Definition: sr_protocol.h:309
uint16_t ether_type
type (protocol) of encapsulated packet
Definition: sr_protocol.h:168
uint8_t ip_p
protocol of encapsulated packet
Definition: sr_protocol.h:152