Skip to content

Commit b4c1f7f

Browse files
committed
Correct LWIP::get_ip_address
Previous change that removed string-based APIs missed `LWIP::get_ip_address`. Remove string-based method (which is not overriding anything in `NetworkInterface`) and add missing binary form to implement `NetworkInterface::get_ip_address`.
1 parent 8f1bf96 commit b4c1f7f

File tree

2 files changed

+7
-33
lines changed

2 files changed

+7
-33
lines changed

features/lwipstack/LWIPStack.cpp

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -191,30 +191,13 @@ LWIP::call_in_callback_cb_t LWIP::get_call_in_callback()
191191
return cb;
192192
}
193193

194-
const char *LWIP::get_ip_address()
194+
nsapi_error_t LWIP::get_ip_address(SocketAddress *address)
195195
{
196196
if (!default_interface) {
197-
return NULL;
197+
return NSAPI_ERROR_NO_ADDRESS;
198198
}
199199

200-
const ip_addr_t *addr = get_ip_addr(true, &default_interface->netif);
201-
202-
if (!addr) {
203-
return NULL;
204-
}
205-
#if LWIP_IPV6
206-
if (IP_IS_V6(addr)) {
207-
return ip6addr_ntoa_r(ip_2_ip6(addr), ip_address, sizeof(ip_address));
208-
}
209-
#endif
210-
#if LWIP_IPV4
211-
if (IP_IS_V4(addr)) {
212-
return ip4addr_ntoa_r(ip_2_ip4(addr), ip_address, sizeof(ip_address));
213-
}
214-
#endif
215-
#if LWIP_IPV6 && LWIP_IPV4
216-
return NULL;
217-
#endif
200+
return get_ip_address_if(address, nullptr);
218201
}
219202

220203
nsapi_error_t LWIP::get_ip_address_if(SocketAddress *address, const char *interface_name)

features/lwipstack/LWIPStack.h

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ class LWIP : public OnboardNetworkStack, private mbed::NonCopyable<LWIP> {
9393
*/
9494
virtual char *get_mac_address(char *buf, nsapi_size_t buflen);
9595

96-
/** @copydoc NetworkStack::get_ip_address */
96+
/** @copydoc OnboardNetworkStack::Interface::get_ip_address */
9797
virtual nsapi_error_t get_ip_address(SocketAddress *address);
9898

9999
/** Get the IPv6 link local address in SocketAddress representation
@@ -304,19 +304,10 @@ class LWIP : public OnboardNetworkStack, private mbed::NonCopyable<LWIP> {
304304
*/
305305
virtual nsapi_error_t add_dns_server(const SocketAddress &address, const char *interface_name);
306306

307-
/** Get the local IP address
308-
*
309-
* @return Null-terminated representation of the local IP address
310-
* or null if not yet connected
311-
*/
312-
virtual const char *get_ip_address();
307+
/** @copydoc NetworkStack::get_ip_address */
308+
virtual nsapi_error_t get_ip_address(SocketAddress *address);
313309

314-
/** Copies IP address of the name based network interface to user supplied buffer
315-
*
316-
* @param address SocketAddress object pointer to store the address
317-
* @param interface_name name of the interface
318-
* @return Pointer to a buffer, or NULL if the buffer is too small
319-
*/
310+
/** @copydoc NetworkStack::get_ip_address_if */
320311
virtual nsapi_error_t get_ip_address_if(SocketAddress *address, const char *interface_name);
321312

322313
/** Set the network interface as default one

0 commit comments

Comments
 (0)