Skip to content
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

Ethernet - complete API (setHostname, dnsIP(n), hostByName, ...) #221

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
29 changes: 29 additions & 0 deletions libraries/Ethernet/src/Ethernet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,20 @@ int CEthernet::begin(IPAddress local_ip, IPAddress subnet, IPAddress gateway, IP
return 1;
}

/* -------------------------------------------------------------------------- */
void CEthernet::setHostname(const char* hostname) {
/* -------------------------------------------------------------------------- */
if (ni != nullptr) {
ni->setHostname(hostname);
}
}

/* -------------------------------------------------------------------------- */
void CEthernet::setDnsServerIP(IPAddress dns_server) {
/* -------------------------------------------------------------------------- */
setDNS(dns_server);
}

/* -------------------------------------------------------------------------- */
void CEthernet::setDNS(IPAddress dns_server) {
/* -------------------------------------------------------------------------- */
Expand Down Expand Up @@ -178,6 +192,11 @@ void CEthernet::MACAddress(uint8_t *mac) {
CLwipIf::getInstance().getMacAddress(NI_ETHERNET, mac);
}

uint8_t* CEthernet::macAddress(uint8_t *mac) {
CLwipIf::getInstance().getMacAddress(NI_ETHERNET, mac);
return mac;
}

IPAddress CEthernet::localIP() {
if(ni != nullptr) {
return IPAddress(ni->getIpAdd());
Expand All @@ -203,4 +222,14 @@ IPAddress CEthernet::dnsServerIP() {
return CLwipIf::getInstance().getDns();
}

IPAddress CEthernet::dnsIP(int n) {
return CLwipIf::getInstance().getDns(n);
}

/* -------------------------------------------------------------------------- */
int CEthernet::hostByName(const char* hostname, IPAddress& result) {
/* -------------------------------------------------------------------------- */
return CLwipIf::getInstance().getHostByName(hostname, result);
}

CEthernet Ethernet;
10 changes: 8 additions & 2 deletions libraries/Ethernet/src/EthernetC33.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ class CEthernet {
int begin(uint8_t *mac_address, IPAddress local_ip, IPAddress dns_server, IPAddress gateway, IPAddress subnet, unsigned long timeout = 60000, unsigned long responseTimeout = 4000);
EthernetHardwareStatus hardwareStatus();

void setHostname(const char* hostname);
void setDnsServerIP(const IPAddress dns_server); // legacy Ethernet API
void setDNS(IPAddress dns_server);

int disconnect(void);
Expand All @@ -62,11 +64,15 @@ class CEthernet {


uint8_t *MACAddress(void);
void MACAddress(uint8_t *mac);
void MACAddress(uint8_t *mac); // legacy Ethernet API
uint8_t* macAddress(uint8_t* mac);
IPAddress localIP();
IPAddress subnetMask();
IPAddress gatewayIP();
IPAddress dnsServerIP();
IPAddress dnsServerIP(); // legacy Ethernet API
IPAddress dnsIP(int n = 0);

int hostByName(const char* hostname, IPAddress& result);

friend class EthernetClient;
friend class EthernetServer;
Expand Down
Loading