1
0
mirror of https://github.com/arduino/Arduino.git synced 2025-01-18 07:52:14 +01:00

Added a way to specify the DNS server to use with static IP

This commit is contained in:
amcewen 2011-06-12 22:02:25 +01:00
parent 8dfee1fb74
commit 789e22add2
2 changed files with 17 additions and 6 deletions

View File

@ -33,27 +33,37 @@ int EthernetClass::begin(uint8_t *mac_address)
} }
void EthernetClass::begin(uint8_t *mac_address, IPAddress local_ip) void EthernetClass::begin(uint8_t *mac_address, IPAddress local_ip)
{
// 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;
begin(mac_address, local_ip, dns_server);
}
void EthernetClass::begin(uint8_t *mac_address, IPAddress local_ip, IPAddress dns_server)
{ {
// Assume the gateway will be the machine on the same network as the local IP // Assume the gateway will be the machine on the same network as the local IP
// but with last octet being '1' // but with last octet being '1'
IPAddress gateway = local_ip; IPAddress gateway = local_ip;
gateway[3] = 1; gateway[3] = 1;
begin(mac_address, local_ip, gateway); begin(mac_address, local_ip, dns_server, gateway);
} }
void EthernetClass::begin(uint8_t *mac_address, IPAddress local_ip, IPAddress gateway) void EthernetClass::begin(uint8_t *mac_address, IPAddress local_ip, IPAddress dns_server, IPAddress gateway)
{ {
IPAddress subnet(255, 255, 255, 0); IPAddress subnet(255, 255, 255, 0);
begin(mac_address, local_ip, gateway, subnet); begin(mac_address, local_ip, dns_server, gateway, subnet);
} }
void EthernetClass::begin(uint8_t *mac, IPAddress local_ip, IPAddress gateway, IPAddress subnet) void EthernetClass::begin(uint8_t *mac, IPAddress local_ip, IPAddress dns_server, IPAddress gateway, IPAddress subnet)
{ {
W5100.init(); W5100.init();
W5100.setMACAddress(mac); W5100.setMACAddress(mac);
W5100.setIPAddress(local_ip._address); W5100.setIPAddress(local_ip._address);
W5100.setGatewayIp(gateway._address); W5100.setGatewayIp(gateway._address);
W5100.setSubnetMask(subnet._address); W5100.setSubnetMask(subnet._address);
_dnsServerAddress = dns_server;
} }
IPAddress EthernetClass::localIP() IPAddress EthernetClass::localIP()

View File

@ -20,8 +20,9 @@ public:
// Returns 0 if the DHCP configuration failed, and 1 if it succeeded // Returns 0 if the DHCP configuration failed, and 1 if it succeeded
int begin(uint8_t *mac_address); int begin(uint8_t *mac_address);
void begin(uint8_t *mac_address, IPAddress local_ip); void begin(uint8_t *mac_address, IPAddress local_ip);
void begin(uint8_t *mac_address, IPAddress local_ip, IPAddress gateway); void begin(uint8_t *mac_address, IPAddress local_ip, IPAddress dns_server);
void begin(uint8_t *mac_address, IPAddress local_ip, IPAddress gateway, IPAddress subnet); void begin(uint8_t *mac_address, IPAddress local_ip, IPAddress dns_server, IPAddress gateway);
void begin(uint8_t *mac_address, IPAddress local_ip, IPAddress dns_server, IPAddress gateway, IPAddress subnet);
IPAddress localIP(); IPAddress localIP();
IPAddress subnetMask(); IPAddress subnetMask();