Merge pull request #11942 from michalpasztamobica/remove_deprecated_apis

IPCore String-based API removal
pull/12488/head
Martin Kojtal 2020-02-21 12:14:06 +00:00 committed by GitHub
commit 8f1bf967d3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
60 changed files with 98 additions and 664 deletions

View File

@ -178,17 +178,21 @@ TEST_F(TestPPPInterface, disconnect)
TEST_F(TestPPPInterface, set_network)
{
char ipAddress[NSAPI_IPv4_SIZE] = "127.0.0.1";
char netmask[NSAPI_IPv4_SIZE] = "255.255.0.0";
char gateway[NSAPI_IPv4_SIZE] = "127.0.0.2";
SocketAddress ipAddress("127.0.0.1");
SocketAddress netmask("255.255.0.0");
SocketAddress gateway("127.0.0.2");
const char *ipAddressArg;
const char *netmaskArg;
const char *gatewayArg;
EXPECT_EQ(0, iface->get_ip_address());
EXPECT_EQ(0, iface->get_netmask());
EXPECT_EQ(0, iface->get_gateway());
SocketAddress ipAddr;
SocketAddress netmaskAddr;
SocketAddress gatewayAddr;
EXPECT_EQ(NSAPI_ERROR_NO_CONNECTION, iface->get_ip_address(&ipAddr));
EXPECT_EQ(NSAPI_ERROR_NO_CONNECTION, iface->get_netmask(&netmaskAddr));
EXPECT_EQ(NSAPI_ERROR_NO_CONNECTION, iface->get_gateway(&gatewayAddr));
EXPECT_CALL(*pppMock, set_stream(_));
EXPECT_CALL(*pppMock, set_ip_stack(_));
@ -213,25 +217,28 @@ TEST_F(TestPPPInterface, set_network)
Return(NSAPI_ERROR_OK)));
EXPECT_EQ(NSAPI_ERROR_OK, iface->connect());
// Check the contents of the stored pointer arguments.
EXPECT_TRUE(0 == strcmp(ipAddress, ipAddressArg));
EXPECT_TRUE(0 == strcmp(netmask, netmaskArg));
EXPECT_TRUE(0 == strcmp(gateway, gatewayArg));
EXPECT_TRUE(0 == strcmp(ipAddress.get_ip_address(), ipAddressArg));
EXPECT_TRUE(0 == strcmp(netmask.get_ip_address(), netmaskArg));
EXPECT_TRUE(0 == strcmp(gateway.get_ip_address(), gatewayArg));
// Testing the getters makes sense now.
EXPECT_CALL(*netStackIface, get_ip_address(_, _))
EXPECT_CALL(*netStackIface, get_ip_address(_))
.Times(1)
.WillOnce(DoAll(SetArgPointee<0>(*ipAddress), Return(ipAddress)));
EXPECT_EQ(std::string(ipAddress), std::string(iface->get_ip_address()));
.WillOnce(DoAll(SetArgPointee<0>(ipAddress), Return(NSAPI_ERROR_OK)));
EXPECT_EQ(NSAPI_ERROR_OK, iface->get_ip_address(&ipAddr));
EXPECT_EQ(ipAddress, ipAddr);
EXPECT_CALL(*netStackIface, get_netmask(_, _))
EXPECT_CALL(*netStackIface, get_netmask(_))
.Times(1)
.WillOnce(DoAll(SetArgPointee<0>(*netmask), Return(netmask)));
EXPECT_EQ(std::string(netmask), std::string(iface->get_netmask()));
.WillOnce(DoAll(SetArgPointee<0>(netmask), Return(NSAPI_ERROR_OK)));
EXPECT_EQ(NSAPI_ERROR_OK, iface->get_netmask(&netmaskAddr));
EXPECT_EQ(netmask, netmaskAddr);
EXPECT_CALL(*netStackIface, get_gateway(_, _))
EXPECT_CALL(*netStackIface, get_gateway(_))
.Times(1)
.WillOnce(DoAll(SetArgPointee<0>(*gateway), Return(gateway)));
EXPECT_EQ(std::string(gateway), std::string(iface->get_gateway()));
.WillOnce(DoAll(SetArgPointee<0>(gateway), Return(NSAPI_ERROR_OK)));
EXPECT_EQ(NSAPI_ERROR_OK, iface->get_gateway(&gatewayAddr));
EXPECT_EQ(gateway, gatewayAddr);
}
TEST_F(TestPPPInterface, get_connection_status)

