40 #include <openssl/ssl.h>
41 static int openssl_init;
43 #include <openssl/crypto.h>
45 static void openssl_lock(
int mode,
int type,
const char *file,
int line)
47 if (mode & CRYPTO_LOCK)
52 #if !defined(WIN32) && OPENSSL_VERSION_NUMBER < 0x10000000
53 static unsigned long openssl_thread_id(
void)
55 return (intptr_t) pthread_self();
61 #include <gnutls/gnutls.h>
62 #if HAVE_THREADS && GNUTLS_VERSION_NUMBER <= 0x020b00
65 GCRY_THREAD_OPTION_PTHREAD_IMPL;
75 SSL_load_error_strings();
77 if (!CRYPTO_get_locking_callback()) {
80 if (!openssl_mutexes) {
84 for (i = 0; i < CRYPTO_num_locks(); i++)
86 CRYPTO_set_locking_callback(openssl_lock);
87 #if !defined(WIN32) && OPENSSL_VERSION_NUMBER < 0x10000000
88 CRYPTO_set_id_callback(openssl_thread_id);
96 #if HAVE_THREADS && GNUTLS_VERSION_NUMBER < 0x020b00
97 if (gcry_control(GCRYCTL_ANY_INITIALIZATION_P) == 0)
98 gcry_control(GCRYCTL_SET_THREAD_CBS, &gcry_threads_pthread);
100 gnutls_global_init();
114 if (CRYPTO_get_locking_callback() == openssl_lock) {
116 CRYPTO_set_locking_callback(
NULL);
117 for (i = 0; i < CRYPTO_num_locks(); i++)
125 gnutls_global_deinit();
138 if (!ff_network_inited_globally)
140 "network initialization. Please use "
141 "avformat_network_init(), this will "
142 "become mandatory later.\n");
144 if (WSAStartup(
MAKEWORD(1,1), &wsaData))
152 int ev = write ? POLLOUT : POLLIN;
153 struct pollfd p = { .fd = fd, .events = ev, .revents = 0 };
155 ret = poll(&p, 1, 100);
156 return ret < 0 ?
ff_neterrno() : p.revents & (ev | POLLERR | POLLHUP) ? 0 :
AVERROR(EAGAIN);
162 int64_t wait_start = 0;
189 int err = WSAGetLastError();
195 case WSAEPROTONOSUPPORT:
196 return AVERROR(EPROTONOSUPPORT);
199 case WSAECONNREFUSED:
210 if (addr->sa_family == AF_INET) {
211 return IN_MULTICAST(ntohl(((
struct sockaddr_in *)addr)->sin_addr.s_addr));
213 #if HAVE_STRUCT_SOCKADDR_IN6
214 if (addr->sa_family == AF_INET6) {
234 }
while (timeout <= 0 || runs-- > 0);
248 fd = socket(af, type | SOCK_CLOEXEC, proto);
249 if (fd == -1 && errno == EINVAL)
252 fd = socket(af, type, proto);
255 if (fcntl(fd, F_SETFD, FD_CLOEXEC) == -1)
264 socklen_t addrlen,
int timeout,
URLContext *h)
268 struct pollfd lp = { fd, POLLIN, 0 };
269 if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &reuse,
sizeof(reuse))) {
272 ret = bind(fd, addr, addrlen);
297 socklen_t addrlen,
int timeout,
URLContext *h,
300 struct pollfd p = {fd, POLLOUT, 0};
307 while ((ret = connect(fd, addr, addrlen))) {
319 optlen =
sizeof(
ret);
320 if (getsockopt (fd, SOL_SOCKET, SO_ERROR, &ret, &optlen))
328 "Connection to %s failed (%s), trying next address\n",
344 if (!strcmp(pattern,
"*"))
347 if (pattern[0] ==
'*')
349 if (pattern[0] ==
'.')
351 len_p = strlen(pattern);
352 len_h = strlen(hostname);
356 if (!strcmp(pattern, &hostname[len_h - len_p])) {
359 if (hostname[len_h - len_p - 1] ==
'.')
378 char *sep, *next =
NULL;
379 start += strspn(start,
" ,");
380 sep = start + strcspn(start,
" ,");