forked from pandax381/microps
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ethernet.h
39 lines (30 loc) · 1.01 KB
/
ethernet.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
#ifndef ETHERNET_H
#define ETHERNET_H
#include <stdio.h>
#include <stdint.h>
#include <unistd.h>
#include <sys/types.h>
#include "net.h"
#define ETHERNET_ADDR_LEN 6
#define ETHERNET_ADDR_STR_LEN 17
#define ETHERNET_HDR_SIZE 14
#define ETHERNET_TRL_SIZE 4
#define ETHERNET_FRAME_SIZE_MIN 64
#define ETHERNET_FRAME_SIZE_MAX 1518
#define ETHERNET_PAYLOAD_SIZE_MIN (ETHERNET_FRAME_SIZE_MIN - (ETHERNET_HDR_SIZE + ETHERNET_TRL_SIZE))
#define ETHERNET_PAYLOAD_SIZE_MAX (ETHERNET_FRAME_SIZE_MAX - (ETHERNET_HDR_SIZE + ETHERNET_TRL_SIZE))
#define ETHERNET_TYPE_IP 0x0800
#define ETHERNET_TYPE_ARP 0x0806
#define ETHERNET_TYPE_LOOPBACK 0x9000
typedef struct {
uint8_t addr[ETHERNET_ADDR_LEN];
} __attribute__ ((packed)) ethernet_addr_t;
extern const ethernet_addr_t ETHERNET_ADDR_ANY;
extern const ethernet_addr_t ETHERNET_ADDR_BROADCAST;
extern int
ethernet_addr_pton (const char *p, ethernet_addr_t *n);
extern char *
ethernet_addr_ntop (const ethernet_addr_t *n, char *p, size_t size);
extern int
ethernet_init (void);
#endif