mbed TLS v2.23.0: net_sockets.h Source File

mbed TLS v2.23.0

net_sockets.h
Go to the documentation of this file.
1
22 /*
23 * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
24 * SPDX-License-Identifier: Apache-2.0
25 *
26 * Licensed under the Apache License, Version 2.0 (the "License"); you may
27 * not use this file except in compliance with the License.
28 * You may obtain a copy of the License at
29 *
30 * http://www.apache.org/licenses/LICENSE-2.0
31 *
32 * Unless required by applicable law or agreed to in writing, software
33 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
34 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
35 * See the License for the specific language governing permissions and
36 * limitations under the License.
37 *
38 * This file is part of mbed TLS (https://tls.mbed.org)
39 */
40 #ifndef MBEDTLS_NET_SOCKETS_H
41 #define MBEDTLS_NET_SOCKETS_H
42
43 #if !defined(MBEDTLS_CONFIG_FILE)
44 #include "mbedtls/config.h"
45 #else
46 #include MBEDTLS_CONFIG_FILE
47 #endif
48
49 #include "mbedtls/ssl.h"
50
51 #include <stddef.h>
52 #include <stdint.h>
53
54 #define MBEDTLS_ERR_NET_SOCKET_FAILED -0x0042
55 #define MBEDTLS_ERR_NET_CONNECT_FAILED -0x0044
56 #define MBEDTLS_ERR_NET_BIND_FAILED -0x0046
57 #define MBEDTLS_ERR_NET_LISTEN_FAILED -0x0048
58 #define MBEDTLS_ERR_NET_ACCEPT_FAILED -0x004A
59 #define MBEDTLS_ERR_NET_RECV_FAILED -0x004C
60 #define MBEDTLS_ERR_NET_SEND_FAILED -0x004E
61 #define MBEDTLS_ERR_NET_CONN_RESET -0x0050
62 #define MBEDTLS_ERR_NET_UNKNOWN_HOST -0x0052
63 #define MBEDTLS_ERR_NET_BUFFER_TOO_SMALL -0x0043
64 #define MBEDTLS_ERR_NET_INVALID_CONTEXT -0x0045
65 #define MBEDTLS_ERR_NET_POLL_FAILED -0x0047
66 #define MBEDTLS_ERR_NET_BAD_INPUT_DATA -0x0049
68 #define MBEDTLS_NET_LISTEN_BACKLOG 10
70 #define MBEDTLS_NET_PROTO_TCP 0
71 #define MBEDTLS_NET_PROTO_UDP 1
73 #define MBEDTLS_NET_POLL_READ 1
74 #define MBEDTLS_NET_POLL_WRITE 2
76 #ifdef __cplusplus
77 extern "C" {
78 #endif
79
87 typedef struct mbedtls_net_context
88 {
89 int fd;
90 }
91 mbedtls_net_context;
92
99 void mbedtls_net_init( mbedtls_net_context *ctx );
100
116 int mbedtls_net_connect( mbedtls_net_context *ctx, const char *host, const char *port, int proto );
117
135 int mbedtls_net_bind( mbedtls_net_context *ctx, const char *bind_ip, const char *port, int proto );
136
153 int mbedtls_net_accept( mbedtls_net_context *bind_ctx,
154 mbedtls_net_context *client_ctx,
155 void *client_ip, size_t buf_size, size_t *ip_len );
156
178 int mbedtls_net_poll( mbedtls_net_context *ctx, uint32_t rw, uint32_t timeout );
179
187 int mbedtls_net_set_block( mbedtls_net_context *ctx );
188
196 int mbedtls_net_set_nonblock( mbedtls_net_context *ctx );
197
206 void mbedtls_net_usleep( unsigned long usec );
207
220 int mbedtls_net_recv( void *ctx, unsigned char *buf, size_t len );
221
234 int mbedtls_net_send( void *ctx, const unsigned char *buf, size_t len );
235
257 int mbedtls_net_recv_timeout( void *ctx, unsigned char *buf, size_t len,
258 uint32_t timeout );
259
265 void mbedtls_net_close( mbedtls_net_context *ctx );
266
272 void mbedtls_net_free( mbedtls_net_context *ctx );
273
274 #ifdef __cplusplus
275 }
276 #endif
277
278 #endif /* net_sockets.h */
mbedtls_net_context
struct mbedtls_net_context mbedtls_net_context
mbedtls_net_context
Definition: net_sockets.h:88
mbedtls_net_init
void mbedtls_net_init(mbedtls_net_context *ctx)
Initialize a context Just makes the context ready to be used or freed safely.
mbedtls_net_set_nonblock
int mbedtls_net_set_nonblock(mbedtls_net_context *ctx)
Set the socket non-blocking.
mbedtls_net_recv_timeout
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,...
mbedtls_net_recv
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.
ssl.h
SSL/TLS functions.
mbedtls_net_free
void mbedtls_net_free(mbedtls_net_context *ctx)
Gracefully shutdown the connection and free associated data.
mbedtls_net_bind
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,...
mbedtls_net_set_block
int mbedtls_net_set_block(mbedtls_net_context *ctx)
Set the socket blocking.
mbedtls_net_accept
int mbedtls_net_accept(mbedtls_net_context *bind_ctx, mbedtls_net_context *client_ctx, void *client_ip, size_t buf_size, size_t *ip_len)
Accept a connection from a remote client.
mbedtls_net_connect
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.
config.h
Configuration options (set of defines)
mbedtls_net_close
void mbedtls_net_close(mbedtls_net_context *ctx)
Closes down the connection and free associated data.
mbedtls_net_usleep
void mbedtls_net_usleep(unsigned long usec)
Portable usleep helper.
mbedtls_net_poll
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.
mbedtls_net_context::fd
int fd
Definition: net_sockets.h:89
mbedtls_net_send
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.