-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprotocols.h
81 lines (67 loc) · 1.97 KB
/
protocols.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#ifndef HEADER_PROTOCOLS
#define HEADER_PROTOCOLS
struct ethernet_header {
uint8_t dest[6];
uint8_t source[6];
uint8_t ether_type[2];
uint8_t fields_8021Q[2];
uint8_t ether_type_8021Q[2];
};
typedef struct ethernet_header ETHERNET_HEADER;
struct arp_header {
uint8_t network_type[2];
uint8_t protocol_type[2];
uint8_t hardware_addr_length;
uint8_t logical_addr_length;
uint8_t operation[2];
uint8_t sender_hardware_addr[6];
uint8_t sender_logical_addr[4];
uint8_t target_hardware_addr[6];
uint8_t target_logical_addr[4];
};
typedef struct arp_header ARP_HEADER;
struct ip_header {
uint8_t vers_ihl;
uint8_t service;
uint8_t total_length[2];
uint8_t id[2];
uint8_t flags_fragment_position[2];
uint8_t ttl;
uint8_t protocol;
uint8_t checksum[2];
uint8_t ip_source[4];
uint8_t ip_dest[4];
};
typedef struct ip_header IP_HEADER;
struct icmp_header {
uint8_t type;
uint8_t code;
uint8_t checksum[2];
uint8_t id[2];
uint8_t seq_num[2];
};
typedef struct icmp_header ICMP_HEADER;
struct udp_header {
uint8_t source_port[2];
uint8_t dest_port[2];
uint8_t length[2];
uint8_t checksum[2];
};
typedef struct udp_header UDP_HEADER;
struct tcp_header {
uint8_t source_port[2];
uint8_t dest_port[2];
uint8_t seq[4];
uint8_t ack_number[4];
uint8_t flags[2];
uint8_t windows[2];
uint8_t checksum[2];
uint8_t urg_opinter[2];
};
typedef struct tcp_header TCP_HEADER;
/*Compute the IP header checksum. All fields have to be set to 0 (including the checksum field, size in 16 bits word of data*/
uint16_t get_checksum(uint8_t* data, uint8_t size);
void ping_request(uint8_t* buffer, uint8_t dest_mac_addr[6], uint8_t dest_ip_addr[4]);
void arp_request(uint8_t* buffer, uint8_t dest_mac_addr[6], uint8_t dest_ip_addr[4], uint8_t source_mac_addr[6], uint8_t source_ip_addr[4]);
void pong_request(uint8_t* buffer, uint8_t dest_mac_addr[6], uint8_t dest_ip_addr[4], uint8_t id[2], uint8_t seq[2],const uint8_t* data, uint8_t data_size);
#endif