Skip to content
This repository was archived by the owner on Jan 7, 2019. It is now read-only.

Commit 5987d71

Browse files
committed
adds support for reading option code 15 of DHCP -> domain name
1 parent 3e436cc commit 5987d71

4 files changed

Lines changed: 23 additions & 1 deletion

File tree

src/Dhcp.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,14 +331,20 @@ uint8_t DhcpClass::parseDHCPResponse(unsigned long responseTimeout, uint32_t& tr
331331
break;
332332

333333
case dns :
334-
335334
opt_len = _dhcpUdpSocket.read();
336335
_dhcpUdpSocket.read(_dhcpDnsServerIp, 4);
337336
for (int i = 0; i < opt_len-4; i++)
338337
{
339338
_dhcpUdpSocket.read();
340339
}
341340
break;
341+
342+
case domainName:
343+
opt_len = _dhcpUdpSocket.read();
344+
_dhcpDnsdomainName = (char*)malloc(sizeof(char)*opt_len+1);
345+
_dhcpUdpSocket.read(_dhcpDnsdomainName, opt_len);
346+
_dhcpDnsdomainName[opt_len] = '\0';
347+
break;
342348

343349
case dhcpServerIdentifier :
344350

@@ -485,6 +491,11 @@ IPAddress DhcpClass::getDnsServerIp()
485491
return IPAddress(_dhcpDnsServerIp);
486492
}
487493

494+
char* DhcpClass::getDnsDomainName()
495+
{
496+
return _dhcpDnsdomainName;
497+
}
498+
488499
void DhcpClass::printByte(char * buf, uint8_t n ) {
489500
char *str = &buf[1];
490501
buf[0]='0';

src/Dhcp.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ class DhcpClass {
143143
uint32_t _dhcpTransactionId;
144144
uint8_t _dhcpMacAddr[6];
145145
uint8_t _dhcpLocalIp[4];
146+
char* _dhcpDnsdomainName;
146147
uint8_t _dhcpSubnetMask[4];
147148
uint8_t _dhcpGatewayIp[4];
148149
uint8_t _dhcpDhcpServerIp[4];
@@ -170,6 +171,7 @@ class DhcpClass {
170171
IPAddress getGatewayIp();
171172
IPAddress getDhcpServerIp();
172173
IPAddress getDnsServerIp();
174+
char* getDnsDomainName();
173175

174176
int beginWithDHCP(uint8_t *, unsigned long timeout = 60000, unsigned long responseTimeout = 5000);
175177
int checkLease();

src/Ethernet2.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ int EthernetClass::begin(void)
4141
w5500.setGatewayIp(_dhcp->getGatewayIp().raw_address());
4242
w5500.setSubnetMask(_dhcp->getSubnetMask().raw_address());
4343
_dnsServerAddress = _dhcp->getDnsServerIp();
44+
_dnsDomainName = _dhcp->getDnsDomainName();
4445
}
4546

4647
return ret;
@@ -100,6 +101,7 @@ int EthernetClass::begin(uint8_t *mac_address)
100101
w5500.setGatewayIp(_dhcp->getGatewayIp().raw_address());
101102
w5500.setSubnetMask(_dhcp->getSubnetMask().raw_address());
102103
_dnsServerAddress = _dhcp->getDnsServerIp();
104+
_dnsDomainName = _dhcp->getDnsDomainName();
103105
}
104106

105107
return ret;
@@ -157,6 +159,7 @@ int EthernetClass::maintain(){
157159
w5500.setGatewayIp(_dhcp->getGatewayIp().raw_address());
158160
w5500.setSubnetMask(_dhcp->getSubnetMask().raw_address());
159161
_dnsServerAddress = _dhcp->getDnsServerIp();
162+
_dnsDomainName = _dhcp->getDnsDomainName();
160163
break;
161164
default:
162165
//this is actually a error, it will retry though
@@ -192,4 +195,8 @@ IPAddress EthernetClass::dnsServerIP()
192195
return _dnsServerAddress;
193196
}
194197

198+
char* EthernetClass::dnsDomainName(){
199+
return _dnsDomainName;
200+
}
201+
195202
EthernetClass Ethernet;

src/Ethernet2.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
class EthernetClass {
2323
private:
2424
IPAddress _dnsServerAddress;
25+
char* _dnsDomainName;
2526
DhcpClass* _dhcp;
2627
public:
2728
uint8_t w5500_cspin;
@@ -60,6 +61,7 @@ class EthernetClass {
6061
IPAddress subnetMask();
6162
IPAddress gatewayIP();
6263
IPAddress dnsServerIP();
64+
char* dnsDomainName();
6365

6466
friend class EthernetClient;
6567
friend class EthernetServer;

0 commit comments

Comments
 (0)