-
Notifications
You must be signed in to change notification settings - Fork 1
/
icmp.h
61 lines (49 loc) · 1.73 KB
/
icmp.h
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
#ifndef CURO_ICMP_H
#define CURO_ICMP_H
#include <iostream>
#define ICMP_TYPE_ECHO_REPLY 0
#define ICMP_TYPE_DESTINATION_UNREACHABLE 3
#define ICMP_TYPE_ECHO_REQUEST 8
#define ICMP_TYPE_TIME_EXCEEDED 11
struct icmp_header {
uint8_t type;
uint8_t code;
uint16_t checksum;
} __attribute__((packed));
struct icmp_echo {
uint16_t identify;
uint16_t sequence;
uint8_t data[];
} __attribute__((packed));
struct icmp_dest_unreachable {
uint32_t unused;
uint8_t data[];
} __attribute__((packed));
struct icmp_time_exceeded {
uint32_t unused;
uint8_t data[];
} __attribute__((packed));
struct icmp_message {
icmp_header header;
union {
icmp_echo echo;
icmp_dest_unreachable dest_unreachable;
icmp_time_exceeded time_exceeded;
};
} __attribute__((packed));
#define ICMP_DEST_UNREACHABLE_CODE_NET_UNREACHABLE 0
#define ICMP_DEST_UNREACHABLE_CODE_HOST_UNREACHABLE 1
#define ICMP_DEST_UNREACHABLE_CODE_PROTOCOL_UNREACHABLE 2
#define ICMP_DEST_UNREACHABLE_CODE_PORT_UNREACHABLE 3
#define ICMP_DEST_UNREACHABLE_CODE_FRAGMENT_NEEDED_AND_DF_SET 4
#define ICMP_DEST_UNREACHABLE_CODE_SOURCE_ROUTE_FAILED 5
#define ICMP_TIME_EXCEEDED_CODE_TIME_TO_LIVE_EXCEEDED 0
#define ICMP_TIME_EXCEEDED_CODE_FRAGMENT_REASSEMBLY_TIME_EXCEEDED 1
void icmp_input(uint32_t source, uint32_t destination, void *buffer,
size_t len);
void send_icmp_time_exceeded(uint32_t dest_addr, uint32_t src_addr,
uint8_t code, void *error_ip_buffer, size_t len);
void send_icmp_destination_unreachable(uint32_t dest_addr, uint32_t src_addr,
uint8_t code, void *error_ip_buffer,
size_t len);
#endif // CURO_ICMP_H