Skip to content

Commit 79e014e

Browse files
authored
Merge pull request #222 from JAndrassy/ethernet_begin_fix_params
Ethernet.begin - fix parameters ordering
2 parents 9ca7bad + bd61f70 commit 79e014e

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

Diff for: libraries/Ethernet/src/Ethernet.cpp

+12-9
Original file line numberDiff line numberDiff line change
@@ -28,29 +28,32 @@ int CEthernet::begin(unsigned long timeout, unsigned long responseTimeout) {
2828
/* -------------------------------------------------------------------------- */
2929
int CEthernet::begin(IPAddress local_ip) {
3030
/* -------------------------------------------------------------------------- */
31-
IPAddress subnet(255, 255, 255, 0);
32-
return begin(local_ip, subnet);
31+
// Assume the DNS server will be the machine on the same network as the local IP
32+
// but with last octet being '1'
33+
IPAddress dns_server = local_ip;
34+
dns_server[3] = 1;
35+
return begin(local_ip, dns_server);
3336
}
3437

3538
/* -------------------------------------------------------------------------- */
36-
int CEthernet::begin(IPAddress local_ip, IPAddress subnet) {
39+
int CEthernet::begin(IPAddress local_ip, IPAddress dns_server) {
3740
/* -------------------------------------------------------------------------- */
3841
// Assume the gateway will be the machine on the same network as the local IP
3942
// but with last octet being '1'
4043
IPAddress gateway = local_ip;
4144
gateway[3] = 1;
42-
return begin(local_ip, subnet, gateway);
45+
return begin(local_ip, dns_server, gateway);
4346
}
4447

4548
/* -------------------------------------------------------------------------- */
46-
int CEthernet::begin(IPAddress local_ip, IPAddress subnet, IPAddress gateway) {
49+
int CEthernet::begin(IPAddress local_ip, IPAddress dns_server, IPAddress gateway) {
4750
/* -------------------------------------------------------------------------- */
48-
// Assume the DNS server will be the same machine than gateway
49-
return begin(local_ip, subnet, gateway, gateway);
51+
IPAddress subnet(255, 255, 255, 0);
52+
return begin(local_ip, dns_server, gateway, subnet);
5053
}
5154

5255
/* -------------------------------------------------------------------------- */
53-
int CEthernet::begin(IPAddress local_ip, IPAddress subnet, IPAddress gateway, IPAddress dns_server) {
56+
int CEthernet::begin(IPAddress local_ip, IPAddress dns_server, IPAddress gateway, IPAddress subnet) {
5457
/* -------------------------------------------------------------------------- */
5558

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

115118
/* -------------------------------------------------------------------------- */

Diff for: libraries/Ethernet/src/EthernetC33.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ class CEthernet {
4141
int begin(unsigned long timeout = 60000, unsigned long responseTimeout = 4000);
4242
EthernetLinkStatus linkStatus();
4343
int begin(IPAddress local_ip);
44-
int begin(IPAddress local_ip, IPAddress subnet);
45-
int begin(IPAddress local_ip, IPAddress subnet, IPAddress gateway);
46-
int begin(IPAddress local_ip, IPAddress subnet, IPAddress gateway, IPAddress dns_server);
44+
int begin(IPAddress local_ip, IPAddress dns_server);
45+
int begin(IPAddress local_ip, IPAddress dns_server, IPAddress gateway);
46+
int begin(IPAddress local_ip, IPAddress dns_server, IPAddress gateway, IPAddress subnet);
4747
// Initialise the Ethernet shield to use the provided MAC address and gain the rest of the
4848
// configuration through DHCP.
4949
// Returns 0 if the DHCP configuration failed, and 1 if it succeeded

0 commit comments

Comments
 (0)