1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
#include <stdlib.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <linux/if_packet.h>
#include <linux/if_ether.h>
#include <sys/ioctl.h>
#include <net/if.h>
#define ICMP_TREQUEST 8
#define ICMP_TECHO 0
#define ICMP_DEFAULT_SIZE 0
//#define ICMP_MAX
typedef struct icmp_pckt_t
{
//etherenet header - 14 bytes
uint8_t eth_dest[6];
uint8_t eth_src[6];
uint16_t eth_type;
//IP4 header - 20 bytes
uint8_t head_hlength; //4bits version, 4bit header length
uint8_t tos;
uint16_t ip_length;
uint16_t ip_ident;
uint16_t flags_fragment_off;
uint8_t ttl; //time to live
uint8_t protocol;
uint16_t ip_chksum;
uint32_t source_addr;
uint32_t dest_addr;
//ICMP header 12 bytes
uint8_t type;
uint8_t code;
uint16_t icmp_check_sum;
uint16_t icmp_ident;
uint16_t seq_num;
uint8_t data[ICMP_MAX_DATA];
} __attribute__((packed, aligned(1))) icmp_pckt_t;
int icmp_eth_init( icmp_pckt_t *icmp );
int icmp_eth_dest( icmp_pckt_t *icmp, uint8_t *mac );
int icmp_eth_src( icmp_pckt_t *icmp, uint8_t *mac );
int icmp_eth_len( icmp_pckt_t *icmp );
int icmp_ip_init( icmp_pckt_t *icmp );
int icmp_ip_chksum( icmp_pckt_t *icmp );
int icmp_ip_dest( icmp_pckt_t *icmp, uint32_t dest );
int icmp_ip_src( icmp_pckt_t *icmp, uint32_t src );
int icmp_ip_ident( icmp_pckt_t *icmp, uint16_t ident );
int icmp_ip_ttl( icmp_pckt_t *icmp, uint8_t ttl );
int icmp_ip_len( icmp_pckt_t *icmp );
int icmp_icmp_init( icmp_pckt_t *icmp );
int icmp_icmp_set_chks( icmp_pckt_t *icmp );
int icmp_icmp_set_code( icmp_pckt_t *icmp, uint8_t code );
int icmp_icmp_set_type( icmp_pckt_t *icmp, uint8_t type );
int icmp_icmp_len( icmp_pckt_t *icmp );
int icmp_icmp_ident( icmp_pckt_t *icmp, uint16_t ident );
int icmp_icmp_seq( icmp_pckt_t *icmp, uint16_t seq);
int icmp_total_len( icmp_pckt_t *icmp );
int icmp_icmp_ts( icmp_pckt_t *icmp, uint64_t timestamp );
int icmp_dump( icmp_pckt_t *icmp );
int icmp_data( icmp_pckt_t *icmp, uint8_t *data, size_t size );
uint16_t
ip_checksum (uint16_t *addr, int len);
|