/src/coturn/src/ns_turn_defs.h
Line | Count | Source |
1 | | /* |
2 | | * SPDX-License-Identifier: BSD-3-Clause |
3 | | * |
4 | | * https://opensource.org/license/bsd-3-clause |
5 | | * |
6 | | * Copyright (C) 2011, 2012, 2013 Citrix Systems |
7 | | * |
8 | | * All rights reserved. |
9 | | * |
10 | | * Redistribution and use in source and binary forms, with or without |
11 | | * modification, are permitted provided that the following conditions |
12 | | * are met: |
13 | | * 1. Redistributions of source code must retain the above copyright |
14 | | * notice, this list of conditions and the following disclaimer. |
15 | | * 2. Redistributions in binary form must reproduce the above copyright |
16 | | * notice, this list of conditions and the following disclaimer in the |
17 | | * documentation and/or other materials provided with the distribution. |
18 | | * 3. Neither the name of the project nor the names of its contributors |
19 | | * may be used to endorse or promote products derived from this software |
20 | | * without specific prior written permission. |
21 | | * |
22 | | * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND |
23 | | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
24 | | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
25 | | * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE |
26 | | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
27 | | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
28 | | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
29 | | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
30 | | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
31 | | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
32 | | * SUCH DAMAGE. |
33 | | */ |
34 | | |
35 | | #ifndef __IOADEFS__ |
36 | | #define __IOADEFS__ |
37 | | |
38 | | #define TURN_SERVER_VERSION "4.18.0" |
39 | | #define TURN_SERVER_VERSION_NAME "Gorst" |
40 | | #ifndef TURN_SERVER_BUILD_INFO |
41 | | #define TURN_SERVER_BUILD_INFO "" |
42 | | #endif |
43 | | #define TURN_SOFTWARE "Coturn-" TURN_SERVER_VERSION " '" TURN_SERVER_VERSION_NAME "'" TURN_SERVER_BUILD_INFO |
44 | | |
45 | | #if (defined(__unix__) || defined(unix)) && !defined(USG) |
46 | | #include <sys/param.h> |
47 | | #endif |
48 | | |
49 | | #if defined(__APPLE__) |
50 | | #define __APPLE_USE_RFC_3542 |
51 | | #endif |
52 | | |
53 | | #if defined(WINDOWS) |
54 | | #include <process.h> |
55 | | #include <ws2tcpip.h> |
56 | | /* MSVC has no <strings.h>; it spells the POSIX case-insensitive compares with a |
57 | | * leading underscore, in <string.h>. */ |
58 | | #define strcasecmp _stricmp |
59 | | #define strncasecmp _strnicmp |
60 | | #else |
61 | | #include <arpa/inet.h> // IWYU pragma: export |
62 | | #include <net/if.h> // IWYU pragma: export |
63 | | #include <netinet/in.h> // IWYU pragma: export |
64 | | #include <netinet/tcp.h> // IWYU pragma: export |
65 | | #include <strings.h> |
66 | | #include <sys/socket.h> // IWYU pragma: export |
67 | | #include <unistd.h> // IWYU pragma: export |
68 | | #endif |
69 | | |
70 | | #include <ctype.h> |
71 | | #include <errno.h> |
72 | | #include <inttypes.h> |
73 | | #include <stdarg.h> |
74 | | #include <stddef.h> // IWYU pragma: export |
75 | | #include <stdint.h> // IWYU pragma: export |
76 | | #include <stdio.h> |
77 | | #include <stdlib.h> |
78 | | #include <string.h> |
79 | | #include <sys/types.h> |
80 | | #include <time.h> |
81 | | |
82 | | #ifdef __cplusplus |
83 | | extern "C" { |
84 | | #endif |
85 | | |
86 | 6.26M | #define nswap16(s) ntohs(s) |
87 | 42.8k | #define nswap32(ul) ntohl(ul) |
88 | 2 | #define nswap64(ull) ioa_ntoh64(ull) |
89 | | |
90 | 2 | static inline uint64_t _ioa_ntoh64(uint64_t v) { |
91 | 2 | #if BYTE_ORDER == LITTLE_ENDIAN |
92 | 2 | uint8_t *src = (uint8_t *)&v; |
93 | 2 | uint8_t *dst = src + 7; |
94 | 10 | while (src < dst) { |
95 | 8 | uint8_t vdst = *dst; |
96 | 8 | *(dst--) = *src; |
97 | 8 | *(src++) = vdst; |
98 | 8 | } |
99 | | #elif BYTE_ORDER == BIG_ENDIAN |
100 | | /* OK */ |
101 | | #else |
102 | | #error WRONG BYTE_ORDER SETTING |
103 | | #endif |
104 | 2 | return v; |
105 | 2 | } Unexecuted instantiation: FuzzStun.c:_ioa_ntoh64 Unexecuted instantiation: FuzzOpenSSLInit.c:_ioa_ntoh64 Unexecuted instantiation: ns_turn_ioaddr.c:_ioa_ntoh64 ns_turn_msg.c:_ioa_ntoh64 Line | Count | Source | 90 | 2 | static inline uint64_t _ioa_ntoh64(uint64_t v) { | 91 | 2 | #if BYTE_ORDER == LITTLE_ENDIAN | 92 | 2 | uint8_t *src = (uint8_t *)&v; | 93 | 2 | uint8_t *dst = src + 7; | 94 | 10 | while (src < dst) { | 95 | 8 | uint8_t vdst = *dst; | 96 | 8 | *(dst--) = *src; | 97 | 8 | *(src++) = vdst; | 98 | 8 | } | 99 | | #elif BYTE_ORDER == BIG_ENDIAN | 100 | | /* OK */ | 101 | | #else | 102 | | #error WRONG BYTE_ORDER SETTING | 103 | | #endif | 104 | 2 | return v; | 105 | 2 | } |
Unexecuted instantiation: ns_turn_msg_addr.c:_ioa_ntoh64 Unexecuted instantiation: ns_turn_utils.c:_ioa_ntoh64 |
106 | | |
107 | | /* TTL */ |
108 | | #define TTL_IGNORE ((int)(-1)) |
109 | | #define TTL_DEFAULT (64) |
110 | | |
111 | | /* TOS */ |
112 | | #define TOS_IGNORE ((int)(-1)) |
113 | | #define TOS_DEFAULT (0) |
114 | | |
115 | 2 | #define ioa_ntoh64 _ioa_ntoh64 |
116 | | #define ioa_hton64 _ioa_ntoh64 |
117 | | |
118 | | /* Alignment-safe access to network-order (big-endian) wire fields. |
119 | | * |
120 | | * STUN attributes and headers sit at arbitrary byte offsets inside receive |
121 | | * buffers, so casting the byte pointer to a wider integer pointer and |
122 | | * dereferencing it is undefined behavior (SIGBUS on strict-alignment |
123 | | * architectures). These helpers go through memcpy — which compilers fold |
124 | | * into a single load/store — and convert to/from host byte order. |
125 | | * For fields that are NOT byte-swapped (e.g. values kept in network order |
126 | | * or CONNECTION-ID's as-is encoding), use a plain memcpy instead. */ |
127 | 5.97M | static inline uint16_t turn_read_u16(const void *field) { |
128 | 5.97M | uint16_t v; |
129 | 5.97M | memcpy(&v, field, sizeof(v)); |
130 | 5.97M | return nswap16(v); |
131 | 5.97M | } Unexecuted instantiation: FuzzStun.c:turn_read_u16 Unexecuted instantiation: FuzzOpenSSLInit.c:turn_read_u16 Unexecuted instantiation: ns_turn_ioaddr.c:turn_read_u16 ns_turn_msg.c:turn_read_u16 Line | Count | Source | 127 | 5.97M | static inline uint16_t turn_read_u16(const void *field) { | 128 | 5.97M | uint16_t v; | 129 | 5.97M | memcpy(&v, field, sizeof(v)); | 130 | | return nswap16(v); | 131 | 5.97M | } |
Unexecuted instantiation: ns_turn_msg_addr.c:turn_read_u16 Unexecuted instantiation: ns_turn_utils.c:turn_read_u16 |
132 | | |
133 | 15.0k | static inline uint32_t turn_read_u32(const void *field) { |
134 | 15.0k | uint32_t v; |
135 | 15.0k | memcpy(&v, field, sizeof(v)); |
136 | 15.0k | return nswap32(v); |
137 | 15.0k | } Unexecuted instantiation: FuzzStun.c:turn_read_u32 Unexecuted instantiation: FuzzOpenSSLInit.c:turn_read_u32 Unexecuted instantiation: ns_turn_ioaddr.c:turn_read_u32 ns_turn_msg.c:turn_read_u32 Line | Count | Source | 133 | 15.0k | static inline uint32_t turn_read_u32(const void *field) { | 134 | 15.0k | uint32_t v; | 135 | 15.0k | memcpy(&v, field, sizeof(v)); | 136 | | return nswap32(v); | 137 | 15.0k | } |
Unexecuted instantiation: ns_turn_msg_addr.c:turn_read_u32 Unexecuted instantiation: ns_turn_utils.c:turn_read_u32 |
138 | | |
139 | 2 | static inline uint64_t turn_read_u64(const void *field) { |
140 | 2 | uint64_t v; |
141 | 2 | memcpy(&v, field, sizeof(v)); |
142 | 2 | return nswap64(v); |
143 | 2 | } Unexecuted instantiation: FuzzStun.c:turn_read_u64 Unexecuted instantiation: FuzzOpenSSLInit.c:turn_read_u64 Unexecuted instantiation: ns_turn_ioaddr.c:turn_read_u64 ns_turn_msg.c:turn_read_u64 Line | Count | Source | 139 | 2 | static inline uint64_t turn_read_u64(const void *field) { | 140 | 2 | uint64_t v; | 141 | 2 | memcpy(&v, field, sizeof(v)); | 142 | 2 | return nswap64(v); | 143 | 2 | } |
Unexecuted instantiation: ns_turn_msg_addr.c:turn_read_u64 Unexecuted instantiation: ns_turn_utils.c:turn_read_u64 |
144 | | |
145 | 262k | static inline void turn_write_u16(void *field, uint16_t v) { |
146 | 262k | const uint16_t raw = nswap16(v); |
147 | 262k | memcpy(field, &raw, sizeof(raw)); |
148 | 262k | } Unexecuted instantiation: FuzzStun.c:turn_write_u16 Unexecuted instantiation: FuzzOpenSSLInit.c:turn_write_u16 Unexecuted instantiation: ns_turn_ioaddr.c:turn_write_u16 ns_turn_msg.c:turn_write_u16 Line | Count | Source | 145 | 262k | static inline void turn_write_u16(void *field, uint16_t v) { | 146 | | const uint16_t raw = nswap16(v); | 147 | 262k | memcpy(field, &raw, sizeof(raw)); | 148 | 262k | } |
Unexecuted instantiation: ns_turn_msg_addr.c:turn_write_u16 Unexecuted instantiation: ns_turn_utils.c:turn_write_u16 |
149 | | |
150 | 20.7k | static inline void turn_write_u32(void *field, uint32_t v) { |
151 | 20.7k | const uint32_t raw = nswap32(v); |
152 | 20.7k | memcpy(field, &raw, sizeof(raw)); |
153 | 20.7k | } Unexecuted instantiation: FuzzStun.c:turn_write_u32 Unexecuted instantiation: FuzzOpenSSLInit.c:turn_write_u32 Unexecuted instantiation: ns_turn_ioaddr.c:turn_write_u32 ns_turn_msg.c:turn_write_u32 Line | Count | Source | 150 | 20.7k | static inline void turn_write_u32(void *field, uint32_t v) { | 151 | | const uint32_t raw = nswap32(v); | 152 | 20.7k | memcpy(field, &raw, sizeof(raw)); | 153 | 20.7k | } |
Unexecuted instantiation: ns_turn_msg_addr.c:turn_write_u32 Unexecuted instantiation: ns_turn_utils.c:turn_write_u32 |
154 | | |
155 | 0 | static inline void turn_write_u64(void *field, uint64_t v) { |
156 | 0 | const uint64_t raw = nswap64(v); |
157 | 0 | memcpy(field, &raw, sizeof(raw)); |
158 | 0 | } Unexecuted instantiation: FuzzStun.c:turn_write_u64 Unexecuted instantiation: FuzzOpenSSLInit.c:turn_write_u64 Unexecuted instantiation: ns_turn_ioaddr.c:turn_write_u64 Unexecuted instantiation: ns_turn_msg.c:turn_write_u64 Unexecuted instantiation: ns_turn_msg_addr.c:turn_write_u64 Unexecuted instantiation: ns_turn_utils.c:turn_write_u64 |
159 | | |
160 | | #if defined(WINDOWS) |
161 | | static inline int socket_errno(void) { return WSAGetLastError(); } |
162 | | static inline int socket_enomem(void) { return socket_errno() == WSA_NOT_ENOUGH_MEMORY; } |
163 | | static inline int socket_eintr(void) { return socket_errno() == WSAEINTR; } |
164 | | static inline int socket_ebadf(void) { return socket_errno() == WSAEBADF; } |
165 | | static inline int socket_eacces(void) { return socket_errno() == WSAEACCES; } |
166 | | static inline int socket_enobufs(void) { return socket_errno() == WSAENOBUFS; } |
167 | | static inline int socket_eagain(void) { return socket_errno() == WSATRY_AGAIN; } |
168 | | static inline int socket_ewouldblock(void) { return socket_errno() == WSAEWOULDBLOCK; } |
169 | | static inline int socket_einprogress(void) { return socket_errno() == WSAEINPROGRESS; } |
170 | | static inline int socket_econnreset(void) { return socket_errno() == WSAECONNRESET; } |
171 | | static inline int socket_econnrefused(void) { return socket_errno() == WSAECONNREFUSED; } |
172 | | static inline int socket_ehostdown(void) { return socket_errno() == WSAEHOSTDOWN; } |
173 | | static inline int socket_emsgsize(void) { return socket_errno() == WSAEMSGSIZE; } |
174 | | #else |
175 | 0 | static inline int socket_errno(void) { return errno; }Unexecuted instantiation: FuzzStun.c:socket_errno Unexecuted instantiation: FuzzOpenSSLInit.c:socket_errno Unexecuted instantiation: ns_turn_ioaddr.c:socket_errno Unexecuted instantiation: ns_turn_msg.c:socket_errno Unexecuted instantiation: ns_turn_msg_addr.c:socket_errno Unexecuted instantiation: ns_turn_utils.c:socket_errno |
176 | 0 | static inline int socket_eperm(void) { return socket_errno() == EPERM; }Unexecuted instantiation: FuzzStun.c:socket_eperm Unexecuted instantiation: FuzzOpenSSLInit.c:socket_eperm Unexecuted instantiation: ns_turn_ioaddr.c:socket_eperm Unexecuted instantiation: ns_turn_msg.c:socket_eperm Unexecuted instantiation: ns_turn_msg_addr.c:socket_eperm Unexecuted instantiation: ns_turn_utils.c:socket_eperm |
177 | 0 | static inline int socket_enomem(void) { return socket_errno() == ENOMEM; }Unexecuted instantiation: FuzzStun.c:socket_enomem Unexecuted instantiation: FuzzOpenSSLInit.c:socket_enomem Unexecuted instantiation: ns_turn_ioaddr.c:socket_enomem Unexecuted instantiation: ns_turn_msg.c:socket_enomem Unexecuted instantiation: ns_turn_msg_addr.c:socket_enomem Unexecuted instantiation: ns_turn_utils.c:socket_enomem |
178 | 0 | static inline int socket_eintr(void) { return socket_errno() == EINTR; }Unexecuted instantiation: FuzzStun.c:socket_eintr Unexecuted instantiation: FuzzOpenSSLInit.c:socket_eintr Unexecuted instantiation: ns_turn_ioaddr.c:socket_eintr Unexecuted instantiation: ns_turn_msg.c:socket_eintr Unexecuted instantiation: ns_turn_msg_addr.c:socket_eintr Unexecuted instantiation: ns_turn_utils.c:socket_eintr |
179 | 0 | static inline int socket_ebadf(void) { return socket_errno() == EBADF; }Unexecuted instantiation: FuzzStun.c:socket_ebadf Unexecuted instantiation: FuzzOpenSSLInit.c:socket_ebadf Unexecuted instantiation: ns_turn_ioaddr.c:socket_ebadf Unexecuted instantiation: ns_turn_msg.c:socket_ebadf Unexecuted instantiation: ns_turn_msg_addr.c:socket_ebadf Unexecuted instantiation: ns_turn_utils.c:socket_ebadf |
180 | 0 | static inline int socket_eacces(void) { return socket_errno() == EACCES; }Unexecuted instantiation: FuzzStun.c:socket_eacces Unexecuted instantiation: FuzzOpenSSLInit.c:socket_eacces Unexecuted instantiation: ns_turn_ioaddr.c:socket_eacces Unexecuted instantiation: ns_turn_msg.c:socket_eacces Unexecuted instantiation: ns_turn_msg_addr.c:socket_eacces Unexecuted instantiation: ns_turn_utils.c:socket_eacces |
181 | 0 | static inline int socket_enobufs(void) { return socket_errno() == ENOBUFS; }Unexecuted instantiation: FuzzStun.c:socket_enobufs Unexecuted instantiation: FuzzOpenSSLInit.c:socket_enobufs Unexecuted instantiation: ns_turn_ioaddr.c:socket_enobufs Unexecuted instantiation: ns_turn_msg.c:socket_enobufs Unexecuted instantiation: ns_turn_msg_addr.c:socket_enobufs Unexecuted instantiation: ns_turn_utils.c:socket_enobufs |
182 | 0 | static inline int socket_eagain(void) { return socket_errno() == EAGAIN; }Unexecuted instantiation: FuzzStun.c:socket_eagain Unexecuted instantiation: FuzzOpenSSLInit.c:socket_eagain Unexecuted instantiation: ns_turn_ioaddr.c:socket_eagain Unexecuted instantiation: ns_turn_msg.c:socket_eagain Unexecuted instantiation: ns_turn_msg_addr.c:socket_eagain Unexecuted instantiation: ns_turn_utils.c:socket_eagain |
183 | | #if defined(EWOULDBLOCK) |
184 | 0 | static inline int socket_ewouldblock(void) { return socket_errno() == EWOULDBLOCK; }Unexecuted instantiation: FuzzStun.c:socket_ewouldblock Unexecuted instantiation: FuzzOpenSSLInit.c:socket_ewouldblock Unexecuted instantiation: ns_turn_ioaddr.c:socket_ewouldblock Unexecuted instantiation: ns_turn_msg.c:socket_ewouldblock Unexecuted instantiation: ns_turn_msg_addr.c:socket_ewouldblock Unexecuted instantiation: ns_turn_utils.c:socket_ewouldblock |
185 | | #else |
186 | | static inline int socket_ewouldblock(void) { return socket_errno() == EAGAIN; } |
187 | | #endif |
188 | 0 | static inline int socket_einprogress(void) { return socket_errno() == EINPROGRESS; }Unexecuted instantiation: FuzzStun.c:socket_einprogress Unexecuted instantiation: FuzzOpenSSLInit.c:socket_einprogress Unexecuted instantiation: ns_turn_ioaddr.c:socket_einprogress Unexecuted instantiation: ns_turn_msg.c:socket_einprogress Unexecuted instantiation: ns_turn_msg_addr.c:socket_einprogress Unexecuted instantiation: ns_turn_utils.c:socket_einprogress |
189 | 0 | static inline int socket_econnreset(void) { return socket_errno() == ECONNRESET; }Unexecuted instantiation: FuzzStun.c:socket_econnreset Unexecuted instantiation: FuzzOpenSSLInit.c:socket_econnreset Unexecuted instantiation: ns_turn_ioaddr.c:socket_econnreset Unexecuted instantiation: ns_turn_msg.c:socket_econnreset Unexecuted instantiation: ns_turn_msg_addr.c:socket_econnreset Unexecuted instantiation: ns_turn_utils.c:socket_econnreset |
190 | 0 | static inline int socket_econnrefused(void) { return socket_errno() == ECONNREFUSED; }Unexecuted instantiation: FuzzStun.c:socket_econnrefused Unexecuted instantiation: FuzzOpenSSLInit.c:socket_econnrefused Unexecuted instantiation: ns_turn_ioaddr.c:socket_econnrefused Unexecuted instantiation: ns_turn_msg.c:socket_econnrefused Unexecuted instantiation: ns_turn_msg_addr.c:socket_econnrefused Unexecuted instantiation: ns_turn_utils.c:socket_econnrefused |
191 | 0 | static inline int socket_ehostdown(void) { return socket_errno() == EHOSTDOWN; }Unexecuted instantiation: FuzzStun.c:socket_ehostdown Unexecuted instantiation: FuzzOpenSSLInit.c:socket_ehostdown Unexecuted instantiation: ns_turn_ioaddr.c:socket_ehostdown Unexecuted instantiation: ns_turn_msg.c:socket_ehostdown Unexecuted instantiation: ns_turn_msg_addr.c:socket_ehostdown Unexecuted instantiation: ns_turn_utils.c:socket_ehostdown |
192 | 0 | static inline int socket_emsgsize(void) { return socket_errno() == EMSGSIZE; }Unexecuted instantiation: FuzzStun.c:socket_emsgsize Unexecuted instantiation: FuzzOpenSSLInit.c:socket_emsgsize Unexecuted instantiation: ns_turn_ioaddr.c:socket_emsgsize Unexecuted instantiation: ns_turn_msg.c:socket_emsgsize Unexecuted instantiation: ns_turn_msg_addr.c:socket_emsgsize Unexecuted instantiation: ns_turn_utils.c:socket_emsgsize |
193 | | #endif |
194 | | |
195 | | #define BUFFEREVENT_FREE(be) \ |
196 | | do { \ |
197 | | if (be) { \ |
198 | | bufferevent_flush(be, EV_READ | EV_WRITE, BEV_FLUSH); \ |
199 | | bufferevent_disable(be, EV_READ | EV_WRITE); \ |
200 | | bufferevent_free(be); \ |
201 | | be = NULL; \ |
202 | | } \ |
203 | | } while (0) |
204 | | |
205 | 0 | #define turn_time() ((turn_time_t)time(NULL)) |
206 | | |
207 | | typedef int vint; |
208 | | typedef vint *vintp; |
209 | | |
210 | | typedef uint32_t turn_time_t; |
211 | | |
212 | | #define turn_time_before(t1, t2) ((((int32_t)(t1)) - ((int32_t)(t2))) < 0) |
213 | | |
214 | | #if !defined(UNUSED_ARG) |
215 | | #define UNUSED_ARG(A) \ |
216 | 31.6k | do { \ |
217 | 31.6k | A = A; \ |
218 | 31.6k | } while (0) |
219 | | #endif |
220 | | |
221 | 73.7k | #define MAX_STUN_MESSAGE_SIZE (65507) |
222 | | #define STUN_BUFFER_SIZE (MAX_STUN_MESSAGE_SIZE) |
223 | | #define UDP_STUN_BUFFER_SIZE (1024 << 4) |
224 | | |
225 | | #define NONCE_LENGTH_32BITS (4) |
226 | | |
227 | | #define DEFAULT_STUN_PORT (3478) |
228 | | #define DEFAULT_STUN_TLS_PORT (5349) |
229 | | |
230 | | #if BYTE_ORDER == LITTLE_ENDIAN |
231 | | #define DEFAULT_STUN_PORT_NBO (0x960D) |
232 | | #elif BYTE_ORDER == BIG_ENDIAN |
233 | | #define DEFAULT_STUN_PORT_NBO (0x0D96) |
234 | | #else |
235 | | #error WRONG BYTE_ORDER SETTING |
236 | | #endif |
237 | | |
238 | | // NOLINTBEGIN(clang-diagnostic-string-compare) |
239 | | #define STRCPY(dst, src) \ |
240 | 23.2k | do { \ |
241 | 23.2k | if ((const char *)(dst) != (const char *)(src)) { \ |
242 | 23.2k | if (sizeof(dst) == sizeof(char *)) \ |
243 | 23.2k | strcpy(((char *)(dst)), (const char *)(src)); \ |
244 | 23.2k | else { \ |
245 | 23.2k | size_t szdst = sizeof((dst)); \ |
246 | 23.2k | strncpy((char *)(dst), (const char *)(src), szdst); \ |
247 | 23.2k | ((char *)(dst))[szdst - 1] = 0; \ |
248 | 23.2k | } \ |
249 | 23.2k | } \ |
250 | 23.2k | } while (0) |
251 | | // NOLINTEND(clang-diagnostic-string-compare) |
252 | | |
253 | | //////////////// Bufferevents ///////////////////// |
254 | | |
255 | | #define TURN_BUFFEREVENTS_OPTIONS (BEV_OPT_DEFER_CALLBACKS | BEV_OPT_THREADSAFE | BEV_OPT_UNLOCK_CALLBACKS) |
256 | | |
257 | | //////////////// KERNEL-LEVEL CHANNEL HANDLERS ///////// |
258 | | |
259 | | #if !defined(TURN_CHANNEL_HANDLER_KERNEL) |
260 | | #define TURN_CHANNEL_HANDLER_KERNEL void * |
261 | | #endif |
262 | | |
263 | | #if !defined(CREATE_TURN_CHANNEL_KERNEL) |
264 | | #define CREATE_TURN_CHANNEL_KERNEL(channel_number, address_family_client, address_family_peer, protocol_client, \ |
265 | | client_addr, local_addr, local_relay_addr, peer_addr) \ |
266 | | ((TURN_CHANNEL_HANDLER_KERNEL)(1)) |
267 | | #endif |
268 | | |
269 | | #if !defined(DELETE_TURN_CHANNEL_KERNEL) |
270 | | #define DELETE_TURN_CHANNEL_KERNEL(handler) |
271 | | #endif |
272 | | |
273 | | //////////////////////////////////////////////////////// |
274 | | |
275 | | #if !defined(IPPROTO_SCTP) && !defined(TURN_NO_SCTP) |
276 | | #define TURN_NO_SCTP |
277 | | #endif |
278 | | |
279 | | #define CLIENT_DGRAM_SOCKET_TYPE SOCK_DGRAM |
280 | | #define CLIENT_DGRAM_SOCKET_PROTOCOL IPPROTO_IP |
281 | | |
282 | | #define CLIENT_STREAM_SOCKET_TYPE SOCK_STREAM |
283 | | #define CLIENT_STREAM_SOCKET_PROTOCOL IPPROTO_IP |
284 | | |
285 | | #define SCTP_CLIENT_STREAM_SOCKET_TYPE SOCK_STREAM |
286 | | |
287 | | #if !defined(TURN_NO_SCTP) |
288 | | #define SCTP_CLIENT_STREAM_SOCKET_PROTOCOL IPPROTO_SCTP |
289 | | #else |
290 | | #define SCTP_CLIENT_STREAM_SOCKET_PROTOCOL IPPROTO_IP |
291 | | #endif |
292 | | |
293 | | #define RELAY_DGRAM_SOCKET_TYPE SOCK_DGRAM |
294 | | #define RELAY_DGRAM_SOCKET_PROTOCOL IPPROTO_IP |
295 | | #define RELAY_STREAM_SOCKET_TYPE SOCK_STREAM |
296 | | #define RELAY_STREAM_SOCKET_PROTOCOL IPPROTO_IP |
297 | | |
298 | | #define ADMIN_STREAM_SOCKET_TYPE SOCK_STREAM |
299 | | #define ADMIN_STREAM_SOCKET_PROTOCOL IPPROTO_IP |
300 | | |
301 | | //////////////////////////////////////////////////////// |
302 | | |
303 | | #ifdef __cplusplus |
304 | | } |
305 | | #endif |
306 | | |
307 | | #endif |
308 | | /* __IODEFS__ */ |