#include <errno.h>
#include <stdint.h>
#include "config.h"
#include "libavutil/error.h"
#include "os_support.h"
#include "avio.h"
#include "url.h"
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <netdb.h>
Go to the source code of this file.
Data Structures
Macros
#define
IN_MULTICAST(
a) ((((uint32_t)(
a)) & 0xf0000000) == 0xe0000000)
Functions
This works similarly to ff_network_wait_fd, but waits up to 'timeout' microseconds Uses ff_network_wait_fd in a loop.
More...
Waits for up to 'timeout' microseconds.
More...
int
ff_getnameinfo (const struct sockaddr *sa, int salen, char *host, int hostlen, char *serv, int servlen, int
flags)
Bind to a file descriptor and poll for a connection.
More...
int
ff_listen (int fd, const struct sockaddr *addr, socklen_t addrlen, void *logctx)
Bind to a file descriptor to an address without accepting connections.
More...
Poll for a single connection on the passed file descriptor.
More...
Connect to a file descriptor and poll for result.
More...
Connect to any of the given addrinfo addresses, with multiple attempts running in parallel.
More...
This function is identical to ff_udp_set_remote_url, except that it takes a sockaddr directly.
More...
Macro Definition Documentation
◆ ff_neterrno
#define ff_neterrno
(
)
AVERROR(errno)
◆ MSG_NOSIGNAL
◆ EAI_AGAIN
◆ EAI_BADFLAGS
◆ EAI_FAIL
◆ EAI_FAMILY
◆ EAI_MEMORY
◆ EAI_NODATA
◆ EAI_NONAME
◆ EAI_SERVICE
◆ EAI_SOCKTYPE
◆ AI_PASSIVE
◆ AI_CANONNAME
◆ AI_NUMERICHOST
◆ NI_NOFQDN
◆ NI_NUMERICHOST
◆ NI_NAMERQD
◆ NI_NUMERICSERV
◆ NI_DGRAM
◆ getaddrinfo
◆ freeaddrinfo
◆ getnameinfo
◆ gai_strerror
◆ INADDR_LOOPBACK
#define INADDR_LOOPBACK 0x7f000001
◆ INET_ADDRSTRLEN
#define INET_ADDRSTRLEN 16
◆ INET6_ADDRSTRLEN
◆ IN_MULTICAST
#define IN_MULTICAST
(
a )
((((uint32_t)(
a)) & 0xf0000000) == 0xe0000000)
◆ IN6_IS_ADDR_MULTICAST
#define IN6_IS_ADDR_MULTICAST
(
a )
(((uint8_t *) (
a))[0] == 0xff)
◆ POLLING_TIME
Function Documentation
◆ ff_socket_nonblock()
int ff_socket_nonblock
(
int
socket,
int
enable
)
◆ ff_network_init()
int ff_network_init
(
void
)
◆ ff_network_close()
void ff_network_close
(
void
)
◆ ff_tls_init()
◆ ff_tls_deinit()
void ff_tls_deinit
(
void
)
◆ ff_network_wait_fd()
int ff_network_wait_fd
(
int
fd,
int
write
)
◆ ff_network_wait_fd_timeout()
int ff_network_wait_fd_timeout
(
int
fd,
int
write,
)
This works similarly to ff_network_wait_fd, but waits up to 'timeout' microseconds Uses ff_network_wait_fd in a loop.
- Parameters
-
fd Socket descriptor
write Set 1 to wait for socket able to be read, 0 to be written
timeout Timeout interval, in microseconds. Actual precision is 100000 mcs, due to ff_network_wait_fd usage
int_cb Interrupt callback, is checked before each ff_network_wait_fd call
- Returns
- 0 if data can be read/written, AVERROR(ETIMEDOUT) if timeout expired, or negative error code
Definition at line 75 of file network.c.
Referenced by amqp_proto_read(), amqp_proto_write(), tcp_read(), and tcp_write().
◆ ff_network_sleep_interruptible()
int ff_network_sleep_interruptible
(
int64_t
timeout,
)
Waits for up to 'timeout' microseconds.
If the usert's int_cb is set and triggered, return before that.
- Parameters
-
timeout Timeout in microseconds. Maybe have lower actual precision.
int_cb Interrupt callback, is checked regularly.
- Returns
- AVERROR(ETIMEDOUT) if timeout expirted, AVERROR_EXIT if interrupted by int_cb
Definition at line 95 of file network.c.
Referenced by http_open_cnx(), and http_read_stream().
◆ ff_getaddrinfo()
int ff_getaddrinfo
(
const char *
node,
const char *
service,
)
◆ ff_freeaddrinfo()
void ff_freeaddrinfo
(
struct
addrinfo *
res )
◆ ff_getnameinfo()
int ff_getnameinfo
(
const struct sockaddr *
sa,
int
salen,
char *
host,
int
hostlen,
char *
serv,
int
servlen,
int
flags
)
◆ ff_gai_strerror()
const char* ff_gai_strerror
(
int
ecode )
◆ ff_is_multicast_address()
int ff_is_multicast_address
(
struct sockaddr *
addr )
◆ ff_listen_bind()
int ff_listen_bind
(
int
fd,
const struct sockaddr *
addr,
socklen_t
addrlen,
int
timeout,
)
Bind to a file descriptor and poll for a connection.
- Parameters
-
fd First argument of bind().
addr Second argument of bind().
addrlen Third argument of bind().
timeout Polling timeout in milliseconds.
h
URLContext providing interrupt check callback and logging context.
- Returns
- A non-blocking file descriptor on success or an AVERROR on failure.
Definition at line 243 of file network.c.
Referenced by sctp_open(), tcp_open(), and unix_open().
◆ ff_listen()
int ff_listen
(
int
fd,
const struct sockaddr *
addr,
socklen_t
addrlen,
void *
logctx
)
Bind to a file descriptor to an address without accepting connections.
- Parameters
-
fd First argument of bind().
addr Second argument of bind().
addrlen Third argument of bind().
- Returns
- 0 on success or an AVERROR on failure.
Definition at line 207 of file network.c.
Referenced by ff_listen_bind(), and tcp_open().
◆ ff_accept()
int ff_accept
(
int
fd,
int
timeout,
)
Poll for a single connection on the passed file descriptor.
- Parameters
-
fd The listening socket file descriptor.
timeout Polling timeout in milliseconds.
h
URLContext providing interrupt check callback and logging context.
- Returns
- A non-blocking file descriptor on success or an AVERROR on failure.
Definition at line 225 of file network.c.
Referenced by ff_listen_bind(), and tcp_accept().
◆ ff_listen_connect()
int ff_listen_connect
(
int
fd,
const struct sockaddr *
addr,
socklen_t
addrlen,
int
timeout,
int
will_try_next
)
Connect to a file descriptor and poll for result.
- Parameters
-
fd First argument of connect(), will be set as non-blocking.
addr Second argument of connect().
addrlen Third argument of connect().
timeout Polling timeout in milliseconds.
h
URLContext providing interrupt check callback and logging context.
will_try_next Whether the caller will try to connect to another address for the same host name, affecting the form of logged errors.
- Returns
- 0 on success, AVERROR on failure.
Definition at line 255 of file network.c.
Referenced by sctp_open(), and unix_open().
◆ ff_http_match_no_proxy()
int ff_http_match_no_proxy
(
const char *
no_proxy,
const char *
hostname
)
◆ ff_socket()
int ff_socket
(
int
domain,
int
type,
int
protocol,
void *
logctx
)
◆ ff_log_net_error()
void ff_log_net_error
(
void *
ctx,
int
level,
const char *
prefix
)
◆ ff_connect_parallel()
int ff_connect_parallel
(
struct
addrinfo *
addrs,
int
timeout_ms_per_address,
int
parallel,
int *
fd,
int(*)(void *, int, int)
customize_fd,
void *
customize_ctx
)
Connect to any of the given addrinfo addresses, with multiple attempts running in parallel.
- Parameters
-
addrs The list of addresses to try to connect to. This list will be mutated internally, but the list head will remain as such, so this doesn't affect the caller freeing the list afterwards.
timeout_ms_per_address The number of milliseconds to wait for each connection attempt. Since multiple addresses are tried, some of them in parallel, the total run time will at most be timeout_ms_per_address*ceil(nb_addrs/parallel) + (parallel - 1) * NEXT_ATTEMPT_DELAY_MS.
parallel The maximum number of connections to attempt in parallel. This is limited to an internal maximum capacity.
h
URLContext providing interrupt check callback and logging context.
fd If successful, the connected socket is returned here.
customize_fd Function that will be called for each socket created, to allow the caller to set socket options before calling connect() on it, may be NULL.
customize_ctx Context parameter passed to customize_fd.
- Returns
- 0 on success, AVERROR on failure.
Definition at line 404 of file network.c.
Referenced by tcp_open().
◆ ff_udp_get_last_recv_addr()
◆ ff_udp_set_remote_addr()
const struct sockaddr *
dest_addr,
socklen_t
dest_addr_len,
int
do_connect
)