Remove remaining string-based API functions

This removes any compiler warnings.
pull/11942/head
Michal Paszta 2019-12-05 19:14:30 +02:00
parent 458957d399
commit f21b8c7fc1
19 changed files with 57 additions and 222 deletions

View File

@ -104,49 +104,6 @@ nsapi_error_t AT_CellularStack::get_ip_address(SocketAddress *address)
return (ipv4 || ipv6) ? NSAPI_ERROR_OK : NSAPI_ERROR_NO_ADDRESS;
}
const char *AT_CellularStack::get_ip_address()
{
_at.lock();
bool ipv4 = false, ipv6 = false;
_at.cmd_start_stop("+CGPADDR", "=", "%d", _cid);
_at.resp_start("+CGPADDR:");
if (_at.info_resp()) {
_at.skip_param();
if (_at.read_string(_ip, PDP_IPV6_SIZE) != -1) {
convert_ipv6(_ip);
SocketAddress address;
address.set_ip_address(_ip);
ipv4 = (address.get_ip_version() == NSAPI_IPv4);
ipv6 = (address.get_ip_version() == NSAPI_IPv6);
// Try to look for second address ONLY if modem has support for dual stack(can handle both IPv4 and IPv6 simultaneously).
// Otherwise assumption is that second address is not reliable, even if network provides one.
if ((_device.get_property(AT_CellularDevice::PROPERTY_IPV4V6_PDP_TYPE) && (_at.read_string(_ip, PDP_IPV6_SIZE) != -1))) {
convert_ipv6(_ip);
address.set_ip_address(_ip);
ipv6 = (address.get_ip_version() == NSAPI_IPv6);
}
}
}
_at.resp_stop();
_at.unlock();
if (ipv4 && ipv6) {
_stack_type = IPV4V6_STACK;
} else if (ipv4) {
_stack_type = IPV4_STACK;
} else if (ipv6) {
_stack_type = IPV6_STACK;
}
return (ipv4 || ipv6) ? _ip : NULL;
}
void AT_CellularStack::set_cid(int cid)
{
_cid = cid;

View File

@ -46,9 +46,6 @@ public: // NetworkStack
virtual nsapi_error_t get_ip_address(SocketAddress *address);
MBED_DEPRECATED_SINCE("mbed-os-5.15", "String-based APIs are deprecated")
virtual const char *get_ip_address();
/**
* Set PDP context ID for this stack
*

View File

@ -398,15 +398,6 @@ void UBLOX_AT_CellularStack::clear_socket(CellularSocket *socket)
}
#ifndef UBX_MDM_SARA_R41XM
const char *UBLOX_AT_CellularStack::get_ip_address()
{
SocketAddress address;
get_ip_address(&address);
return (address.get_ip_version()) ? (address.get_ip_address()) : NULL;
}
nsapi_error_t UBLOX_AT_CellularStack::get_ip_address(SocketAddress *address)
{
if (!address) {

View File

@ -31,8 +31,6 @@ public:
virtual ~UBLOX_AT_CellularStack();
#ifndef UBX_MDM_SARA_R41XM
virtual const char *get_ip_address();
virtual nsapi_error_t get_ip_address(SocketAddress *address);
#endif

View File

@ -328,27 +328,6 @@ nsapi_error_t LWIP::Interface::get_ip_address(SocketAddress *address)
return NSAPI_ERROR_UNSUPPORTED;
}
char *LWIP::Interface::get_ip_address(char *buf, nsapi_size_t buflen)
{
const ip_addr_t *addr = LWIP::get_ip_addr(true, &netif);
if (!addr) {
return NULL;
}
#if LWIP_IPV6
if (IP_IS_V6(addr)) {
return ip6addr_ntoa_r(ip_2_ip6(addr), buf, buflen);
}
#endif
#if LWIP_IPV4
if (IP_IS_V4(addr)) {
return ip4addr_ntoa_r(ip_2_ip4(addr), buf, buflen);
}
#endif
#if LWIP_IPV6 && LWIP_IPV4
return NULL;
#endif
}
nsapi_error_t LWIP::Interface::get_netmask(SocketAddress *address)
{
if (!address) {
@ -368,20 +347,6 @@ nsapi_error_t LWIP::Interface::get_netmask(SocketAddress *address)
#endif
}
char *LWIP::Interface::get_netmask(char *buf, nsapi_size_t buflen)
{
#if LWIP_IPV4
const ip4_addr_t *addr = netif_ip4_netmask(&netif);
if (!ip4_addr_isany(addr)) {
return ip4addr_ntoa_r(addr, buf, buflen);
} else {
return NULL;
}
#else
return NULL;
#endif
}
nsapi_error_t LWIP::Interface::get_gateway(SocketAddress *address)
{
if (!address) {
@ -401,20 +366,6 @@ nsapi_error_t LWIP::Interface::get_gateway(SocketAddress *address)
#endif
}
char *LWIP::Interface::get_gateway(char *buf, nsapi_size_t buflen)
{
#if LWIP_IPV4
const ip4_addr_t *addr = netif_ip4_gw(&netif);
if (!ip4_addr_isany(addr)) {
return ip4addr_ntoa_r(addr, buf, buflen);
} else {
return NULL;
}
#else
return NULL;
#endif
}
LWIP::Interface::Interface() :
hw(NULL), has_addr_state(0),
connected(NSAPI_STATUS_DISCONNECTED),

View File

@ -96,9 +96,6 @@ public:
/** @copydoc NetworkStack::get_ip_address */
virtual nsapi_error_t get_ip_address(SocketAddress *address);
MBED_DEPRECATED_SINCE("mbed-os-5.15", "String-based APIs are deprecated")
virtual char *get_ip_address(char *buf, nsapi_size_t buflen);
/** Get the IPv6 link local address in SocketAddress representation
*
* @address SocketAddress representation of the link local IPv6 address
@ -114,9 +111,6 @@ public:
*/
virtual nsapi_error_t get_netmask(SocketAddress *address);
MBED_DEPRECATED_SINCE("mbed-os-5.15", "String-based APIs are deprecated")
virtual char *get_netmask(char *buf, nsapi_size_t buflen);
/** Copies gateway address of the network interface to user supplied buffer
*
* @param buf buffer to which gateway address will be copied as "W:X:Y:Z"
@ -125,9 +119,6 @@ public:
*/
virtual nsapi_error_t get_gateway(SocketAddress *address);
MBED_DEPRECATED_SINCE("mbed-os-5.15", "String-based APIs are deprecated")
virtual char *get_gateway(char *buf, nsapi_size_t buflen);
private:
friend class LWIP;

View File

@ -26,15 +26,9 @@
class Nanostack::Interface : public OnboardNetworkStack::Interface, private mbed::NonCopyable<Nanostack::Interface> {
public:
virtual nsapi_error_t get_ip_address(SocketAddress *address);
MBED_DEPRECATED_SINCE("mbed-os-5.15", "String-based APIs are deprecated")
virtual char *get_ip_address(char *buf, nsapi_size_t buflen);
virtual char *get_mac_address(char *buf, nsapi_size_t buflen);
virtual nsapi_error_t get_netmask(SocketAddress *address);
MBED_DEPRECATED_SINCE("mbed-os-5.15", "String-based APIs are deprecated")
virtual char *get_netmask(char *buf, nsapi_size_t buflen);
virtual nsapi_error_t get_gateway(SocketAddress *address);
MBED_DEPRECATED_SINCE("mbed-os-5.15", "String-based APIs are deprecated")
virtual char *get_gateway(char *buf, nsapi_size_t buflen);
virtual void attach(mbed::Callback<void(nsapi_event_t, intptr_t)> status_cb);
virtual nsapi_connection_status_t get_connection_status() const;
@ -108,9 +102,6 @@ public:
/** @copydoc NetworkInterface::get_ip_address */
virtual nsapi_error_t get_ip_address(SocketAddress *address);
MBED_DEPRECATED_SINCE("mbed-os-5.15", "String-based APIs are deprecated")
virtual const char *get_ip_address();
/** Get the internally stored MAC address
/return MAC address of the interface
*/

View File

@ -31,7 +31,7 @@ public:
nsapi_ip_stack_t stack = IPV6_STACK,
bool blocking = true);
virtual nsapi_error_t bringdown();
virtual char *get_gateway(char *buf, nsapi_size_t buflen);
virtual nsapi_error_t get_gateway(SocketAddress *sockAddr);
friend class Nanostack;
friend class ::LoWPANNDInterface;
@ -156,13 +156,15 @@ mesh_error_t Nanostack::LoWPANNDInterface::mesh_disconnect()
return MESH_ERROR_UNKNOWN;
}
char *Nanostack::LoWPANNDInterface::get_gateway(char *buf, nsapi_size_t buflen)
nsapi_error_t Nanostack::LoWPANNDInterface::get_gateway(SocketAddress *sockAddr)
{
NanostackLockGuard lock;
if (nd_tasklet_get_router_ip_address(buf, buflen) == 0) {
return buf;
char buf[NSAPI_IPv6_SIZE];
if (nd_tasklet_get_router_ip_address(buf, NSAPI_IPv6_SIZE) == 0) {
sockAddr->set_ip_address(buf);
return NSAPI_ERROR_OK;
}
return NULL;
return NSAPI_ERROR_NO_ADDRESS;
}
bool LoWPANNDInterface::getRouterIpAddress(char *address, int8_t len)

View File

@ -36,19 +36,6 @@ nsapi_error_t Nanostack::Interface::get_ip_address(SocketAddress *address)
}
}
char *Nanostack::Interface::get_ip_address(char *buf, nsapi_size_t buflen)
{
NanostackLockGuard lock;
uint8_t binary_ipv6[16];
if (buflen >= 40 && arm_net_address_get(interface_id, ADDR_IPV6_GP, binary_ipv6) == 0) {
ip6tos(binary_ipv6, buf);
return buf;
} else {
return NULL;
}
}
char *Nanostack::Interface::get_mac_address(char *buf, nsapi_size_t buflen)
{
NanostackLockGuard lock;
@ -71,16 +58,6 @@ nsapi_error_t Nanostack::Interface::get_gateway(SocketAddress *address)
return NSAPI_ERROR_UNSUPPORTED;
}
char *Nanostack::Interface::get_netmask(char *, nsapi_size_t)
{
return NULL;
}
char *Nanostack::Interface::get_gateway(char *, nsapi_size_t)
{
return NULL;
}
nsapi_connection_status_t Nanostack::Interface::get_connection_status() const
{
return _connect_status;
@ -210,14 +187,6 @@ nsapi_error_t InterfaceNanostack::get_ip_address(SocketAddress *address)
return NSAPI_ERROR_NO_ADDRESS;
}
const char *InterfaceNanostack::get_ip_address()
{
if (_interface->get_ip_address(&ip_addr) == NSAPI_ERROR_OK) {
return ip_addr.get_ip_address();
}
return NULL;
}
const char *InterfaceNanostack::get_mac_address()
{
if (_interface->get_mac_address(mac_addr_str, sizeof(mac_addr_str))) {

View File

@ -32,7 +32,7 @@ public:
nsapi_ip_stack_t stack = IPV6_STACK,
bool blocking = true);
virtual nsapi_error_t bringdown();
virtual char *get_gateway(char *buf, nsapi_size_t buflen);
virtual nsapi_error_t get_gateway(SocketAddress *address);
friend class Nanostack;
friend class ::WisunInterface;
@ -157,13 +157,15 @@ mesh_error_t Nanostack::WisunInterface::mesh_disconnect()
return MESH_ERROR_UNKNOWN;
}
char *Nanostack::WisunInterface::get_gateway(char *buf, nsapi_size_t buflen)
nsapi_error_t Nanostack::WisunInterface::get_gateway(SocketAddress *addr)
{
NanostackLockGuard lock;
if (wisun_tasklet_get_router_ip_address(buf, buflen) == 0) {
return buf;
char buf[NSAPI_IPv6_SIZE];
if (wisun_tasklet_get_router_ip_address(buf, NSAPI_IPv6_SIZE) == 0) {
addr->set_ip_address(buf);
return NSAPI_ERROR_OK;
}
return NULL;
return NSAPI_ERROR_NO_ADDRESS;
}
bool WisunInterface::getRouterIpAddress(char *address, int8_t len)

View File

@ -516,21 +516,20 @@ Nanostack::call_in_callback_cb_t Nanostack::get_call_in_callback()
return cb;
}
const char *Nanostack::get_ip_address()
nsapi_error_t Nanostack::get_ip_address(SocketAddress *sockAddr)
{
NanostackLockGuard lock;
for (int if_id = 1; if_id <= 127; if_id++) {
uint8_t address[16];
uint8_t address[NSAPI_IP_BYTES];
int ret = arm_net_address_get(if_id, ADDR_IPV6_GP, address);
if (ret == 0) {
sockAddr->set_ip_bytes(address, NSAPI_IPv6);
ip6tos(address, text_ip_address);
return text_ip_address;
return NSAPI_ERROR_OK;
}
}
// Must result a valid IPv6 address
// For gethostbyname() to detect IP version.
return "::";
return NSAPI_ERROR_NO_ADDRESS;
}
nsapi_error_t Nanostack::socket_open(void **handle, nsapi_protocol_t protocol)

