diff --git a/features/cellular/framework/AT/AT_CellularContext.cpp b/features/cellular/framework/AT/AT_CellularContext.cpp index 4b48037ff1..f1b7df6ed1 100644 --- a/features/cellular/framework/AT/AT_CellularContext.cpp +++ b/features/cellular/framework/AT/AT_CellularContext.cpp @@ -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"); diff --git a/features/netsocket/L3IPInterface.cpp b/features/netsocket/L3IPInterface.cpp index 8669eba1b2..1ece6eca56 100644 --- a/features/netsocket/L3IPInterface.cpp +++ b/features/netsocket/L3IPInterface.cpp @@ -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; } diff --git a/features/netsocket/L3IPInterface.h b/features/netsocket/L3IPInterface.h index 03e0004db8..0f6968abb3 100644 --- a/features/netsocket/L3IPInterface.h +++ b/features/netsocket/L3IPInterface.h @@ -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 _connection_status_cb; };