Skip to content

Commit 1f46a1b

Browse files
committed
Added a way to specify the DNS server to use with static IP
1 parent 0ec9036 commit 1f46a1b

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

Ethernet.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,27 +33,37 @@ int EthernetClass::begin(uint8_t *mac_address)
3333
}
3434

3535
void EthernetClass::begin(uint8_t *mac_address, IPAddress local_ip)
36+
{
37+
// Assume the DNS server will be the machine on the same network as the local IP
38+
// but with last octet being '1'
39+
IPAddress dns_server = local_ip;
40+
dns_server[3] = 1;
41+
begin(mac_address, local_ip, dns_server);
42+
}
43+
44+
void EthernetClass::begin(uint8_t *mac_address, IPAddress local_ip, IPAddress dns_server)
3645
{
3746
// Assume the gateway will be the machine on the same network as the local IP
3847
// but with last octet being '1'
3948
IPAddress gateway = local_ip;
4049
gateway[3] = 1;
41-
begin(mac_address, local_ip, gateway);
50+
begin(mac_address, local_ip, dns_server, gateway);
4251
}
4352

44-
void EthernetClass::begin(uint8_t *mac_address, IPAddress local_ip, IPAddress gateway)
53+
void EthernetClass::begin(uint8_t *mac_address, IPAddress local_ip, IPAddress dns_server, IPAddress gateway)
4554
{
4655
IPAddress subnet(255, 255, 255, 0);
47-
begin(mac_address, local_ip, gateway, subnet);
56+
begin(mac_address, local_ip, dns_server, gateway, subnet);
4857
}
4958

50-
void EthernetClass::begin(uint8_t *mac, IPAddress local_ip, IPAddress gateway, IPAddress subnet)
59+
void EthernetClass::begin(uint8_t *mac, IPAddress local_ip, IPAddress dns_server, IPAddress gateway, IPAddress subnet)
5160
{
5261
W5100.init();
5362
W5100.setMACAddress(mac);
5463
W5100.setIPAddress(local_ip._address);
5564
W5100.setGatewayIp(gateway._address);
5665
W5100.setSubnetMask(subnet._address);
66+
_dnsServerAddress = dns_server;
5767
}
5868

5969
IPAddress EthernetClass::localIP()

Ethernet.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ class EthernetClass {
2020
// Returns 0 if the DHCP configuration failed, and 1 if it succeeded
2121
int begin(uint8_t *mac_address);
2222
void begin(uint8_t *mac_address, IPAddress local_ip);
23-
void begin(uint8_t *mac_address, IPAddress local_ip, IPAddress gateway);
24-
void begin(uint8_t *mac_address, IPAddress local_ip, IPAddress gateway, IPAddress subnet);
23+
void begin(uint8_t *mac_address, IPAddress local_ip, IPAddress dns_server);
24+
void begin(uint8_t *mac_address, IPAddress local_ip, IPAddress dns_server, IPAddress gateway);
25+
void begin(uint8_t *mac_address, IPAddress local_ip, IPAddress dns_server, IPAddress gateway, IPAddress subnet);
2526

2627
IPAddress localIP();
2728
IPAddress subnetMask();

0 commit comments

Comments
 (0)