View File

@ -56,12 +56,8 @@ protected:
Nanostack();
/** Get the local IP address
*
* @return Null-terminated representation of the local IP address
* or null if not yet connected
*/
virtual const char *get_ip_address();
/** @copydoc NetworkStack::get_ip_address */
virtual nsapi_error_t get_ip_address(SocketAddress *sockAddr);
/** Opens a socket
*

View File

@ -119,7 +119,6 @@ nsapi_error_t EMACInterface::get_gateway(SocketAddress *address)
{
if (_interface && _interface->get_gateway(address) == NSAPI_ERROR_OK) {
strncpy(_gateway, address->get_ip_address(), sizeof(_gateway));
address->set_ip_address(_gateway);
return NSAPI_ERROR_OK;
}

View File

@ -59,9 +59,9 @@ public:
* Implicitly disables DHCP, which can be enabled in set_dhcp.
* Requires that the network is disconnected.
*
* @param ip_address Null-terminated representation of the local IP address
* @param netmask Null-terminated representation of the local network mask
* @param gateway Null-terminated representation of the local gateway
* @param ip_address SocketAddress representation of the local IP address
* @param netmask SocketAddress representation of the local network mask
* @param gateway SocketAddress representation of the local gateway
* @return 0 on success, negative error code on failure
*/
virtual nsapi_error_t set_network(const SocketAddress &ip_address, const SocketAddress &netmask, const SocketAddress &gateway);

