Skip to content

Commit b8fbffe

Browse files
committed
1 parent 7c90d9d commit b8fbffe

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

libraries/Ethernet/Dhcp.cpp

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -163,15 +163,15 @@ void DhcpClass::send_DHCP_MESSAGE(uint8_t messageType, uint16_t secondsElapsed)
163163

164164
// OPT - host name
165165
buffer[16] = hostName;
166-
buffer[17] = strlen(HOST_NAME) + 3; // length of hostname + last 3 bytes of mac address
166+
buffer[17] = strlen(HOST_NAME) + 6; // length of hostname + last 3 bytes of mac address
167167
strcpy((char*)&(buffer[18]), HOST_NAME);
168168

169-
buffer[24] = _dhcpMacAddr[3];
170-
buffer[25] = _dhcpMacAddr[4];
171-
buffer[26] = _dhcpMacAddr[5];
169+
printByte((char*)&(buffer[24]), _dhcpMacAddr[3]);
170+
printByte((char*)&(buffer[26]), _dhcpMacAddr[4]);
171+
printByte((char*)&(buffer[28]), _dhcpMacAddr[5]);
172172

173173
//put data in W5100 transmit buffer
174-
_dhcpUdpSocket.write(buffer, 27);
174+
_dhcpUdpSocket.write(buffer, 30);
175175

176176
if(messageType == DHCP_REQUEST)
177177
{
@@ -347,3 +347,13 @@ IPAddress DhcpClass::getDnsServerIp()
347347
return IPAddress(_dhcpDnsServerIp);
348348
}
349349

350+
void DhcpClass::printByte(char * buf, uint8_t n ) {
351+
char *str = &buf[1];
352+
buf[0]='0';
353+
do {
354+
unsigned long m = n;
355+
n /= 16;
356+
char c = m - 16 * n;
357+
*str-- = c < 10 ? c + '0' : c + 'A' - 10;
358+
} while(n);
359+
}

libraries/Ethernet/Dhcp.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ class DhcpClass {
143143

144144
void presend_DHCP();
145145
void send_DHCP_MESSAGE(uint8_t, uint16_t);
146+
void printByte(char *, uint8_t);
146147

147148
uint8_t parseDHCPResponse(unsigned long responseTimeout, uint32_t& transactionId);
148149
public:

0 commit comments

Comments
 (0)