mbed TLS v2.7.17
net_sockets.h
Go to the documentation of this file.
1 
6 /*
7  * Copyright The Mbed TLS Contributors
8  * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
9  *
10  * This file is provided under the Apache License 2.0, or the
11  * GNU General Public License v2.0 or later.
12  *
13  * **********
14  * Apache License 2.0:
15  *
16  * Licensed under the Apache License, Version 2.0 (the "License"); you may
17  * not use this file except in compliance with the License.
18  * You may obtain a copy of the License at
19  *
20  * http://www.apache.org/licenses/LICENSE-2.0
21  *
22  * Unless required by applicable law or agreed to in writing, software
23  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
24  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
25  * See the License for the specific language governing permissions and
26  * limitations under the License.
27  *
28  * **********
29  *
30  * **********
31  * GNU General Public License v2.0 or later:
32  *
33  * This program is free software; you can redistribute it and/or modify
34  * it under the terms of the GNU General Public License as published by
35  * the Free Software Foundation; either version 2 of the License, or
36  * (at your option) any later version.
37  *
38  * This program is distributed in the hope that it will be useful,
39  * but WITHOUT ANY WARRANTY; without even the implied warranty of
40  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
41  * GNU General Public License for more details.
42  *
43  * You should have received a copy of the GNU General Public License along
44  * with this program; if not, write to the Free Software Foundation, Inc.,
45  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
46  *
47  * **********
48  */
49 #ifndef MBEDTLS_NET_SOCKETS_H
50 #define MBEDTLS_NET_SOCKETS_H
51 
52 #if !defined(MBEDTLS_CONFIG_FILE)
53 #include "config.h"
54 #else
55 #include MBEDTLS_CONFIG_FILE
56 #endif
57 
58 #include "ssl.h"
59 
60 #include <stddef.h>
61 #include <stdint.h>
62 
63 #define MBEDTLS_ERR_NET_SOCKET_FAILED -0x0042
64 #define MBEDTLS_ERR_NET_CONNECT_FAILED -0x0044
65 #define MBEDTLS_ERR_NET_BIND_FAILED -0x0046
66 #define MBEDTLS_ERR_NET_LISTEN_FAILED -0x0048
67 #define MBEDTLS_ERR_NET_ACCEPT_FAILED -0x004A
68 #define MBEDTLS_ERR_NET_RECV_FAILED -0x004C
69 #define MBEDTLS_ERR_NET_SEND_FAILED -0x004E
70 #define MBEDTLS_ERR_NET_CONN_RESET -0x0050
71 #define MBEDTLS_ERR_NET_UNKNOWN_HOST -0x0052
72 #define MBEDTLS_ERR_NET_BUFFER_TOO_SMALL -0x0043
73 #define MBEDTLS_ERR_NET_INVALID_CONTEXT -0x0045
75 #define MBEDTLS_NET_LISTEN_BACKLOG 10
77 #define MBEDTLS_NET_PROTO_TCP 0
78 #define MBEDTLS_NET_PROTO_UDP 1
80 #ifdef __cplusplus
81 extern "C" {
82 #endif
83 
91 typedef struct
92 {
93  int fd;
94 }
96 
104 
120 int mbedtls_net_connect( mbedtls_net_context *ctx, const char *host, const char *port, int proto );
121 
139 int mbedtls_net_bind( mbedtls_net_context *ctx, const char *bind_ip, const char *port, int proto );
140 
158  mbedtls_net_context *client_ctx,
159  void *client_ip, size_t buf_size, size_t *ip_len );
160 
169 
178 
187 void mbedtls_net_usleep( unsigned long usec );
188 
201 int mbedtls_net_recv( void *ctx, unsigned char *buf, size_t len );
202 
215 int mbedtls_net_send( void *ctx, const unsigned char *buf, size_t len );
216 
238 int mbedtls_net_recv_timeout( void *ctx, unsigned char *buf, size_t len,
239  uint32_t timeout );
240 
247 
248 #ifdef __cplusplus
249 }
250 #endif
251 
252 #endif /* net_sockets.h */
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, all interfaces are bound.
void mbedtls_net_free(mbedtls_net_context *ctx)
Gracefully shutdown the connection and free associated data.
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.
int mbedtls_net_set_block(mbedtls_net_context *ctx)
Set the socket blocking.
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.
Configuration options (set of defines)
void mbedtls_net_usleep(unsigned long usec)
Portable usleep helper.
int mbedtls_net_send(void *ctx, const unsigned char *buf, size_t len)
Write at most &#39;len&#39; characters. If no error occurs, the actual amount read is returned.
void mbedtls_net_init(mbedtls_net_context *ctx)
Initialize a context Just makes the context ready to be used or freed safely.
SSL/TLS functions.
int mbedtls_net_set_nonblock(mbedtls_net_context *ctx)
Set the socket non-blocking.
int mbedtls_net_recv_timeout(void *ctx, unsigned char *buf, size_t len, uint32_t timeout)
Read at most &#39;len&#39; characters, blocking for at most &#39;timeout&#39; seconds. If no error occurs...
int mbedtls_net_recv(void *ctx, unsigned char *buf, size_t len)
Read at most &#39;len&#39; characters. If no error occurs, the actual amount read is returned.