mirror of https://github.com/ARMmbed/mbed-os.git
Merge pull request #12063 from michalpasztamobica/get_ip_address_if_fixed
Move get_ip_address_if() to NetworkStack and include it in multihoming testpull/12169/head
commit
5bef46b71a
|
|
@ -37,6 +37,7 @@
|
||||||
#include "utest.h"
|
#include "utest.h"
|
||||||
#include "utest/utest_stack_trace.h"
|
#include "utest/utest_stack_trace.h"
|
||||||
#include "multihoming_tests.h"
|
#include "multihoming_tests.h"
|
||||||
|
#include "LWIPStack.h"
|
||||||
|
|
||||||
using namespace utest::v1;
|
using namespace utest::v1;
|
||||||
|
|
||||||
|
|
@ -77,6 +78,10 @@ static void _ifup()
|
||||||
SocketAddress eth_ip_address;
|
SocketAddress eth_ip_address;
|
||||||
eth->get_ip_address(ð_ip_address);
|
eth->get_ip_address(ð_ip_address);
|
||||||
printf("MBED: IP address is '%s' interface name %s\n", eth_ip_address.get_ip_address(), interface_name[interface_num]);
|
printf("MBED: IP address is '%s' interface name %s\n", eth_ip_address.get_ip_address(), interface_name[interface_num]);
|
||||||
|
SocketAddress eth_ip_address_if;
|
||||||
|
LWIP::get_instance().get_ip_address_if(ð_ip_address_if, interface_name[interface_num]);
|
||||||
|
printf("IP_if: %s\n", eth_ip_address.get_ip_address());
|
||||||
|
TEST_ASSERT_EQUAL(eth_ip_address_if, eth_ip_address);
|
||||||
interface_num++;
|
interface_num++;
|
||||||
|
|
||||||
wifi = WiFiInterface::get_default_instance();
|
wifi = WiFiInterface::get_default_instance();
|
||||||
|
|
@ -104,6 +109,10 @@ static void _ifup()
|
||||||
SocketAddress wifi_ip_address;
|
SocketAddress wifi_ip_address;
|
||||||
wifi->get_ip_address(&wifi_ip_address);
|
wifi->get_ip_address(&wifi_ip_address);
|
||||||
printf("IP: %s\n", STRING_VERIFY(wifi_ip_address.get_ip_address()));
|
printf("IP: %s\n", STRING_VERIFY(wifi_ip_address.get_ip_address()));
|
||||||
|
SocketAddress wifi_ip_address_if;
|
||||||
|
LWIP::get_instance().get_ip_address_if(&wifi_ip_address_if, interface_name[interface_num]);
|
||||||
|
printf("IP_if: %s\n", STRING_VERIFY(wifi_ip_address_if.get_ip_address()));
|
||||||
|
TEST_ASSERT_EQUAL(wifi_ip_address_if, wifi_ip_address);
|
||||||
SocketAddress wifi_netmask;
|
SocketAddress wifi_netmask;
|
||||||
wifi->get_netmask(&wifi_netmask);
|
wifi->get_netmask(&wifi_netmask);
|
||||||
printf("Netmask: %s\n", STRING_VERIFY(wifi_netmask.get_ip_address()));
|
printf("Netmask: %s\n", STRING_VERIFY(wifi_netmask.get_ip_address()));
|
||||||
|
|
|
||||||
|
|
@ -349,63 +349,6 @@ char *LWIP::Interface::get_ip_address(char *buf, nsapi_size_t buflen)
|
||||||
#endif
|
#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;
|
|
||||||
|
|
||||||
if (interface_name == NULL) {
|
|
||||||
addr = LWIP::get_ip_addr(true, &netif);
|
|
||||||
} else {
|
|
||||||
addr = LWIP::get_ip_addr(true, netif_find(interface_name));
|
|
||||||
}
|
|
||||||
if (!addr) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
#if LWIP_IPV6
|
|
||||||
if (IP_IS_V6(addr)) {
|
|
||||||
return ip6addr_ntoa_r(ip_2_ip6(addr), buf, buflen);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
#if LWIP_IPV4
|
|
||||||
if (IP_IS_V4(addr)) {
|
|
||||||
return ip4addr_ntoa_r(ip_2_ip4(addr), buf, buflen);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
#if LWIP_IPV6 && LWIP_IPV4
|
|
||||||
return NULL;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
nsapi_error_t LWIP::Interface::get_netmask(SocketAddress *address)
|
nsapi_error_t LWIP::Interface::get_netmask(SocketAddress *address)
|
||||||
{
|
{
|
||||||
if (!address) {
|
if (!address) {
|
||||||
|
|
|
||||||
|
|
@ -217,6 +217,36 @@ const char *LWIP::get_ip_address()
|
||||||
#endif
|
#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)
|
nsapi_error_t LWIP::socket_open(nsapi_socket_t *handle, nsapi_protocol_t proto)
|
||||||
{
|
{
|
||||||
// check if network is connected
|
// check if network is connected
|
||||||
|
|
|
||||||
|
|
@ -106,18 +106,6 @@ public:
|
||||||
*/
|
*/
|
||||||
virtual nsapi_error_t get_ipv6_link_local_address(SocketAddress *address);
|
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);
|
|
||||||
|
|
||||||
/** Copies netmask of the network interface to user supplied buffer
|
/** Copies netmask of the network interface to user supplied buffer
|
||||||
*
|
*
|
||||||
* @param buf buffer to which netmask will be copied as "W:X:Y:Z"
|
* @param buf buffer to which netmask will be copied as "W:X:Y:Z"
|
||||||
|
|
@ -323,6 +311,15 @@ public:
|
||||||
* or null if not yet connected
|
* or null if not yet connected
|
||||||
*/
|
*/
|
||||||
virtual const char *get_ip_address();
|
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
|
/** Set the network interface as default one
|
||||||
*/
|
*/
|
||||||
virtual void set_default_interface(OnboardNetworkStack::Interface *interface);
|
virtual void set_default_interface(OnboardNetworkStack::Interface *interface);
|
||||||
|
|
|
||||||
|
|
@ -121,18 +121,6 @@ public:
|
||||||
return NSAPI_ERROR_UNSUPPORTED;
|
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 */
|
/** @copydoc NetworkStack::get_netmask */
|
||||||
virtual nsapi_error_t get_netmask(SocketAddress *address) = 0;
|
virtual nsapi_error_t get_netmask(SocketAddress *address) = 0;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue