8000 Add helper to convert from IPAddress to SocketAddress · arduino/ArduinoCore-mbed@e1e58b1 · GitHub
[go: up one dir, main page]

Skip to content

Commit e1e58b1

Browse files
committed
Add helper to convert from IPAddress to SocketAddress
1 parent 0cb4082 commit e1e58b1

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

libraries/WiFi/src/WiFi.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ arduino::IPAddress arduino::WiFiClass::ipAddressFromSocketAddress(SocketAddress
1515
return IPAddress(address.bytes[0], address.bytes[1], address.bytes[2], address.bytes[3]);
1616
}
1717

18+
SocketAddress arduino::WiFiClass::socketAddressFromIpAddress(arduino::IPAddress ipAddress, uint16_t port) {
19+
nsapi_addr_t convertedIP = {NSAPI_IPv4, {ip[0], ip[1], ip[2], ip[3]}};
20+
return SocketAddress(convertedIP, port);
21+
}
22+
1823
int arduino::WiFiClass::begin(const char* ssid, const char *passphrase) {
1924
if (_ssid) free(_ssid);
2025

libraries/WiFi/src/WiFi.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,7 @@ class WiFiClass
311311
void ensureDefaultAPNetworkConfiguration();
312312
bool isVisible(const char* ssid);
313313
arduino::IPAddress ipAddressFromSocketAddress(SocketAddress socketAddress);
314+
SocketAddress socketAddressFromIpAddress(arduino::IPAddress ipAddress, uint16_t port);
314315
};
315316

316317
}

0 commit comments

Comments
 (0)
0