Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Potentially incorrect Host Name during DHCP #23

Closed
Dmitro25 opened this issue Dec 7, 2017 · 1 comment
Closed

Potentially incorrect Host Name during DHCP #23

Dmitro25 opened this issue Dec 7, 2017 · 1 comment

Comments

@Dmitro25
Copy link

Dmitro25 commented Dec 7, 2017

Hi.
There are following lines of code inside module dhcp.c in functions send_DHCP_DISCOVER() and send_DHCP_REQUEST() :

	// host name
	pDHCPMSG->OPT[k++] = hostName;
	pDHCPMSG->OPT[k++] = 0;          // fill zero length of hostname
	for(i = 0 ; HOST_NAME[i] != 0; i++)
   	pDHCPMSG->OPT[k++] = HOST_NAME[i];
	pDHCPMSG->OPT[k++] = DHCP_CHADDR[3];
	pDHCPMSG->OPT[k++] = DHCP_CHADDR[4];
	pDHCPMSG->OPT[k++] = DHCP_CHADDR[5];
	pDHCPMSG->OPT[k - (i+3+1)] = i+3; // length of hostname

This code adds the last three bytes of the MAC address to the constant DCHP_HOST_NAME, which in sum forms the full DHCP host name. The problem may occur if MAC address contains bytes smaller than 0x20. Some routers (for example, Zyxel Keenetic Omni II) in this case cease to display the page with DHCP clients list at all.
I propose to replace the above code with the following:

	// host name
	pDHCPMSG->OPT[k++] = hostName;
	pDHCPMSG->OPT[k++] = 0;          // fill zero length of hostname
	for(i = 0 ; HOST_NAME[i] != 0; i++)
   	pDHCPMSG->OPT[k++] = HOST_NAME[i];
	pDHCPMSG->OPT[k++] = NibbleToHex(DHCP_CHADDR[3] >> 4); 
	pDHCPMSG->OPT[k++] = NibbleToHex(DHCP_CHADDR[3]);
	pDHCPMSG->OPT[k++] = NibbleToHex(DHCP_CHADDR[4] >> 4); 
	pDHCPMSG->OPT[k++] = NibbleToHex(DHCP_CHADDR[4]);
	pDHCPMSG->OPT[k++] = NibbleToHex(DHCP_CHADDR[5] >> 4); 
	pDHCPMSG->OPT[k++] = NibbleToHex(DHCP_CHADDR[5]);
	pDHCPMSG->OPT[k - (i+6+1)] = i+6; // length of hostname

and to add function NibbleToHex():

char NibbleToHex(uint8_t nibble)
{
  nibble &= 0x0F;
  if (nibble <= 9)
    return nibble + '0';
  else 
    return nibble + ('A'-0x0A);
}
@Ricky-Kwon
Copy link
Collaborator

Ricky-Kwon commented Dec 13, 2017

thank you. this will be updated after confirmation.

khj098765 pushed a commit that referenced this issue Jul 5, 2018
issue #23
MicroframeDev1 pushed a commit to MicroframeDev1/WIZ550S2E that referenced this issue Jul 17, 2018
Per Wiznet/ioLibrary_Driver#23 the DHCP host name needs to be ASCII chars.
This was actually fixed in WIZ550S2E, but was overwritten when the ioLibrary was merged at r1.1.0.
Bringing back the original fix, which uses sprintf to create valid names.

Spelling fixes

Removed duplicate call to setSIPR(zeroip); as per Wiznet/ioLibrary_Driver#45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants