FFmpeg
Data Structures | Macros | Functions
network.h File Reference
#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

struct   sockaddr_storage
 
union   sockaddr_union
 
struct   addrinfo
 

Macros

#define  ff_neterrno()   AVERROR(errno)
 
#define  MSG_NOSIGNAL   0
 
#define  EAI_AGAIN   2
 
#define  EAI_BADFLAGS   3
 
#define  EAI_FAIL   4
 
#define  EAI_FAMILY   5
 
#define  EAI_MEMORY   6
 
#define  EAI_NODATA   7
 
#define  EAI_NONAME   8
 
#define  EAI_SERVICE   9
 
#define  EAI_SOCKTYPE   10
 
#define  AI_PASSIVE   1
 
#define  AI_CANONNAME   2
 
#define  AI_NUMERICHOST   4
 
#define  NI_NOFQDN   1
 
#define  NI_NUMERICHOST   2
 
#define  NI_NAMERQD   4
 
#define  NI_NUMERICSERV   8
 
#define  NI_DGRAM   16
 
#define  getaddrinfo   ff_getaddrinfo
 
#define  freeaddrinfo   ff_freeaddrinfo
 
#define  getnameinfo   ff_getnameinfo
 
#define  gai_strerror   ff_gai_strerror
 
#define  INADDR_LOOPBACK   0x7f000001
 
#define  INET_ADDRSTRLEN   16
 
 
#define  IN_MULTICAST(a)   ((((uint32_t)(a)) & 0xf0000000) == 0xe0000000)
 
#define  IN6_IS_ADDR_MULTICAST(a)   (((uint8_t *) (a))[0] == 0xff)
 
#define  POLLING_TIME   100
 

Functions

int  ff_socket_nonblock (int socket, int enable)
 
int  ff_network_init (void)
 
void  ff_network_close (void)
 
int  ff_tls_init (void)
 
void  ff_tls_deinit (void)
 
int  ff_network_wait_fd (int fd, int write)
 
int  ff_network_wait_fd_timeout (int fd, int write, int64_t timeout, AVIOInterruptCB *int_cb)
  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_getaddrinfo (const char *node, const char *service, const struct addrinfo *hints, struct addrinfo **res)
 
void  ff_freeaddrinfo (struct addrinfo *res)
 
int  ff_getnameinfo (const struct sockaddr *sa, int salen, char *host, int hostlen, char *serv, int servlen, int flags)
 
const char *  ff_gai_strerror (int ecode)
 
int  ff_is_multicast_address (struct sockaddr *addr)
 
int  ff_listen_bind (int fd, const struct sockaddr *addr, socklen_t addrlen, int timeout, URLContext *h)
  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...
 
int  ff_accept (int fd, int timeout, URLContext *h)
  Poll for a single connection on the passed file descriptor. More...
 
int  ff_listen_connect (int fd, const struct sockaddr *addr, socklen_t addrlen, int timeout, URLContext *h, int will_try_next)
  Connect to a file descriptor and poll for result. More...
 
int  ff_http_match_no_proxy (const char *no_proxy, const char *hostname)
 
int  ff_socket (int domain, int type, int protocol, void *logctx)
 
void  ff_log_net_error (void *ctx, int level, const char *prefix)
 
int  ff_connect_parallel (struct addrinfo *addrs, int timeout_ms_per_address, int parallel, URLContext *h, int *fd, int(*customize_fd)(void *, int, int), void *customize_ctx)
  Connect to any of the given addrinfo addresses, with multiple attempts running in parallel. More...
 
void  ff_udp_get_last_recv_addr (URLContext *h, struct sockaddr_storage *addr, socklen_t *addr_len)
 
int  ff_udp_set_remote_addr (URLContext *h, const struct sockaddr *dest_addr, socklen_t dest_addr_len, int do_connect)
  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)

Definition at line 68 of file network.h.

MSG_NOSIGNAL

#define MSG_NOSIGNAL   0

Definition at line 133 of file network.h.

EAI_AGAIN

#define EAI_AGAIN   2

Definition at line 151 of file network.h.

EAI_BADFLAGS

#define EAI_BADFLAGS   3

Definition at line 154 of file network.h.

EAI_FAIL

#define EAI_FAIL   4

Definition at line 157 of file network.h.

EAI_FAMILY

#define EAI_FAMILY   5

Definition at line 160 of file network.h.

EAI_MEMORY

#define EAI_MEMORY   6

Definition at line 163 of file network.h.

EAI_NODATA

#define EAI_NODATA   7

Definition at line 166 of file network.h.

EAI_NONAME

#define EAI_NONAME   8

Definition at line 169 of file network.h.

EAI_SERVICE

#define EAI_SERVICE   9

Definition at line 172 of file network.h.

EAI_SOCKTYPE

#define EAI_SOCKTYPE   10

Definition at line 175 of file network.h.

AI_PASSIVE

#define AI_PASSIVE   1

Definition at line 179 of file network.h.

AI_CANONNAME

#define AI_CANONNAME   2

Definition at line 183 of file network.h.

AI_NUMERICHOST

#define AI_NUMERICHOST   4

Definition at line 187 of file network.h.

NI_NOFQDN

#define NI_NOFQDN   1

Definition at line 191 of file network.h.

NI_NUMERICHOST

#define NI_NUMERICHOST   2

Definition at line 195 of file network.h.

NI_NAMERQD

#define NI_NAMERQD   4

Definition at line 199 of file network.h.

NI_NUMERICSERV

#define NI_NUMERICSERV   8

Definition at line 203 of file network.h.

NI_DGRAM

#define NI_DGRAM   16

Definition at line 207 of file network.h.

getaddrinfo

#define getaddrinfo   ff_getaddrinfo

Definition at line 217 of file network.h.

freeaddrinfo

#define freeaddrinfo   ff_freeaddrinfo

Definition at line 218 of file network.h.

getnameinfo

#define getnameinfo   ff_getnameinfo

Definition at line 219 of file network.h.

gai_strerror

#define gai_strerror   ff_gai_strerror

Definition at line 225 of file network.h.

INADDR_LOOPBACK

#define INADDR_LOOPBACK   0x7f000001

Definition at line 229 of file network.h.

INET_ADDRSTRLEN

#define INET_ADDRSTRLEN   16

Definition at line 233 of file network.h.

INET6_ADDRSTRLEN

#define INET6_ADDRSTRLEN   INET_ADDRSTRLEN

Definition at line 237 of file network.h.

IN_MULTICAST

#define IN_MULTICAST (   a )    ((((uint32_t)(a)) & 0xf0000000) == 0xe0000000)

Definition at line 241 of file network.h.

IN6_IS_ADDR_MULTICAST

#define IN6_IS_ADDR_MULTICAST (   a )    (((uint8_t *) (a))[0] == 0xff)

Definition at line 244 of file network.h.

POLLING_TIME

#define POLLING_TIME   100

Definition at line 249 of file network.h.

Function Documentation

ff_socket_nonblock()

int ff_socket_nonblock ( int  socket,
int  enable 
)

Referenced by dtls_initialize(), ff_accept(), ff_listen_connect(), start_connect_attempt(), udp_connect(), and udp_open().

ff_network_init()

int ff_network_init ( void  )

Definition at line 55 of file network.c.

Referenced by avformat_network_init(), rtsp_listen(), sap_read_header(), sap_write_header(), and url_alloc_for_protocol().

ff_network_close()

void ff_network_close ( void  )

Definition at line 113 of file network.c.

Referenced by avformat_network_deinit(), ffurl_closep(), rtsp_listen(), rtsp_read_close(), rtsp_write_close(), sap_read_close(), sap_write_close(), and url_alloc_for_protocol().

ff_tls_init()

int ff_tls_init ( void  )

Definition at line 36 of file network.c.

Referenced by avformat_network_init().

ff_tls_deinit()

void ff_tls_deinit ( void  )

Definition at line 46 of file network.c.

Referenced by avformat_network_deinit().

ff_network_wait_fd()

int ff_network_wait_fd ( int  fd,
int  write 
)

Definition at line 66 of file network.c.

Referenced by ff_network_wait_fd_timeout(), rtp_write(), udp_read(), udp_write(), unix_read(), and unix_write().

ff_network_wait_fd_timeout()

int ff_network_wait_fd_timeout ( int  fd,
int  write,
int64_t  timeout,
AVIOInterruptCBint_cb 
)

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,
AVIOInterruptCBint_cb 
)

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,
const struct addrinfohints,
struct addrinfo **  res 
)

ff_freeaddrinfo()

void ff_freeaddrinfo ( struct addrinfores )

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 )

Definition at line 142 of file network.c.

Referenced by ff_udp_set_remote_addr(), and ff_udp_set_remote_url().

ff_listen_bind()

int ff_listen_bind ( int  fd,
const struct sockaddr *  addr,
socklen_t  addrlen,
int  timeout,
URLContexth 
)

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,
URLContexth 
)

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,
URLContexth,
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 
)

Definition at line 549 of file network.c.

Referenced by ff_tls_open_underlying(), http_open_cnx_internal(), and test().

ff_socket()

int ff_socket ( int  domain,
int  type,
int  protocol,
void *  logctx 
)

Definition at line 180 of file network.c.

Referenced by sctp_open(), start_connect_attempt(), tcp_open(), udp_socket_create(), and unix_open().

ff_log_net_error()

void ff_log_net_error ( void *  ctx,
int  level,
const char *  prefix 
)

Definition at line 579 of file network.c.

Referenced by customize_fd(), ff_udp_set_remote_addr(), ff_udp_set_remote_url(), udp_join_multicast_group(), udp_leave_multicast_group(), udp_open(), udp_set_multicast_sources(), udp_set_multicast_ttl(), and udp_socket_create().

ff_connect_parallel()

int ff_connect_parallel ( struct addrinfoaddrs,
int  timeout_ms_per_address,
int  parallel,
URLContexth,
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()

void ff_udp_get_last_recv_addr ( URLContexth,
struct sockaddr_storageaddr,
socklen_t *  addr_len 
)

Definition at line 510 of file udp.c.

Referenced by tls_handshake_loop(), and url_bio_bread().

ff_udp_set_remote_addr()

int ff_udp_set_remote_addr ( URLContexth,
const struct sockaddr *  dest_addr,
socklen_t  dest_addr_len,
int  do_connect 
)

This function is identical to ff_udp_set_remote_url, except that it takes a sockaddr directly.

Definition at line 472 of file udp.c.

Referenced by tls_handshake_loop(), and url_bio_bread().


Generated on Sat Oct 18 2025 19:24:15 for FFmpeg by   doxygen 1.8.17

AltStyle によって変換されたページ (->オリジナル) /