Skip to content

Commit

Permalink
networking - move setHostame to base class SocketWrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
JAndrassy committed Nov 1, 2024
1 parent 26ff735 commit b3ad8e9
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 16 deletions.
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

0 comments on commit b3ad8e9

Please sign in to comment.