mbed TLS v2.7.6
net_sockets.h
Go to the documentation of this file.
1 
6 /*
7  * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
8  * SPDX-License-Identifier: Apache-2.0
9  *
10  * Licensed under the Apache License, Version 2.0 (the "License"); you may
11  * not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  * http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
18  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  *
22  * This file is part of mbed TLS (https://tls.mbed.org)
23  */
24 #ifndef MBEDTLS_NET_SOCKETS_H
25 #define MBEDTLS_NET_SOCKETS_H
26 
27 #if !defined(MBEDTLS_CONFIG_FILE)
28 #include "config.h"
29 #else
30 #include MBEDTLS_CONFIG_FILE
31 #endif
32 
33 #include "ssl.h"
34 
35 #include <stddef.h>
36 #include <stdint.h>
37 
38 #define MBEDTLS_ERR_NET_SOCKET_FAILED -0x0042
39 #define MBEDTLS_ERR_NET_CONNECT_FAILED -0x0044
40 #define MBEDTLS_ERR_NET_BIND_FAILED -0x0046
41 #define MBEDTLS_ERR_NET_LISTEN_FAILED -0x0048
42 #define MBEDTLS_ERR_NET_ACCEPT_FAILED -0x004A
43 #define MBEDTLS_ERR_NET_RECV_FAILED -0x004C
44 #define MBEDTLS_ERR_NET_SEND_FAILED -0x004E
45 #define MBEDTLS_ERR_NET_CONN_RESET -0x0050
46 #define MBEDTLS_ERR_NET_UNKNOWN_HOST -0x0052
47 #define MBEDTLS_ERR_NET_BUFFER_TOO_SMALL -0x0043
48 #define MBEDTLS_ERR_NET_INVALID_CONTEXT -0x0045
50 #define MBEDTLS_NET_LISTEN_BACKLOG 10
52 #define MBEDTLS_NET_PROTO_TCP 0
53 #define MBEDTLS_NET_PROTO_UDP 1
55 #ifdef __cplusplus
56 extern "C" {
57 #endif
58 
66 typedef struct
67 {
68  int fd;
69 }
71 
79 
95 int mbedtls_net_connect( mbedtls_net_context *ctx, const char *host, const char *port, int proto );
96 
114 int mbedtls_net_bind( mbedtls_net_context *ctx, const char *bind_ip, const char *port, int proto );
115 
133  mbedtls_net_context *client_ctx,
134  void *client_ip, size_t buf_size, size_t *ip_len );
135 
144 
153 
162 void mbedtls_net_usleep( unsigned long usec );
163 
176 int mbedtls_net_recv( void *ctx, unsigned char *buf, size_t len );
177 
190 int mbedtls_net_send( void *ctx, const unsigned char *buf, size_t len );
191 
213 int mbedtls_net_recv_timeout( void *ctx, unsigned char *buf, size_t len,
214  uint32_t timeout );
215 
222 
223 #ifdef __cplusplus
224 }
225 #endif
226 
227 #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.