IPCore deprecated string-based API removal

String-based functions should be replaced with an explicit DNS hostname resolution and a SocketAddress-based API.
pull/11942/head
Michal Paszta 2019-11-21 15:35:35 +02:00
parent 8dc15ee6e1
commit 458957d399
33 changed files with 16 additions and 416 deletions

View File

@ -116,11 +116,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

@ -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

@ -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

@ -233,21 +233,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

@ -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

@ -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,14 +115,6 @@ 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) {
@ -156,14 +126,6 @@ nsapi_error_t EMACInterface::get_gateway(SocketAddress *address)
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

@ -66,9 +66,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 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

@ -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') {

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

@ -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

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