Skip to content

Commit b3ad8e9

Browse files
committed
networking - move setHostame to base class SocketWrapper
1 parent 26ff735 commit b3ad8e9

File tree

6 files changed

+9
-16
lines changed

6 files changed

+9
-16
lines changed

Diff for: libraries/Ethernet/src/Ethernet.cpp

-5
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,6 @@ int arduino::EthernetClass::_begin(uint8_t *mac, unsigned long timeout, unsigned
2424
return (linkStatus() == LinkON ? 1 : 0);
2525
}
2626

27-
int arduino::EthernetClass::setHostname(const char* hostname) {
28-
eth_if->set_hostname(hostname);
29-
return 1;
30-
}
31-
3227
int arduino::EthernetClass::begin(uint8_t *mac, IPAddress ip) {
3328
IPAddress dns = ip;
3429
dns[3] = 1;

Diff for: libraries/Ethernet/src/Ethernet.h

-3
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,6 @@ class EthernetClass : public MbedSocketClass {
5656
EthernetClass(EthernetInterface *_if)
5757
: eth_if(_if){};
5858

59-
// When using DHCP the hostname provided will be used.
60-
int setHostname(const char* hostname);
61-
6259
// Initialise the Ethernet shield to use the provided MAC address and
6360
// gain the rest of the configuration through DHCP.
6461
// Returns 0 if the DHCP configuration failed, and 1 if it succeeded

Diff for: libraries/SocketWrapper/src/SocketHelpers.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ String arduino::MbedSocketClass::macAddress() {
1515
return String(getNetwork()->get_mac_address());
1616
}
1717

18+
int arduino::MbedSocketClass::setHostname(const char* hostname) {
19+
NetworkInterface* interface = getNetwork();
20+
interface->set_hostname(hostname);
21+
return 1;
22+
}
23+
1824
int arduino::MbedSocketClass::hostByName(const char* aHostname, IPAddress& aResult) {
1925
SocketAddress socketAddress = SocketAddress();
2026
nsapi_error_t returnCode = gethostbyname(getNetwork(), aHostname, &socketAddress);

Diff for: libraries/SocketWrapper/src/SocketHelpers.h

+3
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ class MbedSocketClass {
5757
*/
5858
void config(IPAddress local_ip, IPAddress dns_server, IPAddress gateway, IPAddress subnet);
5959

60+
// When using DHCP the hostname provided will be used.
61+
int setHostname(const char* hostname);
62+
6063
/* Change DNS Ip configuration
6164
*
6265
* param dns_server1: ip configuration for DNS server 1

Diff for: libraries/WiFi/src/WiFi.cpp

-5
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,6 @@ int arduino::WiFiClass::begin(const char* ssid) {
9696
return begin(ssid, NULL, ENC_TYPE_NONE);
9797
}
9898

99-
int arduino::WiFiClass::setHostname(const char* hostname) {
100-
wifi_if->set_hostname(hostname);
101-
return 1;
102-
}
103-
10499
//Config Wifi to set Static IP && Disable DHCP
105100
void arduino::WiFiClass::config(const char* localip, const char* netmask, const char* gateway){
106101
SocketHelpers::config(IPAddress(localip), dnsIP(0), IPAddress(gateway), IPAddress(netmask));

Diff for: libraries/WiFi/src/WiFi.h

-3
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,6 @@ class WiFiClass : public MbedSocketClass {
7676
*/
7777
int begin(const char* ssid, const char* passphrase, wl_enc_type security = ENC_TYPE_UNKNOWN);
7878

79-
// When using DHCP the hostname provided will be used.
80-
int setHostname(const char* hostname);
81-
8279
// Inherit config methods from the parent class
8380
using MbedSocketClass::config;
8481

0 commit comments

Comments
 (0)