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.
pull/12063/head
Michal Paszta 2019-12-09 17:19:41 +02:00
parent 8d246d8ac1
commit d5d04ebb90
4 changed files with 39 additions and 51 deletions

View File

@ -349,36 +349,6 @@ char *LWIP::Interface::get_ip_address(char *buf, nsapi_size_t buflen)
#endif
}
nsapi_error_t LWIP::Interface::get_ip_address_if(const char *interface_name, SocketAddress *address)
{
if (!address) {
return NSAPI_ERROR_PARAMETER;
}
const ip_addr_t *addr;
if (interface_name == NULL) {
addr = LWIP::get_ip_addr(true, &netif);
} else {
addr = LWIP::get_ip_addr(true, netif_find(interface_name));
}
#if LWIP_IPV6
if (IP_IS_V6(addr)) {
char buf[NSAPI_IPv6_SIZE];
address->set_ip_address(ip6addr_ntoa_r(ip_2_ip6(addr), buf, NSAPI_IPv6_SIZE));
return NSAPI_ERROR_OK;
}
#endif
#if LWIP_IPV4
if (IP_IS_V4(addr)) {
char buf[NSAPI_IPv4_SIZE];
address->set_ip_address(ip4addr_ntoa_r(ip_2_ip4(addr), buf, NSAPI_IPv4_SIZE));
return NSAPI_ERROR_OK;
}
#endif
return NSAPI_ERROR_UNSUPPORTED;
}
char *LWIP::Interface::get_ip_address_if(char *buf, nsapi_size_t buflen, const char *interface_name)
{
const ip_addr_t *addr;

View File

@ -217,6 +217,36 @@ const char *LWIP::get_ip_address()
#endif
}
nsapi_error_t LWIP::get_ip_address_if(SocketAddress *address, const char *interface_name)
{
if (!address) {
return NSAPI_ERROR_PARAMETER;
}
const ip_addr_t *addr;
if (interface_name == NULL) {
addr = get_ip_addr(true, &default_interface->netif);
} else {
addr = get_ip_addr(true, netif_find(interface_name));
}
#if LWIP_IPV6
if (IP_IS_V6(addr)) {
char buf[NSAPI_IPv6_SIZE];
address->set_ip_address(ip6addr_ntoa_r(ip_2_ip6(addr), buf, NSAPI_IPv6_SIZE));
return NSAPI_ERROR_OK;
}
#endif
#if LWIP_IPV4
if (IP_IS_V4(addr)) {
char buf[NSAPI_IPv4_SIZE];
address->set_ip_address(ip4addr_ntoa_r(ip_2_ip4(addr), buf, NSAPI_IPv4_SIZE));
return NSAPI_ERROR_OK;
}
#endif
return NSAPI_ERROR_UNSUPPORTED;
}
nsapi_error_t LWIP::socket_open(nsapi_socket_t *handle, nsapi_protocol_t proto)
{
// check if network is connected

View File

@ -106,15 +106,6 @@ public:
*/
virtual nsapi_error_t get_ipv6_link_local_address(SocketAddress *address);
/** Copies IP address of the name based network interface to user supplied buffer
*
* @param buf buffer to which IP address will be copied as "W:X:Y:Z"
* @param buflen size of supplied buffer
* @param interface_name naame of the interface
* @return Pointer to a buffer, or NULL if the buffer is too small
*/
virtual nsapi_error_t get_ip_address_if(const char *interface_name, SocketAddress *address);
MBED_DEPRECATED_SINCE("mbed-os-5.15", "String-based APIs are deprecated")
virtual char *get_ip_address_if(char *buf, nsapi_size_t buflen, const char *interface_name);
@ -323,6 +314,15 @@ public:
* or null if not yet connected
*/
virtual const char *get_ip_address();
/** Copies IP address of the name based network interface to user supplied buffer
*
* @param address SocketAddress object pointer to store the address
* @param interface_name name of the interface
* @return Pointer to a buffer, or NULL if the buffer is too small
*/
virtual nsapi_error_t get_ip_address_if(SocketAddress *address, const char *interface_name);
/** Set the network interface as default one
*/
virtual void set_default_interface(OnboardNetworkStack::Interface *interface);

View File

@ -121,18 +121,6 @@ public:
return NSAPI_ERROR_UNSUPPORTED;
}
/** @copydoc NetworkStack::get_ip_address_if */
virtual nsapi_error_t get_ip_address_if(SocketAddress *address, const char *interface_name)
{
return NSAPI_ERROR_UNSUPPORTED;
}
MBED_DEPRECATED_SINCE("mbed-os-5.15", "String-based APIs are deprecated")
virtual char *get_ip_address_if(char *buf, nsapi_size_t buflen, const char *interface_name)
{
return NULL;
};
/** @copydoc NetworkStack::get_netmask */
virtual nsapi_error_t get_netmask(SocketAddress *address) = 0;