-
Notifications
You must be signed in to change notification settings - Fork 1
/
dhcp.h
61 lines (50 loc) · 1.31 KB
/
dhcp.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
#ifndef DHCP_H
#define DHCP_H
#include <stddef.h>
#include <stdint.h>
#include "ipv4.h"
#include "mac.h"
typedef struct dhcp_t {
uint8_t op;
uint8_t htype;
uint8_t hlen;
uint8_t hops;
uint32_t xid;
uint16_t secs;
uint16_t flags;
ipaddr_t ciaddr;
ipaddr_t yiaddr;
ipaddr_t siaddr;
ipaddr_t giaddr;
uint8_t chaddr[16];
uint8_t sname[64];
uint8_t bfile[128];
uint32_t magic;
uint8_t options[];
} dhcp_t;
#define DHCP_OPREQUEST 0x01
#define DHCP_OPREPLAY 0x02
#define DHCP_MAGIC 0x63825363
#define DHCP_MSG_TYPE 53
#define DHCP_DISCOVERY 01
#define DHCP_OFFER 02
#define DHCP_REQ 03
#define DHCP_ACK 05
#define DHCP_SRVID 54
#define DHCP_DNS 6
#define DHCP_ROUTER 3
#define DHCP_NETMASK 1
#define DHCP_LEASETIME 51
#define DHCP_TERMINATE 0xFF
#define DHCP_CLIENT_ID 61
int send_dhcpreply(raw_iface_t *iface, uint8_t type, uint32_t xid,
macaddr_t src_mac, ipaddr_t src_ip,
macaddr_t dst_mac, ipaddr_t dst_ip,
ipaddr_t gateway, ipaddr_t dns, ipaddr_t netmask,
macaddr_t chaddr, ipaddr_t ciaddr);
int send_dhcp_discovery(raw_iface_t *iface, macaddr_t src_mac);
int dhcp_parse_request(dhcp_t *dhcp, ipaddr_t *rq_addr);
int dhcp_parse_dns(dhcp_t *dhcp, ipaddr_t *dns);
int dhcp_parse_netmask(dhcp_t *dhcp, ipaddr_t *netmask);
int dhcp_parse_type(dhcp_t *dhcp, uint8_t *type);
#endif