Merge pull request #12506 from kivaisan/fix_socketaddress_regression

Fix 2 string based IP address removal regressions
pull/12610/head
Martin Kojtal 2020-03-04 07:52:31 +00:00 committed by GitHub
commit 6677249a08
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 20 deletions

View File

@ -985,7 +985,9 @@ void AT_CellularContext::cellular_callback(nsapi_event_t ev, intptr_t ptr)
#if NSAPI_PPP_AVAILABLE
if (_is_blocking) {
if (ev == NSAPI_EVENT_CONNECTION_STATUS_CHANGE && ptr == NSAPI_STATUS_GLOBAL_UP) {
tr_info("CellularContext IP %s", get_ip_address());
SocketAddress addr;
get_ip_address(&addr);
tr_info("CellularContext IP %s", addr.get_ip_address());
_cb_data.error = NSAPI_ERROR_OK;
} else if (ev == NSAPI_EVENT_CONNECTION_STATUS_CHANGE && ptr == NSAPI_STATUS_DISCONNECTED) {
tr_info("cellular_callback: PPP mode and NSAPI_STATUS_DISCONNECTED");

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;
};