Skip to content

Ethernet.begin - fix parameters ordering #222

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

Merged
merged 1 commit into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions libraries/Ethernet/src/Ethernet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,29 +28,32 @@ int CEthernet::begin(unsigned long timeout, unsigned long responseTimeout) {
/* -------------------------------------------------------------------------- */
int CEthernet::begin(IPAddress local_ip) {
/* -------------------------------------------------------------------------- */
IPAddress subnet(255, 255, 255, 0);
return begin(local_ip, subnet);
// Assume the DNS server will be the machine on the same network as the local IP
// but with last octet being '1'
IPAddress dns_server = local_ip;
dns_server[3] = 1;
return begin(local_ip, dns_server);
}

/* -------------------------------------------------------------------------- */
int CEthernet::begin(IPAddress local_ip, IPAddress subnet) {
int CEthernet::begin(IPAddress local_ip, IPAddress dns_server) {
/* -------------------------------------------------------------------------- */
// Assume the gateway will be the machine on the same network as the local IP
// but with last octet being '1'
IPAddress gateway = local_ip;
gateway[3] = 1;
return begin(local_ip, subnet, gateway);
return begin(local_ip, dns_server, gateway);
}

/* -------------------------------------------------------------------------- */
int CEthernet::begin(IPAddress local_ip, IPAddress subnet, IPAddress gateway) {
int CEthernet::begin(IPAddress local_ip, IPAddress dns_server, IPAddress gateway) {
/* -------------------------------------------------------------------------- */
// Assume the DNS server will be the same machine than gateway
return begin(local_ip, subnet, gateway, gateway);
IPAddress subnet(255, 255, 255, 0);
return begin(local_ip, dns_server, gateway, subnet);
}

/* -------------------------------------------------------------------------- */
int CEthernet::begin(IPAddress local_ip, IPAddress subnet, IPAddress gateway, IPAddress dns_server) {
int CEthernet::begin(IPAddress local_ip, IPAddress dns_server, IPAddress gateway, IPAddress subnet) {
/* -------------------------------------------------------------------------- */

ni = CLwipIf::getInstance().get(NI_ETHERNET, local_ip, gateway, subnet);
Expand Down Expand Up @@ -109,7 +112,7 @@ int CEthernet::begin(uint8_t *mac_address, IPAddress local_ip, IPAddress dns_ser
int CEthernet::begin(uint8_t *mac, IPAddress local_ip, IPAddress dns_server, IPAddress gateway, IPAddress subnet, unsigned long timeout, unsigned long responseTimeout) {
/* -------------------------------------------------------------------------- */
CLwipIf::getInstance().setMacAddress(NI_ETHERNET, mac_address);
return begin(local_ip, subnet, gateway, dns_server);
return begin(local_ip, dns_server, gateway, subnet);
}

/* -------------------------------------------------------------------------- */
Expand Down
6 changes: 3 additions & 3 deletions libraries/Ethernet/src/EthernetC33.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ class CEthernet {
int begin(unsigned long timeout = 60000, unsigned long responseTimeout = 4000);
EthernetLinkStatus linkStatus();
int begin(IPAddress local_ip);
int begin(IPAddress local_ip, IPAddress subnet);
int begin(IPAddress local_ip, IPAddress subnet, IPAddress gateway);
int begin(IPAddress local_ip, IPAddress subnet, IPAddress gateway, IPAddress dns_server);
int begin(IPAddress local_ip, IPAddress dns_server);
int begin(IPAddress local_ip, IPAddress dns_server, IPAddress gateway);
int begin(IPAddress local_ip, IPAddress dns_server, IPAddress gateway, IPAddress subnet);
// Initialise the Ethernet shield to use the provided MAC address and gain the rest of the
// configuration through DHCP.
// Returns 0 if the DHCP configuration failed, and 1 if it succeeded
Expand Down