Skip to content

Add DHCP hostname option #77

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

shoop
Copy link

@shoop shoop commented Nov 21, 2018

Updated version of PR #50 as well as arduino/Arduino#5701.
Code taken from mykh/ArduinoEthernetLibrary@3625ad9 , lightly edited to apply to current master.
Not intended to take credit, just wanted to contribute.

@greyltc
Copy link

greyltc commented Mar 1, 2020

Can anyone say why seemingly great PRs like this never get merged or even commented on by the maintainers here?

@PaulStoffregen
Copy link
Contributor

Except for very small edits, the reality is nobody is currently maintaining this library. I was maintaining it a couple years ago, which led to the 2.0.0 release. But since then I became very busy working on Teensy 4.0 (which pays my bills... work on this library is unpaid, so please understand every minute I've spent on Ethernet has been funded by Teensy sales). I intended to get back to Ethernet later this year or maybe in 2021. That may still happen. But right now I am extremely busy with a very long list of features people want on Teensy 4. FWIW, one of those features is the built-in ethernet hardware, which has bus master DMA and TCP/IP acceleration hardware.

Arduino also changed their policies, now requiring 2FA for access to any of their repositories. I have not yet set that up on my account. It's on a very long list of lower-priority things I'm too busy to worry about right now. So I no longer have access to commit to this library, even if I did have the time to do so.

Maybe someone else will start maintaining this library? It's an unpaid and mostly thankless job. The Arduino developers also tend to be cautious, so building enough trust to be allowed to maintain such a widely used library takes time.

I wish I had a better answer for you. But hopefully an honest answer is better than a "nice" one?

@greyltc
Copy link

greyltc commented Mar 1, 2020

Thanks for taking the time to respond and also for your volunteer efforts to make the library better for all of us! I'm struggling to understand why you're not (and seemingly nobody is) getting paid to maintain this library. This library drives sales. Why wouldn't the entity behind the Arduino brand spend the money to at least review and integrate features the community is adding for free to their products? Today it feels like they're rejecting free labor from qualified contributors in the community.

@JAndrassy
Copy link
Contributor

JAndrassy commented Mar 1, 2020

it is very risky to change something in so widely used multiplatform library supporting 3 chip versions on many different shield and modules. For the 2.0.0 version Paul did tests which may took longer then to make the changes in the code,

@Misiu
Copy link

Misiu commented Jun 24, 2020

@per1234 @Rotzbua maybe this can be merged instead of #50?

Copy link
Contributor

@Rotzbua Rotzbua left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Misiu there also some space for improvements

src/Ethernet.cpp Outdated
@@ -27,6 +27,11 @@ IPAddress EthernetClass::_dnsServerAddress;
DhcpClass* EthernetClass::_dhcp = NULL;

int EthernetClass::begin(uint8_t *mac, unsigned long timeout, unsigned long responseTimeout)
{
begin(mac, NULL, timeout, responseTimeout);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bug: missing return

src/Dhcp.cpp Outdated
@@ -18,6 +23,20 @@ int DhcpClass::beginWithDHCP(uint8_t *mac, unsigned long timeout, unsigned long
memset(_dhcpMacAddr, 0, 6);
reset_DHCP_lease();

if (NULL == hostname)
{
strcpy(_dhcpHostname, HOST_NAME);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should also use safe str func

src/Dhcp.cpp Outdated
if (NULL == hostname)
{
strcpy(_dhcpHostname, HOST_NAME);
int offset = strlen(HOST_NAME);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if somebody modifies constant HOST_NAME, here we get a too high value which cause a buffer overwrite the following lines.

src/Ethernet.h Outdated

int beginWithDHCP(uint8_t *, unsigned long timeout = 60000, unsigned long responseTimeout = 4000);
int beginWithDHCP(uint8_t *, const char *, unsigned long timeout = 60000, unsigned long responseTimeout = 4000);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this class is just used internally(?), so in my opinion could be changed even if it breaks backwards compatibility.

src/Dhcp.cpp Outdated
@@ -7,6 +7,11 @@
#include "utility/w5100.h"

int DhcpClass::beginWithDHCP(uint8_t *mac, unsigned long timeout, unsigned long responseTimeout)
{
return beginWithDHCP(mac, NULL, timeout, responseTimeout);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of NULL better use nullptr


// MAC address
byte mac[] = {
0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

most examples use:
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED

my pr to use this mac in every example is pending.

byte mac[] = {
0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02
};
// Hostname
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add the max length of hostname to comment, because most people wont get in touch with the source code.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also that just acii charset is allowed

src/Dhcp.cpp Outdated
printByte((char*)&(_dhcpHostname[offset + 0]), mac[3]);
printByte((char*)&(_dhcpHostname[offset + 2]), mac[4]);
printByte((char*)&(_dhcpHostname[offset + 4]), mac[5]);
_dhcpHostname[offset + 6] = 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be '\0' ?

src/Ethernet.h Outdated
@@ -80,6 +81,7 @@ class EthernetClass {
// gain the rest of the configuration through DHCP.
// Returns 0 if the DHCP configuration failed, and 1 if it succeeded
static int begin(uint8_t *mac, unsigned long timeout = 60000, unsigned long responseTimeout = 4000);
static int begin(uint8_t *mac, const char *hostname, unsigned long timeout = 60000, unsigned long responseTimeout = 4000);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

overloading a function with optional arguments is a bad design pattern and should not be done.

a solution without overloading is in this case not so elegant:

  1. breaking backwards compatibility
 	static int begin(uint8_t *mac, const char *hostname = nullptr, unsigned long timeout = 60000, unsigned long responseTimeout = 4000); 
  1. not breaking backwards compatibility
 	static int begin(uint8_t *mac, unsigned long timeout = 60000, unsigned long responseTimeout = 4000, const char *hostname = nullptr); 
  1. introduce extra function
setHostname(const char *hostname = nullptr)

must be called before calling begin()
and keep unchanged:

 	static int begin(uint8_t *mac, unsigned long timeout = 60000, unsigned long responseTimeout = 4000);

src/Dhcp.cpp Outdated
printByte((char*)&(buffer[26]), _dhcpMacAddr[4]);
printByte((char*)&(buffer[28]), _dhcpMacAddr[5]);
buffer[17] = strlen(_dhcpHostname); // length of hostname
strcpy((char*)&(buffer[18]), _dhcpHostname);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should also use safe str func

@Misiu
Copy link

Misiu commented Jun 29, 2020

@shoop any chances you might look into this? 🙂

@shoop
Copy link
Author

shoop commented Jul 1, 2020

hi @Rotzbua , thank you for the review.

I don't pretend that my C code is very good, but I tried to address all your comments.
I chose to break backwards compatibility in the interface because (as seen in the example) I find the consuming version better with the MAC, HOSTNAME order before the optional timeout arguments. But if you would like to be backwards compatible I can try and do another version.

Note this is still only very lightly tested.

@CLAassistant
Copy link

CLAassistant commented Apr 9, 2021

CLA assistant check
All committers have signed the CLA.

@thunermay
Copy link

@Rotzbua Any reasons why this isn't merged? I could really use this feature :)
If I can help out anyhow, feel free to ask :)
BR Leon

@Rotzbua
Copy link
Contributor

Rotzbua commented May 23, 2025

@thunermay I am not a maintainer of this repository, so I can not merge.

@thunermay
Copy link

@Rotzbua who is? You are marked as "Contributor", but I guess that does not mean, that you can merge?!

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

Successfully merging this pull request may close these issues.

8 participants