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()) {
82 for (i = 0; i < CRYPTO_num_locks(); i++)
84 CRYPTO_set_locking_callback(openssl_lock);
85 #if !defined(WIN32) && OPENSSL_VERSION_NUMBER < 0x10000000
86 CRYPTO_set_id_callback(openssl_thread_id);
94 #if HAVE_THREADS && GNUTLS_VERSION_NUMBER < 0x020b00
95 if (gcry_control(GCRYCTL_ANY_INITIALIZATION_P) == 0)
96 gcry_control(GCRYCTL_SET_THREAD_CBS, &gcry_threads_pthread);
112 if (CRYPTO_get_locking_callback() == openssl_lock) {
114 CRYPTO_set_locking_callback(
NULL);
115 for (i = 0; i < CRYPTO_num_locks(); i++)
123 gnutls_global_deinit();
136 if (!ff_network_inited_globally)
138 "network initialization. Please use "
139 "avformat_network_init(), this will "
140 "become mandatory later.\n");
142 if (WSAStartup(
MAKEWORD(1,1), &wsaData))
150 int ev = write ? POLLOUT : POLLIN;
151 struct pollfd p = { .fd = fd, .events = ev, .revents = 0 };
153 ret = poll(&p, 1, 100);
154 return ret < 0 ?
ff_neterrno() : p.revents & (ev | POLLERR | POLLHUP) ? 0 :
AVERROR(EAGAIN);
160 int64_t wait_start = 0;
187 int err = WSAGetLastError();
193 case WSAEPROTONOSUPPORT:
194 return AVERROR(EPROTONOSUPPORT);
197 case WSAECONNREFUSED:
208 if (addr->sa_family == AF_INET) {
209 return IN_MULTICAST(ntohl(((
struct sockaddr_in *)addr)->sin_addr.s_addr));
211 #if HAVE_STRUCT_SOCKADDR_IN6
212 if (addr->sa_family == AF_INET6) {
232 }
while (timeout <= 0 || runs-- > 0);
246 fd = socket(af, type | SOCK_CLOEXEC, proto);
247 if (fd == -1 && errno == EINVAL)
250 fd = socket(af, type, proto);
253 if (fcntl(fd, F_SETFD, FD_CLOEXEC) == -1)
262 socklen_t addrlen,
int timeout,
URLContext *h)
266 struct pollfd lp = { fd, POLLIN, 0 };
267 if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &reuse,
sizeof(reuse))) {
270 ret = bind(fd, addr, addrlen);
295 socklen_t addrlen,
int timeout,
URLContext *h,
298 struct pollfd p = {fd, POLLOUT, 0};
305 while ((ret = connect(fd, addr, addrlen))) {
317 optlen =
sizeof(
ret);
318 if (getsockopt (fd, SOL_SOCKET, SO_ERROR, &ret, &optlen))
326 "Connection to %s failed (%s), trying next address\n",
342 if (!strcmp(pattern,
"*"))
345 if (pattern[0] ==
'*')
347 if (pattern[0] ==
'.')
349 len_p = strlen(pattern);
350 len_h = strlen(hostname);
354 if (!strcmp(pattern, &hostname[len_h - len_p])) {
357 if (hostname[len_h - len_p - 1] ==
'.')
376 char *sep, *next =
NULL;
377 start += strspn(start,
" ,");
378 sep = start + strcspn(start,
" ,");