blob: 5fbce2e0ec86cc90071ab468843ce2b2cca6acba (
plain)
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
|
//http://www.saminiir.com/lets-code-tcp-ip-stack-2-ipv4-icmpv4/
#include <stdint.h>
#include <stdbool.h>
#include "netdev.h"
struct icmp_v4 {
uint8_t type; // purpose 0-echo reply, 3- unreachable, 8- echo request, etc...
uint8_t code; // reason (type=3,code=0 net unreachable, etc..)
uint16_t csum; // checksum (Same as in ipv4 header)
uint8_t data[]; // payload (example icmp_v4_echo)
} __attribute__((packed));
// payload
struct icmp_v4_echo {
uint16_t id; // set by sender
uint16_t seq; // starting at 0
uint8_t data[]; // optinal (example timestamp)
} __attribute__((packed));
struct icmp_v4_dst_unreachable {
uint8_t unused;
uint8_t len; // lenght of original datagramm
uint16_t var; // depends on icmp code
uint8_t data[];
} __attribute__((packed));
uint32_t icmp_ping(struct netdev *dev, uint32_t ip, uint16_t* pos,uint32_t *end);
bool icmp_incoming(struct netdev *dev,struct eth_hdr *hdr);
|