blob: 7357aac7a14aa3fa5393ccef810b72e16f14e60b (
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
|
// http://www.saminiir.com/lets-code-tcp-ip-stack-2-ipv4-icmpv4/
#include <stdint.h>
#include <stdbool.h>
#include "eth.h"
#include "netdev.h"
struct ipv4_hdr {
uint8_t ihl : 4; // 4bit / number of 32 bit words in header
uint8_t version : 4; // 4bit / 4 - ipv4
uint8_t tos; // type of service
uint16_t len; // total length of ip datagramm
uint16_t id; // index of datagram for fragmentation
//uint16_t flags : 3; // various control flags
//uint16_t frag_offset : 13; // fragment offset 0 - first
uint16_t flags_and_offset;
uint8_t ttl; // time to live - countdown decreased by each receiver
uint8_t proto; // payload protocol / 1-icmp, 16 - udp , 6 -tcp
uint16_t csum; // header checksum
uint32_t saddr; // source ip address
uint32_t daddr; // destination ip address
} __attribute__((packed));
bool ipv4_incoming(struct netdev *,struct eth_hdr *);
uint32_t ipv4_generic(struct netdev *dev, uint32_t ip, uint8_t type, uint8_t* pos,uint8_t *end);
|