1 /**
2  * FreeRDP: A Remote Desktop Protocol Implementation
3  * Transmission Control Protocol (TCP)
4  *
5  * Copyright 2011 Vic Lee
6  * Copyright 2011 Marc-Andre Moreau <marcandre.moreau@gmail.com>
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *     http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  */
20 
21 #ifndef FREERDP_LIB_CORE_TCP_H
22 #define FREERDP_LIB_CORE_TCP_H
23 
24 #include <winpr/windows.h>
25 
26 #include <freerdp/types.h>
27 #include <freerdp/settings.h>
28 #include <freerdp/freerdp.h>
29 #include <freerdp/api.h>
30 
31 #include <winpr/crt.h>
32 #include <winpr/synch.h>
33 #include <winpr/stream.h>
34 #include <winpr/winsock.h>
35 #include <winpr/crypto.h>
36 
37 #include <openssl/bio.h>
38 
39 #include <freerdp/utils/ringbuffer.h>
40 
41 #define BIO_TYPE_TSG 65
42 #define BIO_TYPE_SIMPLE 66
43 #define BIO_TYPE_BUFFERED 67
44 
45 #define BIO_C_SET_SOCKET 1101
46 #define BIO_C_GET_SOCKET 1102
47 #define BIO_C_GET_EVENT 1103
48 #define BIO_C_SET_NONBLOCK 1104
49 #define BIO_C_READ_BLOCKED 1105
50 #define BIO_C_WRITE_BLOCKED 1106
51 #define BIO_C_WAIT_READ 1107
52 #define BIO_C_WAIT_WRITE 1108
53 
54 #define BIO_set_socket(b, s, c) BIO_ctrl(b, BIO_C_SET_SOCKET, c, s);
55 #define BIO_get_socket(b, c) BIO_ctrl(b, BIO_C_GET_SOCKET, 0, (char*)c)
56 #define BIO_get_event(b, c) BIO_ctrl(b, BIO_C_GET_EVENT, 0, (char*)c)
57 #define BIO_set_nonblock(b, c) BIO_ctrl(b, BIO_C_SET_NONBLOCK, c, NULL)
58 #define BIO_read_blocked(b) BIO_ctrl(b, BIO_C_READ_BLOCKED, 0, NULL)
59 #define BIO_write_blocked(b) BIO_ctrl(b, BIO_C_WRITE_BLOCKED, 0, NULL)
60 #define BIO_wait_read(b, c) BIO_ctrl(b, BIO_C_WAIT_READ, c, NULL)
61 #define BIO_wait_write(b, c) BIO_ctrl(b, BIO_C_WAIT_WRITE, c, NULL)
62 
63 FREERDP_LOCAL BIO_METHOD* BIO_s_simple_socket(void);
64 FREERDP_LOCAL BIO_METHOD* BIO_s_buffered_socket(void);
65 
66 FREERDP_LOCAL int freerdp_tcp_connect(rdpContext* context, rdpSettings* settings,
67                                       const char* hostname, int port, DWORD timeout);
68 
69 FREERDP_LOCAL char* freerdp_tcp_get_peer_address(SOCKET sockfd);
70 
71 FREERDP_LOCAL struct addrinfo* freerdp_tcp_resolve_host(const char* hostname, int port,
72                                                         int ai_flags);
73 FREERDP_LOCAL char* freerdp_tcp_address_to_string(const struct sockaddr_storage* addr, BOOL* pIPv6);
74 
75 #endif /* FREERDP_LIB_CORE_TCP_H */
76