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 for (i = 0; i < CRYPTO_num_locks(); i++)
82 CRYPTO_set_locking_callback(openssl_lock);
83 #if !defined(WIN32) && OPENSSL_VERSION_NUMBER < 0x10000000
84 CRYPTO_set_id_callback(openssl_thread_id);
92 #if HAVE_THREADS && GNUTLS_VERSION_NUMBER < 0x020b00
93 if (gcry_control(GCRYCTL_ANY_INITIALIZATION_P) == 0)
94 gcry_control(GCRYCTL_SET_THREAD_CBS, &gcry_threads_pthread);
108 if (CRYPTO_get_locking_callback() == openssl_lock) {
110 CRYPTO_set_locking_callback(NULL);
111 for (i = 0; i < CRYPTO_num_locks(); i++)
119 gnutls_global_deinit();
132 if (!ff_network_inited_globally)
134 "network initialization. Please use "
135 "avformat_network_init(), this will "
136 "become mandatory later.\n");
138 if (WSAStartup(
MAKEWORD(1,1), &wsaData))
146 int ev = write ? POLLOUT : POLLIN;
147 struct pollfd p = { .fd = fd, .events = ev, .revents = 0 };
149 ret = poll(&p, 1, 100);
150 return ret < 0 ?
ff_neterrno() : p.revents & (ev | POLLERR | POLLHUP) ? 0 :
AVERROR(EAGAIN);
156 int64_t wait_start = 0;
183 int err = WSAGetLastError();
189 case WSAEPROTONOSUPPORT:
190 return AVERROR(EPROTONOSUPPORT);
193 case WSAECONNREFUSED:
204 if (addr->sa_family == AF_INET) {
205 return IN_MULTICAST(ntohl(((
struct sockaddr_in *)addr)->sin_addr.s_addr));
207 #if HAVE_STRUCT_SOCKADDR_IN6
208 if (addr->sa_family == AF_INET6) {
228 }
while (timeout <= 0 || runs-- > 0);
242 fd = socket(af, type | SOCK_CLOEXEC, proto);
243 if (fd == -1 && errno == EINVAL)
246 fd = socket(af, type, proto);
249 if (fcntl(fd, F_SETFD, FD_CLOEXEC) == -1)
258 socklen_t addrlen,
int timeout,
URLContext *h)
262 struct pollfd lp = { fd, POLLIN, 0 };
263 if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &reuse,
sizeof(reuse))) {
266 ret = bind(fd, addr, addrlen);
278 ret = accept(fd, NULL, NULL);
291 socklen_t addrlen,
int timeout,
URLContext *h,
294 struct pollfd p = {fd, POLLOUT, 0};
301 while ((ret = connect(fd, addr, addrlen))) {
313 optlen =
sizeof(
ret);
314 if (getsockopt (fd, SOL_SOCKET, SO_ERROR, &ret, &optlen))
322 "Connection to %s failed (%s), trying next address\n",
338 if (!strcmp(pattern,
"*"))
341 if (pattern[0] ==
'*')
343 if (pattern[0] ==
'.')
345 len_p = strlen(pattern);
346 len_h = strlen(hostname);
350 if (!strcmp(pattern, &hostname[len_h - len_p])) {
353 if (hostname[len_h - len_p - 1] ==
'.')
372 char *sep, *next = NULL;
373 start += strspn(start,
" ,");
374 sep = start + strcspn(start,
" ,");