aboutsummaryrefslogtreecommitdiff
path: root/libraries/Ethernet/Dhcp.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'libraries/Ethernet/Dhcp.cpp')
-rwxr-xr-xlibraries/Ethernet/Dhcp.cpp30
1 files changed, 24 insertions, 6 deletions
diff --git a/libraries/Ethernet/Dhcp.cpp b/libraries/Ethernet/Dhcp.cpp
index c20d2e6..62bbfeb 100755
--- a/libraries/Ethernet/Dhcp.cpp
+++ b/libraries/Ethernet/Dhcp.cpp
@@ -163,15 +163,15 @@ void DhcpClass::send_DHCP_MESSAGE(uint8_t messageType, uint16_t secondsElapsed)
// OPT - host name
buffer[16] = hostName;
- buffer[17] = strlen(HOST_NAME) + 3; // length of hostname + last 3 bytes of mac address
+ buffer[17] = strlen(HOST_NAME) + 6; // length of hostname + last 3 bytes of mac address
strcpy((char*)&(buffer[18]), HOST_NAME);
- buffer[24] = _dhcpMacAddr[3];
- buffer[25] = _dhcpMacAddr[4];
- buffer[26] = _dhcpMacAddr[5];
+ printByte((char*)&(buffer[24]), _dhcpMacAddr[3]);
+ printByte((char*)&(buffer[26]), _dhcpMacAddr[4]);
+ printByte((char*)&(buffer[28]), _dhcpMacAddr[5]);
//put data in W5100 transmit buffer
- _dhcpUdpSocket.write(buffer, 27);
+ _dhcpUdpSocket.write(buffer, 30);
if(messageType == DHCP_REQUEST)
{
@@ -243,7 +243,7 @@ uint8_t DhcpClass::parseDHCPResponse(unsigned long responseTimeout, uint32_t& tr
// Skip to the option part
// Doing this a byte at a time so we don't have to put a big buffer
// on the stack (as we don't have lots of memory lying around)
- for (int i =0; i < (240 - sizeof(RIP_MSG_FIXED)); i++)
+ for (int i =0; i < (240 - (int)sizeof(RIP_MSG_FIXED)); i++)
{
_dhcpUdpSocket.read(); // we don't care about the returned byte
}
@@ -271,11 +271,19 @@ uint8_t DhcpClass::parseDHCPResponse(unsigned long responseTimeout, uint32_t& tr
case routersOnSubnet :
opt_len = _dhcpUdpSocket.read();
_dhcpUdpSocket.read(_dhcpGatewayIp, 4);
+ for (int i = 0; i < opt_len-4; i++)
+ {
+ _dhcpUdpSocket.read();
+ }
break;
case dns :
opt_len = _dhcpUdpSocket.read();
_dhcpUdpSocket.read(_dhcpDnsServerIp, 4);
+ for (int i = 0; i < opt_len-4; i++)
+ {
+ _dhcpUdpSocket.read();
+ }
break;
case dhcpServerIdentifier :
@@ -339,3 +347,13 @@ IPAddress DhcpClass::getDnsServerIp()
return IPAddress(_dhcpDnsServerIp);
}
+void DhcpClass::printByte(char * buf, uint8_t n ) {
+ char *str = &buf[1];
+ buf[0]='0';
+ do {
+ unsigned long m = n;
+ n /= 16;
+ char c = m - 16 * n;
+ *str-- = c < 10 ? c + '0' : c + 'A' - 10;
+ } while(n);
+}