View File

@ -32,8 +32,6 @@ set(unittest-test-sources
stubs/mbed_shared_queues_stub.cpp
stubs/nsapi_dns_stub.cpp
stubs/EventFlags_stub.cpp
stubs/stoip4_stub.c
stubs/ip4tos_stub.c
stubs/NetworkStack_stub.cpp
stubs/NetworkInterfaceDefaults_stub.cpp
stubs/SocketStats_Stub.cpp

View File

@ -114,11 +114,6 @@ nsapi_error_t AT_CellularContext::get_ip_address(SocketAddress *address)
return NSAPI_ERROR_UNSUPPORTED;
}
const char *AT_CellularContext::get_ip_address()
{
return NULL;
}
void AT_CellularContext::attach(Callback<void(nsapi_event_t, intptr_t)> status_cb)
{
}

View File

@ -36,11 +36,6 @@ nsapi_error_t AT_CellularStack::get_ip_address(SocketAddress* address)
return NSAPI_ERROR_UNSUPPORTED;
}
const char *AT_CellularStack::get_ip_address()
{
return NULL;
}
nsapi_error_t AT_CellularStack::socket_open(nsapi_socket_t *handle, nsapi_protocol_t proto)
{
return NSAPI_ERROR_OK;

View File

@ -31,10 +31,6 @@ nsapi_error_t NetworkInterface::get_ip_address(SocketAddress *)
return NSAPI_ERROR_UNSUPPORTED;
}
const char *NetworkInterface::get_ip_address()
{
return nullptr;
}
nsapi_error_t NetworkInterface::get_ipv6_link_local_address(SocketAddress *address)
{
return NSAPI_ERROR_UNSUPPORTED;
@ -45,31 +41,16 @@ nsapi_error_t NetworkInterface::get_netmask(SocketAddress *)
return NSAPI_ERROR_UNSUPPORTED;
}
const char *NetworkInterface::get_netmask()
{
return nullptr;
}
nsapi_error_t NetworkInterface::get_gateway(SocketAddress *)
{
return NSAPI_ERROR_UNSUPPORTED;
}
const char *NetworkInterface::get_gateway()
{
return nullptr;
}
nsapi_error_t NetworkInterface::set_network(const SocketAddress &ip_address, const SocketAddress &netmask, const SocketAddress &gateway)
{
return NSAPI_ERROR_UNSUPPORTED;
}
nsapi_error_t NetworkInterface::set_network(const char *ip_address, const char *netmask, const char *gateway)
{
return NSAPI_ERROR_UNSUPPORTED;
}
nsapi_error_t NetworkInterface::set_dhcp(bool dhcp)
{
return NSAPI_ERROR_UNSUPPORTED;

View File

@ -104,11 +104,6 @@ nsapi_error_t NetworkStack::get_ip_address(SocketAddress* address)
return NSAPI_ERROR_UNSUPPORTED;
}
const char *NetworkStack::get_ip_address()
{
return NULL;
}
nsapi_error_t NetworkStack::get_ipv6_link_local_address(SocketAddress *address)
{
return NSAPI_ERROR_UNSUPPORTED;
@ -118,8 +113,3 @@ nsapi_error_t NetworkStack::get_ip_address_if(SocketAddress* address, const char
{
return NSAPI_ERROR_UNSUPPORTED;
}
const char *NetworkStack::get_ip_address_if(const char *interface_name)
{
return NULL;
}

View File

@ -40,10 +40,6 @@ public:
{
}
virtual const char *get_ip_address()
{
return "127.0.0.1";
}
virtual nsapi_error_t get_ip_address(SocketAddress* address)
{
address->set_ip_address("127.0.0.1");

View File

@ -82,7 +82,6 @@ public:
MOCK_CONST_METHOD0(get_connection_status, nsapi_connection_status_t());
MOCK_METHOD1(get_interface_name, char *(char *buf));
MOCK_METHOD2(get_mac_address, char *(char *buf, nsapi_size_t buflen));
MOCK_METHOD2(get_ip_address, char *(char *buf, nsapi_size_t buflen));
MOCK_METHOD1(get_ip_address, nsapi_error_t (SocketAddress *address));
MOCK_METHOD1(get_ipv6_link_local_address, nsapi_error_t(SocketAddress *address));
MOCK_METHOD2(get_netmask, char *(char *buf, nsapi_size_t buflen));

View File

@ -507,22 +507,6 @@ int ESP8266Interface::disconnect()
}
}
const char *ESP8266Interface::get_ip_address()
{
if (_software_conn_stat == IFACE_STATUS_DISCONNECTED) {
_esp.uart_enable_input(true);
}
const char *ip_buff = _esp.ip_addr();
if (!ip_buff || strcmp(ip_buff, "0.0.0.0") == 0) {
ip_buff = NULL;
}
if (_software_conn_stat == IFACE_STATUS_DISCONNECTED) {
_esp.uart_enable_input(false);
}
return ip_buff;
}
nsapi_error_t ESP8266Interface::get_ip_address(SocketAddress *address)
{
if (_software_conn_stat == IFACE_STATUS_DISCONNECTED) {

View File

@ -141,9 +141,6 @@ public:
*/
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

@ -122,8 +122,6 @@ public: // from NetworkInterface
virtual nsapi_error_t set_blocking(bool blocking) = 0;
virtual NetworkStack *get_stack() = 0;
virtual nsapi_error_t get_ip_address(SocketAddress *address) = 0;
MBED_DEPRECATED_SINCE("mbed-os-5.15", "String-based APIs are deprecated")
virtual const char *get_ip_address() = 0;
/** Register callback for status reporting.
*

View File

@ -224,21 +224,6 @@ nsapi_error_t AT_CellularContext::get_ip_address(SocketAddress *address)
#endif
}
const char *AT_CellularContext::get_ip_address()
{
#if NSAPI_PPP_AVAILABLE
return nsapi_ppp_get_ip_addr(_at.get_file_handle());
#else
if (!_stack) {
_stack = get_stack();
}
if (_stack) {
return _stack->get_ip_address();
}
return NULL;
#endif
}
char *AT_CellularContext::get_interface_name(char *interface_name)
{
if (_cid < 0) {

View File

@ -35,7 +35,6 @@ public:
virtual nsapi_error_t set_blocking(bool blocking);
virtual NetworkStack *get_stack();
virtual nsapi_error_t get_ip_address(SocketAddress *address);
virtual const char *get_ip_address();
virtual char *get_interface_name(char *interface_name);
virtual void attach(mbed::Callback<void(nsapi_event_t, intptr_t)> status_cb);
virtual nsapi_error_t connect();

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

@ -299,11 +299,6 @@ void UBLOX_AT_CellularContext::get_next_credentials(char **config)
}
}
const char *UBLOX_AT_CellularContext::get_gateway()
{
return get_ip_address();
}
nsapi_error_t UBLOX_AT_CellularContext::get_gateway(SocketAddress *addr)
{
return get_ip_address(addr);

View File

@ -28,7 +28,6 @@ public:
virtual ~UBLOX_AT_CellularContext();
virtual void do_connect();
virtual const char *get_gateway();
virtual nsapi_error_t get_gateway(SocketAddress *addr);
const char *get_apn(void);

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

@ -98,9 +98,6 @@ public:
/** @copydoc NetworkInterface::get_ip_address */
virtual nsapi_error_t get_ip_address(SocketAddress *address) = 0;
MBED_DEPRECATED_SINCE("mbed-os-5.15", "String-based APIs are deprecated")
virtual const char *get_ip_address() = 0;
/** @copydoc NetworkInterface::cellularInterface
*/
virtual CellularInterface *cellularInterface()

View File

@ -23,31 +23,6 @@
// This class requires Mbed TLS SSL/TLS client code
#if defined(MBEDTLS_SSL_CLI_C)
nsapi_error_t DTLSSocket::connect(const char *host, uint16_t port)
{
SocketAddress addr;
nsapi_error_t ret;
ret = _udp_socket.getpeername(&addr);
if (ret != NSAPI_ERROR_NO_CONNECTION) {
return ret;
}
if (!addr || ret == NSAPI_ERROR_NO_CONNECTION) {
nsapi_error_t err = _udp_socket._stack->gethostbyname(host, &addr);
if (err) {
return NSAPI_ERROR_DNS_FAILURE;
}
addr.set_port(port);
set_hostname(host);
_udp_socket.connect(addr); // UDPSocket::connect() cannot fail
}
return connect(addr);
}
DTLSSocket::~DTLSSocket()
{
// Make sure that DTLSSocketWrapper::close() is called before the transport is

View File

@ -87,19 +87,6 @@ public:
using DTLSSocketWrapper::connect;
/** Connects TCP socket to a remote host.
*
* Initiates a connection to a remote server specified by either
* a domain name or an IP address and a port.
*
* @param host Hostname of the remote host.
* @param port Port of the remote host.
* @return NSAPI_ERROR_OK on success, negative error code on failure.
* See @ref TLSSocketWrapper::connect.
*/
MBED_DEPRECATED_SINCE("mbed-os-5.15", "String-based APIs are deprecated")
nsapi_error_t connect(const char *host, uint16_t port);
private:
UDPSocket _udp_socket;
};

View File

@ -31,20 +31,6 @@ EMACInterface::EMACInterface(EMAC &emac, OnboardNetworkStack &stack) :
{
}
nsapi_error_t EMACInterface::set_network(const char *ip_address, const char *netmask, const char *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';
return NSAPI_ERROR_OK;
}
nsapi_error_t EMACInterface::set_network(const SocketAddress &ip_address, const SocketAddress &netmask, const SocketAddress &gateway)
{
_dhcp = false;
@ -110,14 +96,6 @@ nsapi_error_t EMACInterface::get_ip_address(SocketAddress *address)
return NSAPI_ERROR_NO_CONNECTION;
}
const char *EMACInterface::get_ip_address()
{
if (_interface && _interface->get_ip_address(_ip_address, sizeof(_ip_address))) {
return _ip_address;
}
return nullptr;
}
nsapi_error_t EMACInterface::get_ipv6_link_local_address(SocketAddress *address)
{
if (_interface) {
@ -137,33 +115,16 @@ nsapi_error_t EMACInterface::get_netmask(SocketAddress *address)
return NSAPI_ERROR_NO_CONNECTION;
}
const char *EMACInterface::get_netmask()
{
if (_interface && _interface->get_netmask(_netmask, sizeof(_netmask))) {
return _netmask;
}
return nullptr;
}
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;
}
return NSAPI_ERROR_NO_CONNECTION;
}
const char *EMACInterface::get_gateway()
{
if (_interface && _interface->get_gateway(_gateway, sizeof(_gateway))) {
return _gateway;
}
return nullptr;
}
char *EMACInterface::get_interface_name(char *interface_name)
{
if (_interface) {

View File

@ -59,16 +59,13 @@ 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);
MBED_DEPRECATED_SINCE("mbed-os-5.15", "String-based APIs are deprecated")
virtual nsapi_error_t set_network(const char *ip_address, const char *netmask, const char *gateway);
/** Enable or disable DHCP on the network
*
* Requires that the network is disconnected
@ -91,25 +88,15 @@ 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();
/** @copydoc NetworkInterface::get_ipv6_link_local_address */
virtual nsapi_error_t get_ipv6_link_local_address(SocketAddress *address);
/** @copydoc NetworkInterface::get_netmask */
virtual nsapi_error_t get_netmask(SocketAddress *address);
MBED_DEPRECATED_SINCE("mbed-os-5.15", "String-based APIs are deprecated")
virtual const char *get_netmask();
/** @copydoc NetworkInterface::get_gateway */
virtual nsapi_error_t get_gateway(SocketAddress *address);
/** @copydoc NetworkInterface::get_gateway */
MBED_DEPRECATED_SINCE("mbed-os-5.15", "String-based APIs are deprecated")
virtual const char *get_gateway();
/** @copydoc NetworkInterface::get_interface_name */
virtual char *get_interface_name(char *interface_name);

View File

@ -26,27 +26,6 @@ nsapi_error_t InternetDatagramSocket::connect(const SocketAddress &address)
return NSAPI_ERROR_OK;
}
nsapi_size_or_error_t InternetDatagramSocket::sendto(const char *host, uint16_t port, const void *data, nsapi_size_t size)
{
SocketAddress address;
nsapi_size_or_error_t err;
if (!strcmp(_interface_name, "")) {
err = _stack->gethostbyname(host, &address);
} else {
err = _stack->gethostbyname(host, &address, NSAPI_UNSPEC, _interface_name);
}
if (err) {
return NSAPI_ERROR_DNS_FAILURE;
}
address.set_port(port);
// sendto is thread safe
return sendto(address, data, size);
}
nsapi_size_or_error_t InternetDatagramSocket::sendto(const SocketAddress &address, const void *data, nsapi_size_t size)
{
_lock.lock();

View File

@ -29,29 +29,6 @@
*/
class InternetDatagramSocket : public InternetSocket {
public:
/** Send data to the specified host and port.
*
* By default, sendto blocks until data is sent. If socket is set to
* nonblocking or times out, NSAPI_ERROR_WOULD_BLOCK is returned
* immediately.
*
* @param host Domain name of the remote host or a dotted notation IP address.
* @param port Port of the remote host.
* @param data Buffer of data to send to the host.
* @param size Size of the buffer in bytes.
* @retval int Number of sent bytes on success.
* @retval NSAPI_ERROR_NO_SOCKET in case socket was not created correctly.
* @retval NSAPI_ERROR_DNS_FAILURE if the DNS address of host could not be resolved
* @retval NSAPI_ERROR_WOULD_BLOCK in case non-blocking mode is enabled
* and send cannot be performed immediately.
* @retval int Other negative error codes for stack-related failures.
* See @ref NetworkStack::socket_send.
*/
MBED_DEPRECATED_SINCE("mbed-os-5.15", "String-based APIs are deprecated")
virtual nsapi_size_or_error_t sendto(const char *host, uint16_t port,
const void *data, nsapi_size_t size);
/** Send data to the specified address.
*
* By default, sendto blocks until data is sent. If socket is set to

View File

@ -127,13 +127,6 @@ nsapi_error_t InternetSocket::bind(uint16_t port)
return bind(addr);
}
nsapi_error_t InternetSocket::bind(const char *address, uint16_t port)
{
// Underlying bind is thread safe
SocketAddress addr(address, port);
return bind(addr);
}
nsapi_error_t InternetSocket::bind(const SocketAddress &address)
{
_lock.lock();

View File

@ -96,19 +96,6 @@ public:
*/
nsapi_error_t bind(uint16_t port);
/** Bind the socket to a specific address and port on which to receive
* data. If the IP address is zeroed, only the port is bound.
*
* @param address Null-terminated local address to bind.
* @param port Local port to bind.
* @retval NSAPI_ERROR_OK on success.
* @retval NSAPI_ERROR_NO_SOCKET if socket is not open.
* @retval int negative error codes for stack-related failures.
* See @ref NetworkStack::socket_bind.
*/
MBED_DEPRECATED_SINCE("mbed-os-5.15", "String-based APIs are deprecated")
nsapi_error_t bind(const char *address, uint16_t port);
/** @copydoc Socket::bind
*/
virtual nsapi_error_t bind(const SocketAddress &address);

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

@ -37,11 +37,6 @@ nsapi_error_t NetworkInterface::get_ip_address(SocketAddress *)
return NSAPI_ERROR_UNSUPPORTED;
}
const char *NetworkInterface::get_ip_address()
{
return nullptr;
}
nsapi_error_t NetworkInterface::get_ipv6_link_local_address(SocketAddress *address)
{
return NSAPI_ERROR_UNSUPPORTED;
@ -52,31 +47,16 @@ nsapi_error_t NetworkInterface::get_netmask(SocketAddress *)
return NSAPI_ERROR_UNSUPPORTED;
}
const char *NetworkInterface::get_netmask()
{
return nullptr;
}
nsapi_error_t NetworkInterface::get_gateway(SocketAddress *)
{
return NSAPI_ERROR_UNSUPPORTED;
}
const char *NetworkInterface::get_gateway()
{
return nullptr;
}
char *NetworkInterface::get_interface_name(char *interface_name)
{
return 0;
}
nsapi_error_t NetworkInterface::set_network(const char *ip_address, const char *netmask, const char *gateway)
{
return NSAPI_ERROR_UNSUPPORTED;
}
nsapi_error_t NetworkInterface::set_network(const SocketAddress &ip_address, const SocketAddress &netmask, const SocketAddress &gateway)
{
return NSAPI_ERROR_UNSUPPORTED;

View File

@ -110,9 +110,6 @@ public:
*/
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 IPv6 link local address
*
* @param address SocketAddress representation of the link local IPv6 address
@ -132,9 +129,6 @@ public:
*/
virtual nsapi_error_t get_netmask(SocketAddress *address);
MBED_DEPRECATED_SINCE("mbed-os-5.15", "String-based APIs are deprecated")
virtual const char *get_netmask();
/** Get the local gateway.
*
* @param address SocketAddress representation of gateway address
@ -145,9 +139,6 @@ public:
*/
virtual nsapi_error_t get_gateway(SocketAddress *address);
MBED_DEPRECATED_SINCE("mbed-os-5.15", "String-based APIs are deprecated")
virtual const char *get_gateway();
/** Get the network interface name
*
* @return Null-terminated representation of the network interface name
@ -167,9 +158,6 @@ public:
*/
virtual nsapi_error_t set_network(const SocketAddress &ip_address, const SocketAddress &netmask, const SocketAddress &gateway);
MBED_DEPRECATED_SINCE("mbed-os-5.15", "String-based APIs are deprecated")
virtual nsapi_error_t set_network(const char *ip_address, const char *netmask, const char *gateway);
/** Enable or disable DHCP on connecting the network.
*
* Enabled by default unless a static IP address has been assigned. Requires

View File

@ -29,11 +29,6 @@ nsapi_error_t NetworkStack::get_ip_address(SocketAddress *address)
return NSAPI_ERROR_UNSUPPORTED;
}
const char *NetworkStack::get_ip_address()
{
return nullptr;
}
nsapi_error_t NetworkStack::get_ipv6_link_local_address(SocketAddress *address)
{
return NSAPI_ERROR_UNSUPPORTED;
@ -44,11 +39,6 @@ nsapi_error_t NetworkStack::get_ip_address_if(SocketAddress *address, const char
return NSAPI_ERROR_UNSUPPORTED;
}
const char *NetworkStack::get_ip_address_if(const char *interface_name)
{
return nullptr;
}
nsapi_error_t NetworkStack::gethostbyname(const char *name, SocketAddress *address, nsapi_version_t version, const char *interface_name)
{
if (name[0] == '\0') {
@ -87,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();
}
}
@ -154,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

@ -51,9 +51,6 @@ public:
*/
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 IPv6 link local address
*
* @param address SocketAddress representation of the link local IPv6 address
@ -74,9 +71,6 @@ public:
*/
virtual nsapi_error_t get_ip_address_if(SocketAddress *address, const char *interface_name);
MBED_DEPRECATED_SINCE("mbed-os-5.15", "String-based APIs are deprecated")
virtual const char *get_ip_address_if(const char *interface_name);
/** Translates a hostname to an IP address with specific version
*
* The hostname may be either a domain name or an IP address. If the

View File

@ -112,9 +112,6 @@ public:
/** @copydoc NetworkStack::get_ip_address */
virtual nsapi_error_t get_ip_address(SocketAddress *address) = 0;
MBED_DEPRECATED_SINCE("mbed-os-5.15", "String-based APIs are deprecated")
virtual char *get_ip_address(char *buf, nsapi_size_t buflen) = 0;
/** @copydoc NetworkStack::get_ipv6_link_local_address */
virtual nsapi_error_t get_ipv6_link_local_address(SocketAddress *address)
{
@ -124,14 +121,8 @@ public:
/** @copydoc NetworkStack::get_netmask */
virtual nsapi_error_t get_netmask(SocketAddress *address) = 0;
MBED_DEPRECATED_SINCE("mbed-os-5.15", "String-based APIs are deprecated")
virtual char *get_netmask(char *buf, nsapi_size_t buflen) = 0;
/** @copydoc NetworkStack::get_gateway */
virtual nsapi_error_t get_gateway(SocketAddress *address) = 0;
MBED_DEPRECATED_SINCE("mbed-os-5.15", "String-based APIs are deprecated")
virtual char *get_gateway(char *buf, nsapi_size_t buflen) = 0;
};
/** Register a network interface with the IP stack

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;
@ -83,15 +83,6 @@ nsapi_error_t PPPInterface::disconnect()
return NSAPI_ERROR_NO_CONNECTION;
}
const char *PPPInterface::get_ip_address()
{
if (_interface && _interface->get_ip_address(_ip_address, sizeof(_ip_address))) {
return _ip_address;
}
return NULL;
}
nsapi_error_t PPPInterface::get_ip_address(SocketAddress *address)
{
if (_interface && _interface->get_ip_address(address) == NSAPI_ERROR_OK) {
@ -123,24 +114,6 @@ nsapi_error_t PPPInterface::get_gateway(SocketAddress *address)
return NSAPI_ERROR_NO_CONNECTION;
}
const char *PPPInterface::get_netmask()
{
if (_interface && _interface->get_netmask(_netmask, sizeof(_netmask))) {
return _netmask;
}
return 0;
}
const char *PPPInterface::get_gateway()
{
if (_interface && _interface->get_gateway(_gateway, sizeof(_gateway))) {
return _gateway;
}
return 0;
}
char *PPPInterface::get_interface_name(char *interface_name)
{
if (_interface) {

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();
@ -59,9 +59,6 @@ public:
/** @copydoc NetworkInterface::disconnect */
virtual nsapi_error_t disconnect();
/** @copydoc NetworkInterface::get_ip_address */
virtual const char *get_ip_address();
/** @copydoc NetworkInterface::get_ip_address */
virtual nsapi_error_t get_ip_address(SocketAddress *address);
@ -71,12 +68,6 @@ public:
/** @copydoc NetworkInterface::get_gateway */
virtual nsapi_error_t get_gateway(SocketAddress *address);
/** @copydoc NetworkInterface::get_netmask */
virtual const char *get_netmask();
/** @copydoc NetworkInterface::get_gateway */
virtual const char *get_gateway();
/** @copydoc NetworkInterface::get_interface_name */
virtual char *get_interface_name(char *interface_name);

View File

@ -104,28 +104,6 @@ nsapi_error_t TCPSocket::connect(const SocketAddress &address)
return ret;
}
nsapi_error_t TCPSocket::connect(const char *host, uint16_t port)
{
SocketAddress address;
if (!_socket) {
return NSAPI_ERROR_NO_SOCKET;
}
nsapi_error_t err;
if (!strcmp(_interface_name, "")) {
err = _stack->gethostbyname(host, &address);
} else {
err = _stack->gethostbyname(host, &address, NSAPI_UNSPEC, _interface_name);
}
if (err) {
return NSAPI_ERROR_DNS_FAILURE;
}
address.set_port(port);
// connect is thread safe
return connect(address);
}
nsapi_size_or_error_t TCPSocket::send(const void *data, nsapi_size_t size)
{
_lock.lock();

View File

@ -70,24 +70,6 @@ public:
return NSAPI_ERROR_UNSUPPORTED;
}
/** Connects TCP socket to a remote host
*
* Initiates a connection to a remote server specified by either
* a domain name or an IP address and a port.
*
* @param host Hostname of the remote host
* @param port Port of the remote host
* @retval NSAPI_ERROR_OK on success
* @retval NSAPI_ERROR_IN_PROGRESS if the operation is ongoing
* @retval NSAPI_ERROR_NO_SOCKET if the socket has not been allocated
* @retval NSAPI_ERROR_DNS_FAILURE if the DNS address of host could not be resolved
* @retval NSAPI_ERROR_IS_CONNECTED if the connection is already established
* @retval int Other negative error codes for stack-related failures.
* See NetworkStack::socket_connect().
*/
MBED_DEPRECATED_SINCE("mbed-os-5.15", "String-based APIs are deprecated")
nsapi_error_t connect(const char *host, uint16_t port);
/** Connects TCP socket to a remote host
*
* Initiates a connection to a remote server specified by the

View File

@ -25,21 +25,6 @@
// This class requires Mbed TLS SSL/TLS client code
#if defined(MBEDTLS_SSL_CLI_C)
nsapi_error_t TLSSocket::connect(const char *host, uint16_t port)
{
nsapi_error_t ret = NSAPI_ERROR_OK;
if (!is_handshake_started()) {
ret = tcp_socket.connect(host, port);
if (ret == NSAPI_ERROR_OK || ret == NSAPI_ERROR_IN_PROGRESS) {
set_hostname(host);
}
if (ret != NSAPI_ERROR_OK && ret != NSAPI_ERROR_IS_CONNECTED) {
return ret;
}
}
return TLSSocketWrapper::start_handshake(ret == NSAPI_ERROR_OK);
}
TLSSocket::~TLSSocket()
{
/* Transport is a member of TLSSocket which is derived from TLSSocketWrapper.
@ -91,15 +76,6 @@ nsapi_error_t TLSSocket::set_client_cert_key(const char *client_cert_pem, const
return set_client_cert_key(client_cert_pem, strlen(client_cert_pem), client_private_key_pem, strlen(client_private_key_pem));
}
nsapi_error_t TLSSocket::connect(const char *host, uint16_t port)
{
nsapi_error_t ret = enable_tlssocket();
if (ret == NSAPI_ERROR_OK) {
ret = TCPSocket::connect(host, port);
}
return ret;
}
nsapi_error_t TLSSocket::connect(const SocketAddress &address)
{
nsapi_error_t ret = enable_tlssocket();

View File

@ -80,22 +80,6 @@ public:
using TLSSocketWrapper::connect;
/** Connects TCP socket to a remote host.
*
* Initiates a connection to a remote server specified by either
* a domain name or an IP address and port.
*
* @note: In case connect() returns NSAPI_ERROR_AUTH_FAILURE,
* the socket must be freed either by calling close() or destroying it.
*
* @param host Hostname of the remote host.
* @param port Port of the remote host.
* @return NSAPI_ERROR_OK on success, negative error code on failure.
* See @ref TLSSocketWrapper::connect.
*/
MBED_DEPRECATED_SINCE("mbed-os-5.15", "String-based APIs are deprecated")
nsapi_error_t connect(const char *host, uint16_t port);
private:
TCPSocket tcp_socket;
};

View File

@ -168,8 +168,9 @@ static void sendPacket(UDPSocket *socket, dhcp_packet_t *dhcp, uint32_t size)
uint32_t broadcast_ip = 0xFFFFFFFF;
char string_addr[16];
ipv4_to_string(string_addr, htonl(broadcast_ip));
SocketAddress sock_addr(string_addr, IP_PORT_DHCP_CLIENT);
err = socket->sendto(string_addr, IP_PORT_DHCP_CLIENT, reinterpret_cast<uint8_t *>(dhcp), size);
err = socket->sendto(sock_addr, reinterpret_cast<uint8_t *>(dhcp), size);
if (err < 0) {
printf("DHCP ERROR: Packet send failure with error %d.", err);
} else if (err != (int)size) {
@ -352,8 +353,11 @@ void CyDhcpServer::runServer(void)
_socket.bind((uint16_t)IP_PORT_DHCP_SERVER);
/* Save the current netmask to be sent in DHCP packets as the 'subnet mask option' */
_server_addr.addrv4.addr = string_to_ipv4(_niface->get_ip_address());
_netmask.addrv4.addr = string_to_ipv4(_niface->get_netmask());
SocketAddress sock_addr;
_niface->get_ip_address(&sock_addr);
_server_addr.addrv4.addr = string_to_ipv4(sock_addr.get_ip_address());
_niface->get_netmask(&sock_addr);
_netmask.addrv4.addr = string_to_ipv4(sock_addr.get_ip_address());
#ifdef DHCP_EXTENSIVE_DEBUG
printf("DHCP Server started.\n");

View File

@ -133,7 +133,9 @@ const char *nsapi_ppp_get_ip_addr(FileHandle *stream)
static char ip_addr[IPADDR_STRLEN_MAX];
if (stream == my_stream) {
if (my_interface->get_ip_address(ip_addr, IPADDR_STRLEN_MAX)) {
SocketAddress addr;
if (my_interface->get_ip_address(&addr) == NSAPI_ERROR_OK) {
strncpy(ip_addr, addr.get_ip_address(), IPADDR_STRLEN_MAX);
return ip_addr;
}
}
@ -148,7 +150,9 @@ const char *nsapi_ppp_get_netmask(FileHandle *stream)
static char netmask[IPADDR_STRLEN_MAX];
if (stream == my_stream) {
if (my_interface->get_netmask(netmask, IPADDR_STRLEN_MAX)) {
SocketAddress addr;
if (my_interface->get_netmask(&addr)) {
strncpy(netmask, addr.get_ip_address(), IPADDR_STRLEN_MAX);
return netmask;
}
}
@ -163,7 +167,9 @@ const char *nsapi_ppp_get_gw_addr(FileHandle *stream)
static char gwaddr[IPADDR_STRLEN_MAX];
if (stream == my_stream) {
if (my_interface->get_gateway(gwaddr, IPADDR_STRLEN_MAX)) {
SocketAddress addr;
if (my_interface->get_gateway(&addr)) {
strncpy(gwaddr, addr.get_ip_address(), IPADDR_STRLEN_MAX);
return gwaddr;
}
}