Mbed TLS v2.28.8
Loading...
Searching...
No Matches
net_sockets.h
Go to the documentation of this file.
1
22/*
23 * Copyright The Mbed TLS Contributors
24 * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
25 */
26#ifndef MBEDTLS_NET_SOCKETS_H
27#define MBEDTLS_NET_SOCKETS_H
28
29#if !defined(MBEDTLS_CONFIG_FILE)
30#include "mbedtls/config.h"
31#else
32#include MBEDTLS_CONFIG_FILE
33#endif
34
35#include "mbedtls/ssl.h"
36
37#include <stddef.h>
38#include <stdint.h>
39
41#define MBEDTLS_ERR_NET_SOCKET_FAILED -0x0042
43#define MBEDTLS_ERR_NET_CONNECT_FAILED -0x0044
45#define MBEDTLS_ERR_NET_BIND_FAILED -0x0046
47#define MBEDTLS_ERR_NET_LISTEN_FAILED -0x0048
49#define MBEDTLS_ERR_NET_ACCEPT_FAILED -0x004A
51#define MBEDTLS_ERR_NET_RECV_FAILED -0x004C
53#define MBEDTLS_ERR_NET_SEND_FAILED -0x004E
55#define MBEDTLS_ERR_NET_CONN_RESET -0x0050
57#define MBEDTLS_ERR_NET_UNKNOWN_HOST -0x0052
59#define MBEDTLS_ERR_NET_BUFFER_TOO_SMALL -0x0043
61#define MBEDTLS_ERR_NET_INVALID_CONTEXT -0x0045
63#define MBEDTLS_ERR_NET_POLL_FAILED -0x0047
65#define MBEDTLS_ERR_NET_BAD_INPUT_DATA -0x0049
66
67#define MBEDTLS_NET_LISTEN_BACKLOG 10
69#define MBEDTLS_NET_PROTO_TCP 0
70#define MBEDTLS_NET_PROTO_UDP 1
72#define MBEDTLS_NET_POLL_READ 1
73#define MBEDTLS_NET_POLL_WRITE 2
75#ifdef __cplusplus
76extern "C" {
77#endif
78
86typedef struct mbedtls_net_context {
87 int fd;
88}
90
98
114int mbedtls_net_connect(mbedtls_net_context *ctx, const char *host, const char *port, int proto);
115
134int mbedtls_net_bind(mbedtls_net_context *ctx, const char *bind_ip, const char *port, int proto);
135
155 mbedtls_net_context *client_ctx,
156 void *client_ip, size_t buf_size, size_t *cip_len);
157
183int mbedtls_net_poll(mbedtls_net_context *ctx, uint32_t rw, uint32_t timeout);
184
193
202
211void mbedtls_net_usleep(unsigned long usec);
212
225int mbedtls_net_recv(void *ctx, unsigned char *buf, size_t len);
226
239int mbedtls_net_send(void *ctx, const unsigned char *buf, size_t len);
240
267int mbedtls_net_recv_timeout(void *ctx, unsigned char *buf, size_t len,
268 uint32_t timeout);
269
280
291
292#ifdef __cplusplus
293}
294#endif
295
296#endif /* net_sockets.h */
Configuration options (set of defines)
int mbedtls_net_recv(void *ctx, unsigned char *buf, size_t len)
Read at most 'len' characters. If no error occurs, the actual amount read is returned.
int mbedtls_net_accept(mbedtls_net_context *bind_ctx, mbedtls_net_context *client_ctx, void *client_ip, size_t buf_size, size_t *cip_len)
Accept a connection from a remote client.
int mbedtls_net_set_nonblock(mbedtls_net_context *ctx)
Set the socket non-blocking.
int mbedtls_net_send(void *ctx, const unsigned char *buf, size_t len)
Write at most 'len' characters. If no error occurs, the actual amount read is returned.
void mbedtls_net_close(mbedtls_net_context *ctx)
Closes down the connection and free associated data.
struct mbedtls_net_context mbedtls_net_context
int mbedtls_net_recv_timeout(void *ctx, unsigned char *buf, size_t len, uint32_t timeout)
Read at most 'len' characters, blocking for at most 'timeout' seconds. If no error occurs,...
void mbedtls_net_usleep(unsigned long usec)
Portable usleep helper.
void mbedtls_net_free(mbedtls_net_context *ctx)
Gracefully shutdown the connection and free associated data.
int mbedtls_net_bind(mbedtls_net_context *ctx, const char *bind_ip, const char *port, int proto)
Create a receiving socket on bind_ip:port in the chosen protocol. If bind_ip == NULL,...
int mbedtls_net_poll(mbedtls_net_context *ctx, uint32_t rw, uint32_t timeout)
Check and wait for the context to be ready for read/write.
int mbedtls_net_connect(mbedtls_net_context *ctx, const char *host, const char *port, int proto)
Initiate a connection with host:port in the given protocol.
void mbedtls_net_init(mbedtls_net_context *ctx)
Initialize a context Just makes the context ready to be used or freed safely.
int mbedtls_net_set_block(mbedtls_net_context *ctx)
Set the socket blocking.
SSL/TLS functions.