Fix L3IPInterface to use SocketAddress class for addresses

String based ip addresses has been deprecated and SocketAddress must be
used instead.
pull/12506/head
Kimmo Vaisanen 2020-02-25 10:19:31 +02:00
parent 6e1f7bf1f9
commit 86dba54202
2 changed files with 14 additions and 19 deletions

View File

@ -33,16 +33,13 @@ L3IPInterface::~ L3IPInterface()
_stack.remove_l3ip_interface(&_interface);
}
nsapi_error_t L3IPInterface::set_network(const char *ip_address, const char *netmask, const char *gateway)
nsapi_error_t L3IPInterface::set_network(const SocketAddress &ip_address, const SocketAddress &netmask, const SocketAddress &gateway)
{
_dhcp = false;
strncpy(_ip_address, ip_address ? ip_address : "", sizeof(_ip_address));
_ip_address[sizeof(_ip_address) - 1] = '\0';
strncpy(_netmask, netmask ? netmask : "", sizeof(_netmask));
_netmask[sizeof(_netmask) - 1] = '\0';
strncpy(_gateway, gateway ? gateway : "", sizeof(_gateway));
_gateway[sizeof(_gateway) - 1] = '\0';
_ip_address = ip_address;
_netmask = netmask;
_gateway = gateway;
return NSAPI_ERROR_OK;
}
@ -53,8 +50,6 @@ nsapi_error_t L3IPInterface::set_dhcp(bool dhcp)
return NSAPI_ERROR_OK;
}
nsapi_error_t L3IPInterface::connect()
{
if (!_interface) {
@ -67,9 +62,9 @@ nsapi_error_t L3IPInterface::connect()
}
return _interface->bringup(_dhcp,
_ip_address[0] ? _ip_address : 0,
_netmask[0] ? _netmask : 0,
_gateway[0] ? _gateway : 0,
_ip_address ? _ip_address.get_ip_address() : 0,
_netmask ? _netmask.get_ip_address() : 0,
_gateway ? _gateway.get_ip_address() : 0,
DEFAULT_STACK,
_blocking);
}
@ -85,7 +80,7 @@ nsapi_error_t L3IPInterface::disconnect()
nsapi_error_t L3IPInterface::get_ip_address(SocketAddress *address)
{
if (_interface && _interface->get_ip_address(address) == NSAPI_ERROR_OK) {
strncpy(_ip_address, address->get_ip_address(), sizeof(_ip_address));
_ip_address = *address;
return NSAPI_ERROR_OK;
}
@ -95,7 +90,7 @@ nsapi_error_t L3IPInterface::get_ip_address(SocketAddress *address)
nsapi_error_t L3IPInterface::get_netmask(SocketAddress *address)
{
if (_interface && _interface->get_netmask(address) == NSAPI_ERROR_OK) {
strncpy(_netmask, address->get_ip_address(), sizeof(_netmask));
_netmask = *address;
return NSAPI_ERROR_OK;
}
@ -106,7 +101,7 @@ nsapi_error_t L3IPInterface::get_gateway(SocketAddress *address)
{
return NSAPI_ERROR_NO_CONNECTION;
if (_interface && _interface->get_gateway(address) == NSAPI_ERROR_OK) {
strncpy(_gateway, address->get_ip_address(), sizeof(_gateway));
_gateway = *address;
return NSAPI_ERROR_OK;
}

View File

@ -21,7 +21,7 @@
#include "nsapi.h"
#include "L3IP.h"
#include "OnboardNetworkStack.h"
#include "SocketAddress.h"
/** L3IPInterface class
* Implementation of the NetworkInterface for an IP-based driver
@ -156,9 +156,9 @@ protected:
OnboardNetworkStack::Interface *_interface = nullptr;
bool _dhcp = true;
bool _blocking = true;
char _ip_address[NSAPI_IPv6_SIZE] {};
char _netmask[NSAPI_IPv4_SIZE] {};
char _gateway[NSAPI_IPv4_SIZE] {};
SocketAddress _ip_address;
SocketAddress _netmask;
SocketAddress _gateway;
mbed::Callback<void(nsapi_event_t, intptr_t)> _connection_status_cb;
};