blob: a690ac04d433aeb3c9b5dc4ca82c43774d343853 (
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
|
// http://www.saminiir.com/lets-code-tcp-ip-stack-1-ethernet-arp/
//
#include <stdint.h>
#include "netdev.h"
struct arp_hdr
{
uint16_t hwtype; // link layer type (1 - ethernet)
uint16_t protype; // protocol (0x800 - ipv4)
unsigned char hwsize; // hardware field size (6 bytes mac)
unsigned char prosize; // protocol field size (4 byte ip)
uint16_t opcode; // arp message type (1- arp request, 2- arp reply, 3- rarp request, 4- rarp reply)
unsigned char data[]; // payload
} __attribute__((packed));
// arp ipv4 payload
struct arp_ipv4
{
unsigned char smac[6]; // sender mac
uint32_t sip; // sender ip
unsigned char dmac[6]; // receiver mac
uint32_t dip; // receiver ip
} __attribute__((packed));
void arp_incoming(struct netdev *netdev, struct eth_hdr *hdr);
void arp_reply(struct netdev *netdev, struct eth_hdr *hdr, struct arp_hdr *arphdr);
|