Skip to content

Commit d5d04eb

Browse files
Move get_ip_address_if to the right class
get_ip_address_if was wrongly added to OnboardNetworkStack::Interface, while it should in fact be placed directly in OnboardNetworkStack.
1 parent 8d246d8 commit d5d04eb

File tree

4 files changed

+39
-51
lines changed

4 files changed

+39
-51
lines changed

features/lwipstack/LWIPInterface.cpp

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -349,36 +349,6 @@ char *LWIP::Interface::get_ip_address(char *buf, nsapi_size_t buflen)
349349
#endif
350350
}
351351

352-
nsapi_error_t LWIP::Interface::get_ip_address_if(const char *interface_name, SocketAddress *address)
353-
{
354-
if (!address) {
355-
return NSAPI_ERROR_PARAMETER;
356-
}
357-
358-
const ip_addr_t *addr;
359-
360-
if (interface_name == NULL) {
361-
addr = LWIP::get_ip_addr(true, &netif);
362-
} else {
363-
addr = LWIP::get_ip_addr(true, netif_find(interface_name));
364-
}
365-
#if LWIP_IPV6
366-
if (IP_IS_V6(addr)) {
367-
char buf[NSAPI_IPv6_SIZE];
368-
address->set_ip_address(ip6addr_ntoa_r(ip_2_ip6(addr), buf, NSAPI_IPv6_SIZE));
369-
return NSAPI_ERROR_OK;
370-
}
371-
#endif
372-
#if LWIP_IPV4
373-
if (IP_IS_V4(addr)) {
374-
char buf[NSAPI_IPv4_SIZE];
375-
address->set_ip_address(ip4addr_ntoa_r(ip_2_ip4(addr), buf, NSAPI_IPv4_SIZE));
376-
return NSAPI_ERROR_OK;
377-
}
378-
#endif
379-
return NSAPI_ERROR_UNSUPPORTED;
380-
}
381-
382352
char *LWIP::Interface::get_ip_address_if(char *buf, nsapi_size_t buflen, const char *interface_name)
383353
{
384354
const ip_addr_t *addr;

features/lwipstack/LWIPStack.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,36 @@ const char *LWIP::get_ip_address()
217217
#endif
218218
}
219219

220+
nsapi_error_t LWIP::get_ip_address_if(SocketAddress *address, const char *interface_name)
221+
{
222+
if (!address) {
223+
return NSAPI_ERROR_PARAMETER;
224+
}
225+
226+
const ip_addr_t *addr;
227+
228+
if (interface_name == NULL) {
229+
addr = get_ip_addr(true, &default_interface->netif);
230+
} else {
231+
addr = get_ip_addr(true, netif_find(interface_name));
232+
}
233+
#if LWIP_IPV6
234+
if (IP_IS_V6(addr)) {
235+
char buf[NSAPI_IPv6_SIZE];
236+
address->set_ip_address(ip6addr_ntoa_r(ip_2_ip6(addr), buf, NSAPI_IPv6_SIZE));
237+
return NSAPI_ERROR_OK;
238+
}
239+
#endif
240+
#if LWIP_IPV4
241+
if (IP_IS_V4(addr)) {
242+
char buf[NSAPI_IPv4_SIZE];
243+
address->set_ip_address(ip4addr_ntoa_r(ip_2_ip4(addr), buf, NSAPI_IPv4_SIZE));
244+
return NSAPI_ERROR_OK;
245+
}
246+
#endif
247+
return NSAPI_ERROR_UNSUPPORTED;
248+
}
249+
220250
nsapi_error_t LWIP::socket_open(nsapi_socket_t *handle, nsapi_protocol_t proto)
221251
{
222252
// check if network is connected

features/lwipstack/LWIPStack.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -106,15 +106,6 @@ class LWIP : public OnboardNetworkStack, private mbed::NonCopyable<LWIP> {
106106
*/
107107
virtual nsapi_error_t get_ipv6_link_local_address(SocketAddress *address);
108108

109-
/** Copies IP address of the name based network interface to user supplied buffer
110-
*
111-
* @param buf buffer to which IP address will be copied as "W:X:Y:Z"
112-
* @param buflen size of supplied buffer
113-
* @param interface_name naame of the interface
114-
* @return Pointer to a buffer, or NULL if the buffer is too small
115-
*/
116-
virtual nsapi_error_t get_ip_address_if(const char *interface_name, SocketAddress *address);
117-
118109
MBED_DEPRECATED_SINCE("mbed-os-5.15", "String-based APIs are deprecated")
119110
virtual char *get_ip_address_if(char *buf, nsapi_size_t buflen, const char *interface_name);
120111

@@ -323,6 +314,15 @@ class LWIP : public OnboardNetworkStack, private mbed::NonCopyable<LWIP> {
323314
* or null if not yet connected
324315
*/
325316
virtual const char *get_ip_address();
317+
318+
/** Copies IP address of the name based network interface to user supplied buffer
319+
*
320+
* @param address SocketAddress object pointer to store the address
321+
* @param interface_name name of the interface
322+
* @return Pointer to a buffer, or NULL if the buffer is too small
323+
*/
324+
virtual nsapi_error_t get_ip_address_if(SocketAddress *address, const char *interface_name);
325+
326326
/** Set the network interface as default one
327327
*/
328328
virtual void set_default_interface(OnboardNetworkStack::Interface *interface);

features/netsocket/OnboardNetworkStack.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -121,18 +121,6 @@ class OnboardNetworkStack : public NetworkStack {
121121
return NSAPI_ERROR_UNSUPPORTED;
122122
}
123123

124-
/** @copydoc NetworkStack::get_ip_address_if */
125-
virtual nsapi_error_t get_ip_address_if(SocketAddress *address, const char *interface_name)
126-
{
127-
return NSAPI_ERROR_UNSUPPORTED;
128-
}
129-
130-
MBED_DEPRECATED_SINCE("mbed-os-5.15", "String-based APIs are deprecated")
131-
virtual char *get_ip_address_if(char *buf, nsapi_size_t buflen, const char *interface_name)
132-
{
133-
return NULL;
134-
};
135-
136124
/** @copydoc NetworkStack::get_netmask */
137125
virtual nsapi_error_t get_netmask(SocketAddress *address) = 0;
138126

0 commit comments

Comments
 (0)