View File

@ -88,31 +88,35 @@ nsapi_error_t L3IPInterface::disconnect()
return NSAPI_ERROR_NO_CONNECTION;
}
const char *L3IPInterface::get_ip_address()
nsapi_error_t L3IPInterface::get_ip_address(SocketAddress *address)
{
if (_interface && _interface->get_ip_address(_ip_address, sizeof(_ip_address))) {
return _ip_address;
if (_interface && _interface->get_ip_address(address) == NSAPI_ERROR_OK) {
strncpy(_ip_address, address->get_ip_address(), sizeof(_ip_address));
return NSAPI_ERROR_OK;
}
return NULL;
return NSAPI_ERROR_NO_CONNECTION;
}
const char *L3IPInterface::get_netmask()
nsapi_error_t L3IPInterface::get_netmask(SocketAddress *address)
{
if (_interface && _interface->get_netmask(_netmask, sizeof(_netmask))) {
return _netmask;
if (_interface && _interface->get_netmask(address) == NSAPI_ERROR_OK) {
strncpy(_netmask, address->get_ip_address(), sizeof(_netmask));
return NSAPI_ERROR_OK;
}
return 0;
return NSAPI_ERROR_NO_ADDRESS;
}
const char *L3IPInterface::get_gateway()
nsapi_error_t L3IPInterface::get_gateway(SocketAddress *address)
{
if (_interface && _interface->get_gateway(_gateway, sizeof(_gateway))) {
return _gateway;
return NSAPI_ERROR_NO_CONNECTION;
if (_interface && _interface->get_gateway(address) == NSAPI_ERROR_OK) {
strncpy(_gateway, address->get_ip_address(), sizeof(_gateway));
return NSAPI_ERROR_OK;
}
return 0;
return NSAPI_ERROR_NO_ADDRESS;
}
char *L3IPInterface::get_interface_name(char *interface_name)

View File

@ -56,12 +56,12 @@ public:
* Implicitly disables DHCP, which can be enabled in set_dhcp.
* Requires that the network is disconnected.
*
* @param ip_address Null-terminated representation of the local IP address
* @param netmask Null-terminated representation of the local network mask
* @param gateway Null-terminated representation of the local gateway
* @param ip_address SocketAddress representation of the local IP address
* @param netmask SocketAddress representation of the local network mask
* @param gateway SocketAddress representation of the local gateway
* @return 0 on success, negative error code on failure
*/
virtual nsapi_error_t set_network(const char *ip_address, const char *netmask, const char *gateway);
virtual nsapi_error_t set_network(const SocketAddress &ip_address, const SocketAddress &netmask, const SocketAddress &gateway);
/** Enable or disable DHCP on the network
*
@ -82,26 +82,14 @@ public:
*/
virtual nsapi_error_t disconnect();
/** Get the local IP address
*
* @return Null-terminated representation of the local IP address
* or null if no IP address has been received
*/
virtual const char *get_ip_address();
/** @copydoc NetworkInterface::get_ip_address */
virtual nsapi_error_t get_ip_address(SocketAddress *address);
/** Get the local network mask
*
* @return Null-terminated representation of the local network mask
* or null if no network mask has been received
*/
virtual const char *get_netmask();
/** @copydoc NetworkInterface::get_netmask */
virtual nsapi_error_t get_netmask(SocketAddress *address);
/** Get the local gateways
*
* @return Null-terminated representation of the local gateway
* or null if no network mask has been received
*/
virtual const char *get_gateway();
/** @copydoc NetworkInterface::get_gateway */
virtual nsapi_error_t get_gateway(SocketAddress *address);
/** Get the network interface name
*

View File

@ -77,7 +77,7 @@ nsapi_value_or_error_t NetworkStack::getaddrinfo(const char *hostname, SocketAdd
// ip address of the underlying stack
if (version == NSAPI_UNSPEC) {
SocketAddress testaddress;
if (testaddress.set_ip_address(this->get_ip_address())) {
if (this->get_ip_address(&testaddress) == NSAPI_ERROR_OK) {
version = testaddress.get_ip_version();
}
}
@ -144,7 +144,7 @@ nsapi_value_or_error_t NetworkStack::getaddrinfo_async(const char *hostname, Soc
// ip address of the underlying stack
if (version == NSAPI_UNSPEC) {
SocketAddress testaddress;
if (testaddress.set_ip_address(this->get_ip_address())) {
if (this->get_ip_address(&testaddress) == NSAPI_ERROR_OK) {
version = testaddress.get_ip_version();
}
}

View File

@ -40,13 +40,13 @@ PPPInterface::~PPPInterface()
_stack.remove_ppp_interface(&_interface);
}
nsapi_error_t PPPInterface::set_network(const char *ip_address, const char *netmask, const char *gateway)
nsapi_error_t PPPInterface::set_network(const SocketAddress &ip_address, const SocketAddress &netmask, const SocketAddress &gateway)
{
strncpy(_ip_address, ip_address ? ip_address : "", sizeof(_ip_address));
strncpy(_ip_address, ip_address.get_ip_address() ? ip_address.get_ip_address() : "", sizeof(_ip_address));
_ip_address[sizeof(_ip_address) - 1] = '\0';
strncpy(_netmask, netmask ? netmask : "", sizeof(_netmask));
strncpy(_netmask, netmask.get_ip_address() ? netmask.get_ip_address() : "", sizeof(_netmask));
_netmask[sizeof(_netmask) - 1] = '\0';
strncpy(_gateway, gateway ? gateway : "", sizeof(_gateway));
strncpy(_gateway, gateway.get_ip_address() ? gateway.get_ip_address() : "", sizeof(_gateway));
_gateway[sizeof(_gateway) - 1] = '\0';
return NSAPI_ERROR_OK;

View File

@ -51,7 +51,7 @@ public:
virtual ~PPPInterface();
/** @copydoc NetworkInterface::set_network */
virtual nsapi_error_t set_network(const char *ip_address, const char *netmask, const char *gateway);
virtual nsapi_error_t set_network(const SocketAddress &ip_address, const SocketAddress &netmask, const SocketAddress &gateway);
/** @copydoc NetworkInterface::connect */
virtual nsapi_error_t connect();