40 #include <openssl/ssl.h>
41 static int openssl_init;
43 #include <openssl/crypto.h>
46 static void openssl_lock(
int mode,
int type,
const char *file,
int line)
48 if (mode & CRYPTO_LOCK)
53 #if !defined(WIN32) && OPENSSL_VERSION_NUMBER < 0x10000000
54 static unsigned long openssl_thread_id(
void)
56 return (intptr_t) pthread_self();
62 #include <gnutls/gnutls.h>
63 #if HAVE_THREADS && GNUTLS_VERSION_NUMBER <= 0x020b00
66 GCRY_THREAD_OPTION_PTHREAD_IMPL;
76 SSL_load_error_strings();
78 if (!CRYPTO_get_locking_callback()) {
81 for (i = 0; i < CRYPTO_num_locks(); i++)
83 CRYPTO_set_locking_callback(openssl_lock);
84 #if !defined(WIN32) && OPENSSL_VERSION_NUMBER < 0x10000000
85 CRYPTO_set_id_callback(openssl_thread_id);
93 #if HAVE_THREADS && GNUTLS_VERSION_NUMBER < 0x020b00
94 if (gcry_control(GCRYCTL_ANY_INITIALIZATION_P) == 0)
95 gcry_control(GCRYCTL_SET_THREAD_CBS, &gcry_threads_pthread);
109 if (CRYPTO_get_locking_callback() == openssl_lock) {
111 CRYPTO_set_locking_callback(NULL);
112 for (i = 0; i < CRYPTO_num_locks(); i++)
120 gnutls_global_deinit();
133 if (!ff_network_inited_globally)
135 "network initialization. Please use "
136 "avformat_network_init(), this will "
137 "become mandatory later.\n");
139 if (WSAStartup(
MAKEWORD(1,1), &wsaData))
147 int ev = write ? POLLOUT : POLLIN;
148 struct pollfd p = { .fd = fd, .events = ev, .revents = 0 };
150 ret = poll(&p, 1, 100);
151 return ret < 0 ?
ff_neterrno() : p.revents & (ev | POLLERR | POLLHUP) ? 0 :
AVERROR(EAGAIN);
157 int64_t wait_start = 0;
184 int err = WSAGetLastError();
190 case WSAEPROTONOSUPPORT:
191 return AVERROR(EPROTONOSUPPORT);
194 case WSAECONNREFUSED:
205 if (addr->sa_family == AF_INET) {
206 return IN_MULTICAST(ntohl(((
struct sockaddr_in *)addr)->sin_addr.s_addr));
208 #if HAVE_STRUCT_SOCKADDR_IN6
209 if (addr->sa_family == AF_INET6) {
229 }
while (timeout <= 0 || runs-- > 0);
239 socklen_t addrlen,
int timeout,
URLContext *h)
243 struct pollfd lp = { fd, POLLIN, 0 };
244 if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &reuse,
sizeof(reuse))) {
247 ret = bind(fd, addr, addrlen);
259 ret = accept(fd, NULL, NULL);
270 socklen_t addrlen,
int timeout,
URLContext *h)
272 struct pollfd p = {fd, POLLOUT, 0};
278 while ((ret = connect(fd, addr, addrlen))) {
290 optlen =
sizeof(
ret);
291 if (getsockopt (fd, SOL_SOCKET, SO_ERROR, &ret, &optlen))
298 "Connection to %s failed: %s\n",
311 if (!strcmp(pattern,
"*"))
314 if (pattern[0] ==
'*')
316 if (pattern[0] ==
'.')
318 len_p = strlen(pattern);
319 len_h = strlen(hostname);
323 if (!strcmp(pattern, &hostname[len_h - len_p])) {
326 if (hostname[len_h - len_p - 1] ==
'.')
345 char *sep, *next = NULL;
346 start += strspn(start,
" ,");
347 sep = start + strcspn(start,
" ,");