Skip to content

Commit f21b8c7

Browse files
Remove remaining string-based API functions
This removes any compiler warnings.
1 parent 458957d commit f21b8c7

19 files changed

+57
-222
lines changed

features/cellular/framework/AT/AT_CellularStack.cpp

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -104,49 +104,6 @@ nsapi_error_t AT_CellularStack::get_ip_address(SocketAddress *address)
104104
return (ipv4 || ipv6) ? NSAPI_ERROR_OK : NSAPI_ERROR_NO_ADDRESS;
105105
}
106106

107-
const char *AT_CellularStack::get_ip_address()
108-
{
109-
_at.lock();
110-
111-
bool ipv4 = false, ipv6 = false;
112-
113-
_at.cmd_start_stop("+CGPADDR", "=", "%d", _cid);
114-
_at.resp_start("+CGPADDR:");
115-
116-
if (_at.info_resp()) {
117-
_at.skip_param();
118-
119-
if (_at.read_string(_ip, PDP_IPV6_SIZE) != -1) {
120-
convert_ipv6(_ip);
121-
SocketAddress address;
122-
address.set_ip_address(_ip);
123-
124-
ipv4 = (address.get_ip_version() == NSAPI_IPv4);
125-
ipv6 = (address.get_ip_version() == NSAPI_IPv6);
126-
127-
// Try to look for second address ONLY if modem has support for dual stack(can handle both IPv4 and IPv6 simultaneously).
128-
// Otherwise assumption is that second address is not reliable, even if network provides one.
129-
if ((_device.get_property(AT_CellularDevice::PROPERTY_IPV4V6_PDP_TYPE) && (_at.read_string(_ip, PDP_IPV6_SIZE) != -1))) {
130-
convert_ipv6(_ip);
131-
address.set_ip_address(_ip);
132-
ipv6 = (address.get_ip_version() == NSAPI_IPv6);
133-
}
134-
}
135-
}
136-
_at.resp_stop();
137-
_at.unlock();
138-
139-
if (ipv4 && ipv6) {
140-
_stack_type = IPV4V6_STACK;
141-
} else if (ipv4) {
142-
_stack_type = IPV4_STACK;
143-
} else if (ipv6) {
144-
_stack_type = IPV6_STACK;
145-
}
146-
147-
return (ipv4 || ipv6) ? _ip : NULL;
148-
}
149-
150107
void AT_CellularStack::set_cid(int cid)
151108
{
152109
_cid = cid;

features/cellular/framework/AT/AT_CellularStack.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,6 @@ class AT_CellularStack : public NetworkStack {
4646

4747
virtual nsapi_error_t get_ip_address(SocketAddress *address);
4848

49-
MBED_DEPRECATED_SINCE("mbed-os-5.15", "String-based APIs are deprecated")
50-
virtual const char *get_ip_address();
51-
5249
/**
5350
* Set PDP context ID for this stack
5451
*

features/cellular/framework/targets/UBLOX/AT/UBLOX_AT_CellularStack.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -398,15 +398,6 @@ void UBLOX_AT_CellularStack::clear_socket(CellularSocket *socket)
398398
}
399399

400400
#ifndef UBX_MDM_SARA_R41XM
401-
const char *UBLOX_AT_CellularStack::get_ip_address()
402-
{
403-
SocketAddress address;
404-
405-
get_ip_address(&address);
406-
407-
return (address.get_ip_version()) ? (address.get_ip_address()) : NULL;
408-
}
409-
410401
nsapi_error_t UBLOX_AT_CellularStack::get_ip_address(SocketAddress *address)
411402
{
412403
if (!address) {

features/cellular/framework/targets/UBLOX/AT/UBLOX_AT_CellularStack.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ class UBLOX_AT_CellularStack : public AT_CellularStack {
3131
virtual ~UBLOX_AT_CellularStack();
3232

3333
#ifndef UBX_MDM_SARA_R41XM
34-
virtual const char *get_ip_address();
35-
3634
virtual nsapi_error_t get_ip_address(SocketAddress *address);
3735
#endif
3836

features/lwipstack/LWIPInterface.cpp

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -328,27 +328,6 @@ nsapi_error_t LWIP::Interface::get_ip_address(SocketAddress *address)
328328
return NSAPI_ERROR_UNSUPPORTED;
329329
}
330330

331-
char *LWIP::Interface::get_ip_address(char *buf, nsapi_size_t buflen)
332-
{
333-
const ip_addr_t *addr = LWIP::get_ip_addr(true, &netif);
334-
if (!addr) {
335-
return NULL;
336-
}
337-
#if LWIP_IPV6
338-
if (IP_IS_V6(addr)) {
339-
return ip6addr_ntoa_r(ip_2_ip6(addr), buf, buflen);
340-
}
341-
#endif
342-
#if LWIP_IPV4
343-
if (IP_IS_V4(addr)) {
344-
return ip4addr_ntoa_r(ip_2_ip4(addr), buf, buflen);
345-
}
346-
#endif
347-
#if LWIP_IPV6 && LWIP_IPV4
348-
return NULL;
349-
#endif
350-
}
351-
352331
nsapi_error_t LWIP::Interface::get_netmask(SocketAddress *address)
353332
{
354333
if (!address) {
@@ -368,20 +347,6 @@ nsapi_error_t LWIP::Interface::get_netmask(SocketAddress *address)
368347
#endif
369348
}
370349

371-
char *LWIP::Interface::get_netmask(char *buf, nsapi_size_t buflen)
372-
{
373-
#if LWIP_IPV4
374-
const ip4_addr_t *addr = netif_ip4_netmask(&netif);
375-
if (!ip4_addr_isany(addr)) {
376-
return ip4addr_ntoa_r(addr, buf, buflen);
377-
} else {
378-
return NULL;
379-
}
380-
#else
381-
return NULL;
382-
#endif
383-
}
384-
385350
nsapi_error_t LWIP::Interface::get_gateway(SocketAddress *address)
386351
{
387352
if (!address) {
@@ -401,20 +366,6 @@ nsapi_error_t LWIP::Interface::get_gateway(SocketAddress *address)
401366
#endif
402367
}
403368

404-
char *LWIP::Interface::get_gateway(char *buf, nsapi_size_t buflen)
405-
{
406-
#if LWIP_IPV4
407-
const ip4_addr_t *addr = netif_ip4_gw(&netif);
408-
if (!ip4_addr_isany(addr)) {
409-
return ip4addr_ntoa_r(addr, buf, buflen);
410-
} else {
411-
return NULL;
412-
}
413-
#else
414-
return NULL;
415-
#endif
416-
}
417-
418369
LWIP::Interface::Interface() :
419370
hw(NULL), has_addr_state(0),
420371
connected(NSAPI_STATUS_DISCONNECTED),

features/lwipstack/LWIPStack.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,6 @@ class LWIP : public OnboardNetworkStack, private mbed::NonCopyable<LWIP> {
9696
/** @copydoc NetworkStack::get_ip_address */
9797
virtual nsapi_error_t get_ip_address(SocketAddress *address);
9898

99-
MBED_DEPRECATED_SINCE("mbed-os-5.15", "String-based APIs are deprecated")
100-
virtual char *get_ip_address(char *buf, nsapi_size_t buflen);
101-
10299
/** Get the IPv6 link local address in SocketAddress representation
103100
*
104101
* @address SocketAddress representation of the link local IPv6 address
@@ -114,9 +111,6 @@ class LWIP : public OnboardNetworkStack, private mbed::NonCopyable<LWIP> {
114111
*/
115112
virtual nsapi_error_t get_netmask(SocketAddress *address);
116113

117-
MBED_DEPRECATED_SINCE("mbed-os-5.15", "String-based APIs are deprecated")
118-
virtual char *get_netmask(char *buf, nsapi_size_t buflen);
119-
120114
/** Copies gateway address of the network interface to user supplied buffer
121115
*
122116
* @param buf buffer to which gateway address will be copied as "W:X:Y:Z"
@@ -125,9 +119,6 @@ class LWIP : public OnboardNetworkStack, private mbed::NonCopyable<LWIP> {
125119
*/
126120
virtual nsapi_error_t get_gateway(SocketAddress *address);
127121

128-
MBED_DEPRECATED_SINCE("mbed-os-5.15", "String-based APIs are deprecated")
129-
virtual char *get_gateway(char *buf, nsapi_size_t buflen);
130-
131122
private:
132123
friend class LWIP;
133124

features/nanostack/mbed-mesh-api/mbed-mesh-api/MeshInterfaceNanostack.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,9 @@
2626
class Nanostack::Interface : public OnboardNetworkStack::Interface, private mbed::NonCopyable<Nanostack::Interface> {
2727
public:
2828
virtual nsapi_error_t get_ip_address(SocketAddress *address);
29-
MBED_DEPRECATED_SINCE("mbed-os-5.15", "String-based APIs are deprecated")
30-
virtual char *get_ip_address(char *buf, nsapi_size_t buflen);
3129
virtual char *get_mac_address(char *buf, nsapi_size_t buflen);
3230
virtual nsapi_error_t get_netmask(SocketAddress *address);
33-
MBED_DEPRECATED_SINCE("mbed-os-5.15", "String-based APIs are deprecated")
34-
virtual char *get_netmask(char *buf, nsapi_size_t buflen);
3531
virtual nsapi_error_t get_gateway(SocketAddress *address);
36-
MBED_DEPRECATED_SINCE("mbed-os-5.15", "String-based APIs are deprecated")
37-
virtual char *get_gateway(char *buf, nsapi_size_t buflen);
3832
virtual void attach(mbed::Callback<void(nsapi_event_t, intptr_t)> status_cb);
3933
virtual nsapi_connection_status_t get_connection_status() const;
4034

@@ -108,9 +102,6 @@ class InterfaceNanostack : public virtual NetworkInterface {
108102
/** @copydoc NetworkInterface::get_ip_address */
109103
virtual nsapi_error_t get_ip_address(SocketAddress *address);
110104

111-
MBED_DEPRECATED_SINCE("mbed-os-5.15", "String-based APIs are deprecated")
112-
virtual const char *get_ip_address();
113-
114105
/** Get the internally stored MAC address
115106
/return MAC address of the interface
116107
*/

features/nanostack/mbed-mesh-api/source/LoWPANNDInterface.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class Nanostack::LoWPANNDInterface : public Nanostack::MeshInterface {
3131
nsapi_ip_stack_t stack = IPV6_STACK,
3232
bool blocking = true);
3333
virtual nsapi_error_t bringdown();
34-
virtual char *get_gateway(char *buf, nsapi_size_t buflen);
34+
virtual nsapi_error_t get_gateway(SocketAddress *sockAddr);
3535

3636
friend class Nanostack;
3737
friend class ::LoWPANNDInterface;
@@ -156,13 +156,15 @@ mesh_error_t Nanostack::LoWPANNDInterface::mesh_disconnect()
156156
return MESH_ERROR_UNKNOWN;
157157
}
158158

159-
char *Nanostack::LoWPANNDInterface::get_gateway(char *buf, nsapi_size_t buflen)
159+
nsapi_error_t Nanostack::LoWPANNDInterface::get_gateway(SocketAddress *sockAddr)
160160
{
161161
NanostackLockGuard lock;
162-
if (nd_tasklet_get_router_ip_address(buf, buflen) == 0) {
163-
return buf;
162+
char buf[NSAPI_IPv6_SIZE];
163+
if (nd_tasklet_get_router_ip_address(buf, NSAPI_IPv6_SIZE) == 0) {
164+
sockAddr->set_ip_address(buf);
165+
return NSAPI_ERROR_OK;
164166
}
165-
return NULL;
167+
return NSAPI_ERROR_NO_ADDRESS;
166168
}
167169

168170
bool LoWPANNDInterface::getRouterIpAddress(char *address, int8_t len)

features/nanostack/mbed-mesh-api/source/MeshInterfaceNanostack.cpp

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -36,19 +36,6 @@ nsapi_error_t Nanostack::Interface::get_ip_address(SocketAddress *address)
3636
}
3737
}
3838

39-
char *Nanostack::Interface::get_ip_address(char *buf, nsapi_size_t buflen)
40-
{
41-
NanostackLockGuard lock;
42-
uint8_t binary_ipv6[16];
43-
44-
if (buflen >= 40 && arm_net_address_get(interface_id, ADDR_IPV6_GP, binary_ipv6) == 0) {
45-
ip6tos(binary_ipv6, buf);
46-
return buf;
47-
} else {
48-
return NULL;
49-
}
50-
}
51-
5239
char *Nanostack::Interface::get_mac_address(char *buf, nsapi_size_t buflen)
5340
{
5441
NanostackLockGuard lock;
@@ -71,16 +58,6 @@ nsapi_error_t Nanostack::Interface::get_gateway(SocketAddress *address)
7158
return NSAPI_ERROR_UNSUPPORTED;
7259
}
7360

74-
char *Nanostack::Interface::get_netmask(char *, nsapi_size_t)
75-
{
76-
return NULL;
77-
}
78-
79-
char *Nanostack::Interface::get_gateway(char *, nsapi_size_t)
80-
{
81-
return NULL;
82-
}
83-
8461
nsapi_connection_status_t Nanostack::Interface::get_connection_status() const
8562
{
8663
return _connect_status;
@@ -210,14 +187,6 @@ nsapi_error_t InterfaceNanostack::get_ip_address(SocketAddress *address)
210187
return NSAPI_ERROR_NO_ADDRESS;
211188
}
212189

213-
const char *InterfaceNanostack::get_ip_address()
214-
{
215-
if (_interface->get_ip_address(&ip_addr) == NSAPI_ERROR_OK) {
216-
return ip_addr.get_ip_address();
217-
}
218-
return NULL;
219-
}
220-
221190
const char *InterfaceNanostack::get_mac_address()
222191
{
223192
if (_interface->get_mac_address(mac_addr_str, sizeof(mac_addr_str))) {

features/nanostack/mbed-mesh-api/source/WisunInterface.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class Nanostack::WisunInterface : public Nanostack::MeshInterface {
3232
nsapi_ip_stack_t stack = IPV6_STACK,
3333
bool blocking = true);
3434
virtual nsapi_error_t bringdown();
35-
virtual char *get_gateway(char *buf, nsapi_size_t buflen);
35+
virtual nsapi_error_t get_gateway(SocketAddress *address);
3636

3737
friend class Nanostack;
3838
friend class ::WisunInterface;
@@ -157,13 +157,15 @@ mesh_error_t Nanostack::WisunInterface::mesh_disconnect()
157157
return MESH_ERROR_UNKNOWN;
158158
}
159159

160-
char *Nanostack::WisunInterface::get_gateway(char *buf, nsapi_size_t buflen)
160+
nsapi_error_t Nanostack::WisunInterface::get_gateway(SocketAddress *addr)
161161
{
162162
NanostackLockGuard lock;
163-
if (wisun_tasklet_get_router_ip_address(buf, buflen) == 0) {
164-
return buf;
163+
char buf[NSAPI_IPv6_SIZE];
164+
if (wisun_tasklet_get_router_ip_address(buf, NSAPI_IPv6_SIZE) == 0) {
165+
addr->set_ip_address(buf);
166+
return NSAPI_ERROR_OK;
165167
}
166-
return NULL;
168+
return NSAPI_ERROR_NO_ADDRESS;
167169
}
168170

169171
bool WisunInterface::getRouterIpAddress(char *address, int8_t len)

features/nanostack/nanostack-interface/Nanostack.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -516,21 +516,20 @@ Nanostack::call_in_callback_cb_t Nanostack::get_call_in_callback()
516516
return cb;
517517
}
518518

519-
const char *Nanostack::get_ip_address()
519+
nsapi_error_t Nanostack::get_ip_address(SocketAddress *sockAddr)
520520
{
521521
NanostackLockGuard lock;
522522

523523
for (int if_id = 1; if_id <= 127; if_id++) {
524-
uint8_t address[16];
524+
uint8_t address[NSAPI_IP_BYTES];
525525
int ret = arm_net_address_get(if_id, ADDR_IPV6_GP, address);
526526
if (ret == 0) {
527+
sockAddr->set_ip_bytes(address, NSAPI_IPv6);
527528
ip6tos(address, text_ip_address);
528-
return text_ip_address;
529+
return NSAPI_ERROR_OK;
529530
}
530531
}
531-
// Must result a valid IPv6 address
532-
// For gethostbyname() to detect IP version.
533-
return "::";
532+
return NSAPI_ERROR_NO_ADDRESS;
534533
}
535534

536535
nsapi_error_t Nanostack::socket_open(void **handle, nsapi_protocol_t protocol)

features/nanostack/nanostack-interface/Nanostack.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,8 @@ class Nanostack : public OnboardNetworkStack, private mbed::NonCopyable<Nanostac
5656

5757
Nanostack();
5858

59-
/** Get the local IP address
60-
*
61-
* @return Null-terminated representation of the local IP address
62-
* or null if not yet connected
63-
*/
64-
virtual const char *get_ip_address();
59+
/** @copydoc NetworkStack::get_ip_address */
60+
virtual nsapi_error_t get_ip_address(SocketAddress *sockAddr);
6561

6662
/** Opens a socket
6763
*

features/netsocket/EMACInterface.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@ nsapi_error_t EMACInterface::get_gateway(SocketAddress *address)
119119
{
120120
if (_interface && _interface->get_gateway(address) == NSAPI_ERROR_OK) {
121121
strncpy(_gateway, address->get_ip_address(), sizeof(_gateway));
122-
address->set_ip_address(_gateway);
123122
return NSAPI_ERROR_OK;
124123
}
125124

features/netsocket/EMACInterface.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ class EMACInterface : public virtual NetworkInterface {
5959
* Implicitly disables DHCP, which can be enabled in set_dhcp.
6060
* Requires that the network is disconnected.
6161
*
62-
* @param ip_address Null-terminated representation of the local IP address
63-
* @param netmask Null-terminated representation of the local network mask
64-
* @param gateway Null-terminated representation of the local gateway
62+
* @param ip_address SocketAddress representation of the local IP address
63+
* @param netmask SocketAddress representation of the local network mask
64+
* @param gateway SocketAddress representation of the local gateway
6565
* @return 0 on success, negative error code on failure
6666
*/
6767
virtual nsapi_error_t set_network(const SocketAddress &ip_address, const SocketAddress &netmask, const SocketAddress &gateway);

0 commit comments

Comments
 (0)