Skip to content

Fix 2 string based IP address removal regressions #12506

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion features/cellular/framework/AT/AT_CellularContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
25 changes: 10 additions & 15 deletions features/netsocket/L3IPInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -53,8 +50,6 @@ nsapi_error_t L3IPInterface::set_dhcp(bool dhcp)
return NSAPI_ERROR_OK;
}



nsapi_error_t L3IPInterface::connect()
{
if (!_interface) {
Expand All @@ -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);
}
Expand All @@ -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;
}

Expand All @@ -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;
}

Expand All @@ -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;
}

Expand Down
8 changes: 4 additions & 4 deletions features/netsocket/L3IPInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -156,9 +156,9 @@ class L3IPInterface : public virtual NetworkInterface {
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;
};

Expand Down