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

networking - move setHostname to base class SocketWrapper #986

Merged
merged 1 commit into from
Jan 20, 2025
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
5 changes: 0 additions & 5 deletions libraries/Ethernet/src/Ethernet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,6 @@ int arduino::EthernetClass::_begin(uint8_t *mac, unsigned long timeout, unsigned
return (linkStatus() == LinkON ? 1 : 0);
}

int arduino::EthernetClass::setHostname(const char* hostname) {
eth_if->set_hostname(hostname);
return 1;
}

int arduino::EthernetClass::begin(uint8_t *mac, IPAddress ip) {
IPAddress dns = ip;
dns[3] = 1;
Expand Down
3 changes: 0 additions & 3 deletions libraries/Ethernet/src/Ethernet.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,6 @@ class EthernetClass : public MbedSocketClass {
EthernetClass(EthernetInterface *_if)
: eth_if(_if){};

// When using DHCP the hostname provided will be used.
int setHostname(const char* hostname);

// 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
6 changes: 6 additions & 0 deletions libraries/SocketWrapper/src/SocketHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ String arduino::MbedSocketClass::macAddress() {
return String(getNetwork()->get_mac_address());
}

int arduino::MbedSocketClass::setHostname(const char* hostname) {
NetworkInterface* interface = getNetwork();
interface->set_hostname(hostname);
return 1;
}

int arduino::MbedSocketClass::hostByName(const char* aHostname, IPAddress& aResult) {
SocketAddress socketAddress = SocketAddress();
nsapi_error_t returnCode = gethostbyname(getNetwork(), aHostname, &socketAddress);
Expand Down
3 changes: 3 additions & 0 deletions libraries/SocketWrapper/src/SocketHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ class MbedSocketClass {
*/
void config(IPAddress local_ip, IPAddress dns_server, IPAddress gateway, IPAddress subnet);

// When using DHCP the hostname provided will be used.
int setHostname(const char* hostname);

/* Change DNS Ip configuration
*
* param dns_server1: ip configuration for DNS server 1
Expand Down
5 changes: 0 additions & 5 deletions libraries/WiFi/src/WiFi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,6 @@ int arduino::WiFiClass::begin(const char* ssid) {
return begin(ssid, NULL, ENC_TYPE_NONE);
}

int arduino::WiFiClass::setHostname(const char* hostname) {
wifi_if->set_hostname(hostname);
return 1;
}

//Config Wifi to set Static IP && Disable DHCP
void arduino::WiFiClass::config(const char* localip, const char* netmask, const char* gateway){
SocketHelpers::config(IPAddress(localip), dnsIP(0), IPAddress(gateway), IPAddress(netmask));
Expand Down
3 changes: 0 additions & 3 deletions libraries/WiFi/src/WiFi.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,6 @@ class WiFiClass : public MbedSocketClass {
*/
int begin(const char* ssid, const char* passphrase, wl_enc_type security = ENC_TYPE_UNKNOWN);

// When using DHCP the hostname provided will be used.
int setHostname(const char* hostname);

// Inherit config methods from the parent class
using MbedSocketClass::config;

Expand Down