Skip to content

Commit 6677249

Browse files
authored
Merge pull request #12506 from kivaisan/fix_socketaddress_regression
Fix 2 string based IP address removal regressions
2 parents a17866e + 86dba54 commit 6677249

File tree

3 files changed

+17
-20
lines changed

3 files changed

+17
-20
lines changed

features/cellular/framework/AT/AT_CellularContext.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -985,7 +985,9 @@ void AT_CellularContext::cellular_callback(nsapi_event_t ev, intptr_t ptr)
985985
#if NSAPI_PPP_AVAILABLE
986986
if (_is_blocking) {
987987
if (ev == NSAPI_EVENT_CONNECTION_STATUS_CHANGE && ptr == NSAPI_STATUS_GLOBAL_UP) {
988-
tr_info("CellularContext IP %s", get_ip_address());
988+
SocketAddress addr;
989+
get_ip_address(&addr);
990+
tr_info("CellularContext IP %s", addr.get_ip_address());
989991
_cb_data.error = NSAPI_ERROR_OK;
990992
} else if (ev == NSAPI_EVENT_CONNECTION_STATUS_CHANGE && ptr == NSAPI_STATUS_DISCONNECTED) {
991993
tr_info("cellular_callback: PPP mode and NSAPI_STATUS_DISCONNECTED");

features/netsocket/L3IPInterface.cpp

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,13 @@ L3IPInterface::~ L3IPInterface()
3333
_stack.remove_l3ip_interface(&_interface);
3434
}
3535

36-
nsapi_error_t L3IPInterface::set_network(const char *ip_address, const char *netmask, const char *gateway)
36+
nsapi_error_t L3IPInterface::set_network(const SocketAddress &ip_address, const SocketAddress &netmask, const SocketAddress &gateway)
3737
{
3838
_dhcp = false;
3939

40-
strncpy(_ip_address, ip_address ? ip_address : "", sizeof(_ip_address));
41-
_ip_address[sizeof(_ip_address) - 1] = '\0';
42-
strncpy(_netmask, netmask ? netmask : "", sizeof(_netmask));
43-
_netmask[sizeof(_netmask) - 1] = '\0';
44-
strncpy(_gateway, gateway ? gateway : "", sizeof(_gateway));
45-
_gateway[sizeof(_gateway) - 1] = '\0';
40+
_ip_address = ip_address;
41+
_netmask = netmask;
42+
_gateway = gateway;
4643

4744
return NSAPI_ERROR_OK;
4845
}
@@ -53,8 +50,6 @@ nsapi_error_t L3IPInterface::set_dhcp(bool dhcp)
5350
return NSAPI_ERROR_OK;
5451
}
5552

56-
57-
5853
nsapi_error_t L3IPInterface::connect()
5954
{
6055
if (!_interface) {
@@ -67,9 +62,9 @@ nsapi_error_t L3IPInterface::connect()
6762
}
6863

6964
return _interface->bringup(_dhcp,
70-
_ip_address[0] ? _ip_address : 0,
71-
_netmask[0] ? _netmask : 0,
72-
_gateway[0] ? _gateway : 0,
65+
_ip_address ? _ip_address.get_ip_address() : 0,
66+
_netmask ? _netmask.get_ip_address() : 0,
67+
_gateway ? _gateway.get_ip_address() : 0,
7368
DEFAULT_STACK,
7469
_blocking);
7570
}
@@ -85,7 +80,7 @@ nsapi_error_t L3IPInterface::disconnect()
8580
nsapi_error_t L3IPInterface::get_ip_address(SocketAddress *address)
8681
{
8782
if (_interface && _interface->get_ip_address(address) == NSAPI_ERROR_OK) {
88-
strncpy(_ip_address, address->get_ip_address(), sizeof(_ip_address));
83+
_ip_address = *address;
8984
return NSAPI_ERROR_OK;
9085
}
9186

@@ -95,7 +90,7 @@ nsapi_error_t L3IPInterface::get_ip_address(SocketAddress *address)
9590
nsapi_error_t L3IPInterface::get_netmask(SocketAddress *address)
9691
{
9792
if (_interface && _interface->get_netmask(address) == NSAPI_ERROR_OK) {
98-
strncpy(_netmask, address->get_ip_address(), sizeof(_netmask));
93+
_netmask = *address;
9994
return NSAPI_ERROR_OK;
10095
}
10196

@@ -106,7 +101,7 @@ nsapi_error_t L3IPInterface::get_gateway(SocketAddress *address)
106101
{
107102
return NSAPI_ERROR_NO_CONNECTION;
108103
if (_interface && _interface->get_gateway(address) == NSAPI_ERROR_OK) {
109-
strncpy(_gateway, address->get_ip_address(), sizeof(_gateway));
104+
_gateway = *address;
110105
return NSAPI_ERROR_OK;
111106
}
112107

features/netsocket/L3IPInterface.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#include "nsapi.h"
2222
#include "L3IP.h"
2323
#include "OnboardNetworkStack.h"
24-
24+
#include "SocketAddress.h"
2525

2626
/** L3IPInterface class
2727
* Implementation of the NetworkInterface for an IP-based driver
@@ -156,9 +156,9 @@ class L3IPInterface : public virtual NetworkInterface {
156156
OnboardNetworkStack::Interface *_interface = nullptr;
157157
bool _dhcp = true;
158158
bool _blocking = true;
159-
char _ip_address[NSAPI_IPv6_SIZE] {};
160-
char _netmask[NSAPI_IPv4_SIZE] {};
161-
char _gateway[NSAPI_IPv4_SIZE] {};
159+
SocketAddress _ip_address;
160+
SocketAddress _netmask;
161+
SocketAddress _gateway;
162162
mbed::Callback<void(nsapi_event_t, intptr_t)> _connection_status_cb;
163163
};
164164

0 commit comments

Comments
 (0)