Mbed OS Reference
Loading...
Searching...
No Matches
NetworkStack.h
Go to the documentation of this file.
1
2/* NetworkStack
3 * Copyright (c) 2015 ARM Limited
4 * SPDX-License-Identifier: Apache-2.0
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
19#ifndef NETWORK_STACK_H
20#define NETWORK_STACK_H
21
22#include <type_traits>
23#include "nsapi_types.h"
26#include "DNS.h"
27
28/** @file NetworkStack.h NetworkStack class */
29/** @addtogroup NetSocket
30 * @{ */
31
32// Predeclared classes
34
35/** NetworkStack class
36 *
37 * Common interface that is shared between hardware that
38 * can connect to a network over IP. By implementing the
39 * NetworkStack, a network stack can be used as a target
40 * for instantiating network sockets.
41 */
42class NetworkStack : public DNS {
43public:
44 virtual ~NetworkStack() = default;
45
46 /** Get the local IP address
47 *
48 * @param address SocketAddress representation of the local IP address
49 * @retval NSAPI_ERROR_OK on success
50 * @retval NSAPI_ERROR_UNSUPPORTED if this feature is not supported
51 * @retval NSAPI_ERROR_PARAMETER if the provided pointer is invalid
52 * @retval NSAPI_ERROR_NO_ADDRESS if the address cannot be obtained from stack
53 */
55
56 /** Get the IPv6 link local address
57 *
58 * @param address SocketAddress representation of the link local IPv6 address
59 * @retval NSAPI_ERROR_OK on success
60 * @retval NSAPI_ERROR_UNSUPPORTED if this feature is not supported
61 * @retval NSAPI_ERROR_PARAMETER if the provided pointer is invalid
62 */
64
65 /** Get the local IP address on interface name
66 *
67 * @param address SocketAddress representation of the link local IPv6 address
68 * @param interface_name Network interface_name
69 * @retval NSAPI_ERROR_OK on success
70 * @retval NSAPI_ERROR_UNSUPPORTED if this feature is not supported
71 * @retval NSAPI_ERROR_PARAMETER if the provided pointer is invalid
72 * @retval NSAPI_ERROR_NO_ADDRESS if the address cannot be obtained from stack
73 */
74 virtual nsapi_error_t get_ip_address_if(SocketAddress *address, const char *interface_name);
75
76 /** Translates a hostname to an IP address with specific version
77 *
78 * The hostname may be either a domain name or an IP address. If the
79 * hostname is an IP address, no network transactions will be performed.
80 *
81 * If no stack-specific DNS resolution is provided, the hostname
82 * will be resolve using a UDP socket on the stack.
83 *
84 * @param host Hostname to resolve
85 * @param address Pointer to a SocketAddress to store the result.
86 * @param version IP version of address to resolve, NSAPI_UNSPEC indicates
87 * version is chosen by the stack (defaults to NSAPI_UNSPEC)
88 * @param interface_name Network interface_name
89 * @retval NSAPI_ERROR_OK on success
90 * @retval NSAPI_ERROR_PARAMETER if invalid (null) name is provided
91 * @retval NSAPI_ERROR_DNS_FAILURE if DNS resolution fails
92 * @retval int other negative errors, see @ref nsapi_dns_query
93 */
94 virtual nsapi_error_t gethostbyname(const char *host,
95 SocketAddress *address, nsapi_version_t version = NSAPI_UNSPEC, const char *interface_name = NULL);
96
97 /** Translate a hostname to the multiple IP addresses with specific version using network interface name.
98 *
99 * The hostname may be either a domain name or an IP address. If the
100 * hostname is an IP address, no network transactions will be performed.
101 *
102 * If no stack-specific DNS resolution is provided, the hostname
103 * will be resolve using a UDP socket on the stack.
104 *
105 * @param hostname Hostname to resolve.
106 * @param hints Pointer to a SocketAddress with query parameters.
107 * @param res Pointer to a SocketAddress array to store the result..
108 * @param interface_name Network interface name
109 * @return number of results on success, negative error code on failure.
110 */
111 virtual nsapi_value_or_error_t getaddrinfo(const char *hostname, SocketAddress *hints, SocketAddress **res, const char *interface_name = NULL);
112
114
115 /** Translates a hostname to multiple IP addresses (asynchronous)
116 *
117 * The hostname may be either a domain name or an IP address. If the
118 * hostname is an IP address, no network transactions will be performed.
119 *
120 * If no stack-specific DNS resolution is provided, the hostname
121 * will be resolve using a UDP socket on the stack.
122 *
123 * Call is non-blocking. Result of the DNS operation is returned by the callback.
124 * If this function returns failure, callback will not be called. In case result
125 * is success (IP address was found from DNS cache), callback will be called
126 * before function returns.
127 *
128 * @param host Hostname to resolve
129 * @param callback Callback that is called for result
130 * @param version IP version of address to resolve, NSAPI_UNSPEC indicates
131 * version is chosen by the stack (defaults to NSAPI_UNSPEC)
132 * @param interface_name Network interface_name
133 * @return 0 on immediate success,
134 * negative error code on immediate failure or
135 * a positive unique id that represents the hostname translation operation
136 * and can be passed to cancel
137 */
138 virtual nsapi_value_or_error_t gethostbyname_async(const char *host, hostbyname_cb_t callback, nsapi_version_t version = NSAPI_UNSPEC,
139 const char *interface_name = NULL);
140
141 /** Translates a hostname to the multiple IP addresses (asynchronous)
142 *
143 * The hostname may be either a domain name or an IP address. If the
144 * hostname is an IP address, no network transactions will be performed.
145 *
146 * If no stack-specific DNS resolution is provided, the hostname
147 * will be resolve using a UDP socket on the stack.
148 *
149 * The call is non-blocking. Result of the DNS operation is returned by the callback.
150 * If this function returns failure, callback will not be called. In case that
151 * IP addresses are found from DNS cache, callback will be called before function returns.
152 *
153 * @param hostname Hostname to resolve
154 * @param hints Pointer to a SocketAddress with query parameters.
155 * @param callback Callback that is called for result
156 * @param interface_name Network interface_name
157 * @return 0 on immediate success,
158 * negative error code on immediate failure or
159 * a positive unique id that represents the hostname translation operation
160 * and can be passed to cancel
161 */
162 virtual nsapi_value_or_error_t getaddrinfo_async(const char *hostname, SocketAddress *hints, hostbyname_cb_t callback, const char *interface_name = NULL);
163
164 /** Cancels asynchronous hostname translation
165 *
166 * When translation is cancelled, callback will not be called.
167 *
168 * @param id Unique id of the hostname translation operation
169 * @return NSAPI_ERROR_OK on success, negative error code on failure
170 */
172
173 /** Add a domain name server to list of servers to query
174 *
175 * @param address Destination for the host address
176 * @param interface_name Network interface name. Currently unused, the server is added for all interfaces.
177 * @return NSAPI_ERROR_OK on success, negative error code on failure
178 */
179 virtual nsapi_error_t add_dns_server(const SocketAddress &address, const char *interface_name = NULL);
180
181 /** Get a domain name server from a list of servers to query
182 *
183 * Returns a DNS server address for a index. If returns error no more
184 * DNS servers to read.
185 *
186 * @param index Index of the DNS server, starts from zero
187 * @param address Destination for the host address
188 * @param interface_name Network interface name
189 * @return NSAPI_ERROR_OK on success, negative error code on failure
190 */
191 virtual nsapi_error_t get_dns_server(int index, SocketAddress *address, const char *interface_name = NULL);
192
193 /* Set stack options
194 *
195 * setstackopt allows an application to pass stack-specific options
196 * to the underlying stack using stack-specific level and option names,
197 * or to request generic options using levels from nsapi_stack_level_t.
198 *
199 * For unsupported options, NSAPI_ERROR_UNSUPPORTED is returned
200 * and the stack is unmodified.
201 *
202 * @param level Stack-specific protocol level or nsapi_stack_level_t
203 * @param optname Level-specific option name
204 * @param optval Option value
205 * @param optlen Length of the option value
206 * @return NSAPI_ERROR_OK on success, negative error code on failure
207 */
208 virtual nsapi_error_t setstackopt(int level, int optname, const void *optval, unsigned optlen);
209
210 /* Get stack options
211 *
212 * getstackopt allows an application to retrieve stack-specific options
213 * to the underlying stack using stack-specific level and option names,
214 * or to request generic options using levels from nsapi_stack_level_t.
215 *
216 * @param level Stack-specific protocol level or nsapi_stack_level_t
217 * @param optname Level-specific option name
218 * @param optval Destination for option value
219 * @param optlen Length of the option value
220 * @return NSAPI_ERROR_OK on success, negative error code on failure
221 */
222 virtual nsapi_error_t getstackopt(int level, int optname, void *optval, unsigned *optlen);
223
224 /** Dynamic downcast to a OnboardNetworkStack */
226 {
227 return nullptr;
228 }
229
230 /**
231 * Type for a call-in callback.
232 * This is a pointer to a function that will call the provided callback from the network stack
233 * after a given delay, or immediately if \p delay_ms is 0.
234 */
235 typedef mbed::Callback<nsapi_error_t (int delay_ms, mbed::Callback<void()> user_cb)> call_in_callback_cb_t;
236
237protected:
238 friend class InternetSocket;
239 friend class InternetDatagramSocket;
240 friend class TCPSocket;
241
242 /** Opens a socket
243 *
244 * Creates a network socket and stores it in the specified handle.
245 * The handle must be passed to following calls on the socket.
246 *
247 * A stack may have a finite number of sockets, in this case
248 * NSAPI_ERROR_NO_SOCKET is returned if no socket is available.
249 *
250 * @param handle Destination for the handle to a newly created socket
251 * @param proto Protocol of socket to open, NSAPI_TCP or NSAPI_UDP
252 * @return NSAPI_ERROR_OK on success, negative error code on failure
253 */
254 virtual nsapi_error_t socket_open(nsapi_socket_t *handle, nsapi_protocol_t proto) = 0;
255
256 /** Close the socket
257 *
258 * Closes any open connection and deallocates any memory associated
259 * with the socket.
260 *
261 * @param handle Socket handle
262 * @return NSAPI_ERROR_OK on success, negative error code on failure
263 */
265
266 /** Bind a specific address to a socket
267 *
268 * Binding a socket specifies the address and port on which to receive
269 * data. If the IP address is zeroed, only the port is bound.
270 *
271 * @param handle Socket handle
272 * @param address Local address to bind
273 * @return NSAPI_ERROR_OK on success, negative error code on failure.
274 */
275 virtual nsapi_error_t socket_bind(nsapi_socket_t handle, const SocketAddress &address) = 0;
276
277 /** Listen for connections on a TCP socket
278 *
279 * Marks the socket as a passive socket that can be used to accept
280 * incoming connections.
281 *
282 * @param handle Socket handle
283 * @param backlog Number of pending connections that can be queued
284 * simultaneously
285 * @return NSAPI_ERROR_OK on success, negative error code on failure
286 */
287 virtual nsapi_error_t socket_listen(nsapi_socket_t handle, int backlog) = 0;
288
289 /** Connects TCP socket to a remote host
290 *
291 * Initiates a connection to a remote server specified by the
292 * indicated address.
293 *
294 * @param handle Socket handle
295 * @param address The SocketAddress of the remote host
296 * @return NSAPI_ERROR_OK on success, negative error code on failure
297 */
298 virtual nsapi_error_t socket_connect(nsapi_socket_t handle, const SocketAddress &address) = 0;
299
300 /** Accepts a connection on a TCP socket
301 *
302 * The server socket must be bound and set to listen for connections.
303 * On a new connection, creates a network socket and stores it in the
304 * specified handle. The handle must be passed to following calls on
305 * the socket.
306 *
307 * A stack may have a finite number of sockets, in this case
308 * NSAPI_ERROR_NO_SOCKET is returned if no socket is available.
309 *
310 * This call is non-blocking. If accept would block,
311 * NSAPI_ERROR_WOULD_BLOCK is returned immediately.
312 *
313 * @param server Socket handle to server to accept from
314 * @param handle Destination for a handle to the newly created socket
315 * @param address Destination for the remote address or NULL
316 * @return NSAPI_ERROR_OK on success, negative error code on failure
317 */
319 nsapi_socket_t *handle, SocketAddress *address = 0) = 0;
320
321 /** Send data over a TCP socket
322 *
323 * The socket must be connected to a remote host. Returns the number of
324 * bytes sent from the buffer.
325 *
326 * This call is non-blocking. If send would block,
327 * NSAPI_ERROR_WOULD_BLOCK is returned immediately.
328 *
329 * @param handle Socket handle
330 * @param data Buffer of data to send to the host
331 * @param size Size of the buffer in bytes
332 * @return Number of sent bytes on success, negative error
333 * code on failure
334 */
336 const void *data, nsapi_size_t size) = 0;
337
338 /** Receive data over a TCP socket
339 *
340 * The socket must be connected to a remote host. Returns the number of
341 * bytes received into the buffer.
342 *
343 * This call is non-blocking. If recv would block,
344 * NSAPI_ERROR_WOULD_BLOCK is returned immediately.
345 *
346 * @param handle Socket handle
347 * @param data Destination buffer for data received from the host
348 * @param size Size of the buffer in bytes
349 * @return Number of received bytes on success, negative error
350 * code on failure
351 */
353 void *data, nsapi_size_t size) = 0;
354
355 /** Send a packet over a UDP socket
356 *
357 * Sends data to the specified address. Returns the number of bytes
358 * sent from the buffer.
359 *
360 * This call is non-blocking. If sendto would block,
361 * NSAPI_ERROR_WOULD_BLOCK is returned immediately.
362 *
363 * @param handle Socket handle
364 * @param address The SocketAddress of the remote host
365 * @param data Buffer of data to send to the host
366 * @param size Size of the buffer in bytes
367 * @return Number of sent bytes on success, negative error
368 * code on failure
369 */
371 const void *data, nsapi_size_t size) = 0;
372
373 /** Receive a packet over a UDP socket
374 *
375 * Receives data and stores the source address in address if address
376 * is not NULL. Returns the number of bytes received into the buffer.
377 *
378 * This call is non-blocking. If recvfrom would block,
379 * NSAPI_ERROR_WOULD_BLOCK is returned immediately.
380 *
381 * @param handle Socket handle
382 * @param address Destination for the source address or NULL
383 * @param buffer Destination buffer for data received from the host
384 * @param size Size of the buffer in bytes
385 * @return Number of received bytes on success, negative error
386 * code on failure
387 */
389 void *buffer, nsapi_size_t size) = 0;
390
391 /** Send a packet with ancillary data over a UDP socket
392 *
393 * Sends data to the specified address. Returns the number of bytes
394 * sent from the buffer.
395 *
396 * This call is non-blocking. If sendto would block,
397 * NSAPI_ERROR_WOULD_BLOCK is returned immediately.
398 *
399 * @param handle Socket handle
400 * @param address The SocketAddress of the remote host
401 * @param data Buffer of data to send to the host
402 * @param size Size of the buffer in bytes
403 * @param control Storage for ancillary data
404 * @param control_size Size of ancillary data
405 * @return Number of sent bytes on success, negative error
406 * code on failure
407 */
409 const void *data, nsapi_size_t size,
410 nsapi_msghdr_t *control, nsapi_size_t control_size)
411 {
412 if (control != NULL) {
414 }
415
416 return socket_sendto(handle, address, data, size);
417 }
418
419 /** Receive a packet with ancillary data over a UDP socket
420 *
421 * Receives data and stores the source address in address if address
422 * is not NULL. Returns the number of bytes received into the buffer.
423 *
424 * Ancillary data is stored into \c control. The caller needs to allocate a buffer
425 * that is large enough to contain the data they want to receive, then pass the pointer in
426 * through the \c control member. The data will be filled into \c control, beginning with a header
427 * specifying what data was received. See #MsgHeaderIterator for how to parse this data.
428 *
429 * This call is non-blocking. If recvfrom would block,
430 * NSAPI_ERROR_WOULD_BLOCK is returned immediately.
431 *
432 * @param handle Socket handle
433 * @param address Destination for the source address or NULL
434 * @param data Destination buffer for data received from the host
435 * @param size Size of the buffer in bytes
436 * @param control Storage for ancillary data
437 * @param control_size Size of ancillary data
438 * @return Number of received bytes on success, negative error
439 * code on failure
440 */
442 void *data, nsapi_size_t size,
443 nsapi_msghdr_t *control, nsapi_size_t control_size)
444 {
445 if (control != NULL) {
447 }
448
449 return socket_recvfrom(handle, address, data, size);
450 }
451
452 /** Register a callback on state change of the socket
453 *
454 * The specified callback will be called on state changes such as when
455 * the socket can recv/send/accept successfully and on when an error
456 * occurs. The callback may also be called spuriously without reason.
457 *
458 * The callback may be called in an interrupt context and should not
459 * perform expensive operations such as recv/send calls.
460 *
461 * @param handle Socket handle
462 * @param callback Function to call on state change
463 * @param data Argument to pass to callback
464 */
465 virtual void socket_attach(nsapi_socket_t handle, void (*callback)(void *), void *data) = 0;
466
467 /** Set stack-specific socket options.
468 *
469 * The setsockopt allow an application to pass stack-specific hints
470 * to the underlying stack. For unsupported options,
471 * NSAPI_ERROR_UNSUPPORTED is returned and the socket is unmodified.
472 *
473 * @param handle Socket handle.
474 * @param level Stack-specific protocol level.
475 * @param optname Stack-specific option identifier.
476 * @param optval Option value.
477 * @param optlen Length of the option value.
478 * @return NSAPI_ERROR_OK on success, negative error code on failure.
479 */
480 virtual nsapi_error_t setsockopt(nsapi_socket_t handle, int level,
481 int optname, const void *optval, unsigned optlen);
482
483 /** Get stack-specific socket options.
484 *
485 * The getstackopt allow an application to retrieve stack-specific hints
486 * from the underlying stack. For unsupported options,
487 * NSAPI_ERROR_UNSUPPORTED is returned and optval is unmodified.
488 *
489 * @param handle Socket handle.
490 * @param level Stack-specific protocol level.
491 * @param optname Stack-specific option identifier.
492 * @param optval Destination for option value.
493 * @param optlen Length of the option value.
494 * @return NSAPI_ERROR_OK on success, negative error code on failure.
495 */
496 virtual nsapi_error_t getsockopt(nsapi_socket_t handle, int level,
497 int optname, void *optval, unsigned *optlen);
498
499private:
500
501 /** Get a call in callback
502 *
503 * Get a call in callback from the network stack context.
504 *
505 * Callback should not take more than 10ms to execute, otherwise it might
506 * prevent underlying thread processing. A portable user of the callback
507 * should not make calls to network operations due to stack size limitations.
508 * The callback should not perform expensive operations such as socket recv/send
509 * calls or blocking operations.
510 *
511 * @return Call in callback
512 */
513 virtual call_in_callback_cb_t get_call_in_callback();
514
515 /** Call a callback after a delay
516 *
517 * Call a callback from the network stack context after a delay. If function
518 * returns error callback will not be called.
519 *
520 * @param delay Delay in milliseconds
521 * @param func Callback to be called
522 * @return NSAPI_ERROR_OK on success, negative error code on failure
523 */
524 virtual nsapi_error_t call_in(int delay, mbed::Callback<void()> func);
525};
526
527inline NetworkStack *_nsapi_create_stack(NetworkStack *stack, std::true_type /* convertible to NetworkStack */)
528{
529 return stack;
530}
531
532inline NetworkStack *_nsapi_create_stack(NetworkInterface *iface, std::false_type /* not convertible to NetworkStack */)
533{
534 return iface->get_stack();
535}
536
537/** Convert a raw nsapi_stack_t object into a C++ NetworkStack object
538 *
539 * @param stack Pointer to an object that can be converted to a stack
540 * - A raw nsapi_stack_t object
541 * - A pointer to a network stack
542 * - A pointer to a network interface
543 * @return Pointer to the underlying network stack
544 */
546
547template <typename IF>
549{
550 return _nsapi_create_stack(iface, std::is_convertible<IF *, NetworkStack *>());
551}
552
553
554#endif
555
556/** @} */
Domain Name Service.
Network Interface base class.
SocketAddress class.
Base class for DNS provider.
Definition: DNS.h:28
InternetDatagramSocket socket implementation.
Socket implementation that uses IP network stack.
Common interface that is shared between network devices.
NetworkStack class.
Definition: NetworkStack.h:42
virtual nsapi_error_t get_dns_server(int index, SocketAddress *address, const char *interface_name=NULL)
Get a domain name server from a list of servers to query.
virtual nsapi_size_or_error_t socket_recv(nsapi_socket_t handle, void *data, nsapi_size_t size)=0
Receive data over a TCP socket.
virtual nsapi_error_t gethostbyname_async_cancel(int id)
Cancels asynchronous hostname translation.
virtual nsapi_error_t get_ip_address(SocketAddress *address)
Get the local IP address.
virtual nsapi_size_or_error_t socket_recvfrom(nsapi_socket_t handle, SocketAddress *address, void *buffer, nsapi_size_t size)=0
Receive a packet over a UDP socket.
virtual nsapi_size_or_error_t socket_recvfrom_control(nsapi_socket_t handle, SocketAddress *address, void *data, nsapi_size_t size, nsapi_msghdr_t *control, nsapi_size_t control_size)
Receive a packet with ancillary data over a UDP socket.
Definition: NetworkStack.h:441
virtual nsapi_error_t socket_listen(nsapi_socket_t handle, int backlog)=0
Listen for connections on a TCP socket.
virtual nsapi_error_t socket_close(nsapi_socket_t handle)=0
Close the socket.
virtual nsapi_error_t gethostbyname(const char *host, SocketAddress *address, nsapi_version_t version=NSAPI_UNSPEC, const char *interface_name=NULL)
Translates a hostname to an IP address with specific version.
virtual nsapi_size_or_error_t socket_send(nsapi_socket_t handle, const void *data, nsapi_size_t size)=0
Send data over a TCP socket.
virtual nsapi_size_or_error_t socket_sendto(nsapi_socket_t handle, const SocketAddress &address, const void *data, nsapi_size_t size)=0
Send a packet over a UDP socket.
mbed::Callback< nsapi_error_t(int delay_ms, mbed::Callback< void()> user_cb)> call_in_callback_cb_t
Type for a call-in callback.
Definition: NetworkStack.h:235
virtual nsapi_error_t get_ipv6_link_local_address(SocketAddress *address)
Get the IPv6 link local address.
virtual void socket_attach(nsapi_socket_t handle, void(*callback)(void *), void *data)=0
Register a callback on state change of the socket.
virtual nsapi_value_or_error_t getaddrinfo(const char *hostname, SocketAddress *hints, SocketAddress **res, const char *interface_name=NULL)
Translate a hostname to the multiple IP addresses with specific version using network interface name.
virtual nsapi_error_t socket_open(nsapi_socket_t *handle, nsapi_protocol_t proto)=0
Opens a socket.
virtual nsapi_error_t socket_accept(nsapi_socket_t server, nsapi_socket_t *handle, SocketAddress *address=0)=0
Accepts a connection on a TCP socket.
virtual OnboardNetworkStack * onboardNetworkStack()
Dynamic downcast to a OnboardNetworkStack.
Definition: NetworkStack.h:225
virtual nsapi_size_or_error_t socket_sendto_control(nsapi_socket_t handle, const SocketAddress &address, const void *data, nsapi_size_t size, nsapi_msghdr_t *control, nsapi_size_t control_size)
Send a packet with ancillary data over a UDP socket.
Definition: NetworkStack.h:408
virtual nsapi_value_or_error_t getaddrinfo_async(const char *hostname, SocketAddress *hints, hostbyname_cb_t callback, const char *interface_name=NULL)
Translates a hostname to the multiple IP addresses (asynchronous)
virtual nsapi_error_t setsockopt(nsapi_socket_t handle, int level, int optname, const void *optval, unsigned optlen)
Set stack-specific socket options.
virtual nsapi_value_or_error_t gethostbyname_async(const char *host, hostbyname_cb_t callback, nsapi_version_t version=NSAPI_UNSPEC, const char *interface_name=NULL)
Translates a hostname to multiple IP addresses (asynchronous)
virtual nsapi_error_t socket_bind(nsapi_socket_t handle, const SocketAddress &address)=0
Bind a specific address to a socket.
virtual nsapi_error_t socket_connect(nsapi_socket_t handle, const SocketAddress &address)=0
Connects TCP socket to a remote host.
virtual nsapi_error_t get_ip_address_if(SocketAddress *address, const char *interface_name)
Get the local IP address on interface name.
virtual nsapi_error_t add_dns_server(const SocketAddress &address, const char *interface_name=NULL)
Add a domain name server to list of servers to query.
virtual nsapi_error_t getsockopt(nsapi_socket_t handle, int level, int optname, void *optval, unsigned *optlen)
Get stack-specific socket options.
mbed OS API for onboard IP stack abstraction
SocketAddress class.
Definition: SocketAddress.h:37
TCP socket connection.
Definition: TCPSocket.h:33
Callback class based on template specialization.
Definition: Callback.h:53
signed int nsapi_size_or_error_t
Type used to represent either a size or error passed through sockets.
Definition: nsapi_types.h:153
signed int nsapi_value_or_error_t
Type used to represent either a value or error.
Definition: nsapi_types.h:160
signed int nsapi_error_t
Type used to represent error codes.
Definition: nsapi_types.h:142
NetworkStack * nsapi_create_stack(nsapi_stack_t *stack)
Convert a raw nsapi_stack_t object into a C++ NetworkStack object.
void * nsapi_socket_t
Opaque handle for network sockets.
Definition: nsapi_types.h:264
unsigned int nsapi_size_t
Type used to represent the size of data passed through sockets.
Definition: nsapi_types.h:146
@ NSAPI_ERROR_UNSUPPORTED
Definition: nsapi_types.h:87
@ NSAPI_UNSPEC
Definition: nsapi_types.h:240
Header structure for control info.
Definition: nsapi_types.h:426
nsapi_stack structure
Definition: nsapi_types.h:381