15#include <basictypes.h>
23#define DHCP_OPT_OFFS 236
24#define DHCP_CLIENT_PORT 68
25#define DHCP_SERVER_PORT 67
51#define DHCPOPT_SUBNET_MASK 1
52#define DHCPOPT_ROUTER 3
53#define DHCPOPT_TIME_SERVER 4
54#define DHCPOPT_DNS_SERVER 6
55#define DHCPOPT_LOG_SERVER 7
56#define DHCPOPT_HOST_NAME 12
57#define DHCPOPT_DOMAIN_NAME 15
58#define DHCPOPT_NTP_SERVER 42
59#define DHCPOPT_REQ_IPADDR4 50
60#define DHCPOPT_LEASE_TIME 51
61#define DHCPOPT_MSG_TYPE 53
62#define DHCPOPT_SERVER_ID 54
63#define DHCPOPT_PARAM_REQ 55
64#define DHCPOPT_RENEW_TIME 58
65#define DHCPOPT_REBIND_TIME 59
66#define DHCPOPT_CLIENT_ID 61
67#define DHCPOPT_TFTP_SERVER 66
68#define DHCPOPT_BOOTFILE 67
69#define DHCPOPT_SMTP_SERVER 69
71#define DHCPOPT_END 255
77#define DHCPCOOKIE0 (uint8_t)99
78#define DHCPCOOKIE1 (uint8_t)130
79#define DHCPCOOKIE2 (uint8_t)83
80#define DHCPCOOKIE3 (uint8_t)99
86#define PDM_DHCPOFFER 1
96typedef struct dhcp_msg
112 uint8_t options[OPT_SIZE];
113} __attribute__((packed)) DHCP_MESSAGE;
129 DHCPMessage(puint8_t pData);
132 void SetOp(uint8_t n) { Msg.op = n; }
134 uint8_t GetMsgType() {
return msg_type; }
136 void SetHtype(uint8_t n) { Msg.htype = n; }
137 void SetHlen(uint8_t n) { Msg.hlen = n; }
138 void SetHops(uint8_t n) { Msg.hops = n; }
140 void SetXid(uint32_t n) { Msg.xid = n; }
142 void SetRandomXid(
const MACADR &ma);
144 void SetSecs(uint16_t n) { Msg.secs = n; }
145 void SetFlags(uint16_t n) { Msg.flags = n; }
146 void SetCiaddr(
IPADDR4 i) { Msg.ciaddr = i; }
147 void SetYiaddr(
IPADDR4 i) { Msg.yiaddr = i; }
148 void SetSiaddr(
IPADDR4 i) { Msg.siaddr = i; }
149 void SetGiaddr(
IPADDR4 i) { Msg.giaddr = i; }
152 memset(Msg.chaddr, 0x0, 16);
153 for (
int i = 0; i < 6; i++)
159 void SetSname(
char *s) { memcpy(Msg.sname, s, 64); }
160 void SetFile(
char *s) { memcpy(Msg.file, s, 128); }
161 void SetOptions(
char *s) { memcpy(Msg.options, s, OPT_SIZE); }
163 void SetOptionsIp(
int &offset,
IPADDR4 &ip4)
165 uint32_t u32 = (uint32_t)ip4;
166 Msg.options[offset++] = ((u32 >> 24) & 0xff);
167 Msg.options[offset++] = ((u32 >> 16) & 0xff);
168 Msg.options[offset++] = ((u32 >> 8) & 0xff);
169 Msg.options[offset++] = (u32 & 0xff);
172 void SetOptions(
int i, uint8_t n) { Msg.options[i] = n; }
174 uint32_t GetXid() {
return Msg.xid; }
175 uint16_t GetSecs() {
return Msg.secs; }
176 uint16_t GetFlags() {
return Msg.flags; }
177 IPADDR4 GetCiaddr() {
return Msg.ciaddr; }
178 IPADDR4 GetYiaddr() {
return Msg.yiaddr; }
179 IPADDR4 GetGiaddr() {
return Msg.giaddr; }
180 IPADDR4 GetSiaddr() {
return Msg.siaddr; }
181 uint8_t GetChaddr(
int i) {
return Msg.chaddr[i]; }
183 puint8_t GetDataPtr() {
return (uint8_t *)(&Msg); }
184 int GetDataLen() {
return sizeof(DHCP_MESSAGE); }
186 void CreateReply(uint32_t xid, uint32_t yip);
189 puint8_t GetOptionData(uint8_t code);
190 puint8_t GetOptionData(uint8_t code,
int &length);
201void CreateDhcpDiscoverMsg(DHCPMessage &NewMsg,
InterfaceBlock *pIfb);
202void CreateDhcpRequestMsg(DHCPMessage &OfferMsg, DHCPMessage &NewMsg,
InterfaceBlock *pIfb);
203void CreateDhcpReleaseMsg(DHCPMessage &NewMsg,
InterfaceBlock *pIfb);
204void ShowDhcpConfig();
205void UpdateIPRuntimeVars(BOOLEAN release);
207int ExecDHCPClient(
int DhcpState);
208BOOLEAN ValidDhcpMsg(puint8_t pData);
209BOOLEAN DhcpConfig(DHCPMessage &Msg);
215extern void (*AddDhcpOptionsFunc)(DHCPMessage &NewMsg,
int &opt,
int MsgType);
216extern void (*AddDhcpFieldsFunc)(DHCPMessage &NewMsg,
int &opt,
int MsgType);
217extern void (*ParseDhcpOptions)(DHCPMessage &Msg);
Used to store and manipulate IPv4 addresses in dual stack mode.
Definition nettypes.h:225
Network interface configuration block class for interface control and configuration.
Definition netinterface.h:245
Used to store and manipulate MAC addresses.
Definition nettypes.h:69
uint8_t GetByte(int n) const
Get the nth byte of the MAC.
Definition nettypes.h:91
NetBurner Network Interface Header File.