-
Notifications
You must be signed in to change notification settings - Fork 269
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
base: master
Are you sure you want to change the base?
Conversation
Can anyone say why seemingly great PRs like this never get merged or even commented on by the maintainers here? |
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? |
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. |
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, |
There was a problem hiding this 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); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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:
- breaking backwards compatibility
static int begin(uint8_t *mac, const char *hostname = nullptr, unsigned long timeout = 60000, unsigned long responseTimeout = 4000);
- not breaking backwards compatibility
static int begin(uint8_t *mac, unsigned long timeout = 60000, unsigned long responseTimeout = 4000, const char *hostname = nullptr);
- 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); |
There was a problem hiding this comment.
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
@shoop any chances you might look into this? 🙂 |
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. Note this is still only very lightly tested. |
@Rotzbua Any reasons why this isn't merged? I could really use this feature :) |
@thunermay I am not a maintainer of this repository, so I can not merge. |
@Rotzbua who is? You are marked as "Contributor", but I guess that does not mean, that you can merge?! |
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.