2 * Copyright (c) 2007 The FFmpeg Project
4 * This file is part of FFmpeg.
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 #ifndef AVFORMAT_NETWORK_H
22 #define AVFORMAT_NETWORK_H
28 #include "libavutil/error.h"
29 #include "os_support.h"
41 #ifndef EPROTONOSUPPORT
42 #define EPROTONOSUPPORT WSAEPROTONOSUPPORT
45 #define ETIMEDOUT WSAETIMEDOUT
48 #define ECONNREFUSED WSAECONNREFUSED
51 #define EINPROGRESS WSAEINPROGRESS
54 #define getsockopt(a, b, c, d, e) getsockopt(a, b, c, (char*) d, e)
55 #define setsockopt(a, b, c, d, e) setsockopt(a, b, c, (const char*) d, e)
57 int ff_neterrno(void);
59 #include <sys/types.h>
60 #include <sys/socket.h>
61 #include <netinet/in.h>
64 #define ff_neterrno() AVERROR(errno)
65 #endif /* HAVE_WINSOCK2_H */
68 #include <arpa/inet.h>
75 int ff_socket_nonblock(int socket
, int enable
);
77 extern int ff_network_inited_globally
;
78 int ff_network_init(void);
79 void ff_network_close(void);
81 void ff_tls_init(void);
82 void ff_tls_deinit(void);
84 int ff_network_wait_fd(int fd
, int write
);
87 * This works similarly to ff_network_wait_fd, but waits up to 'timeout' microseconds
88 * Uses ff_network_wait_fd in a loop
90 * @fd Socket descriptor
91 * @write Set 1 to wait for socket able to be read, 0 to be written
92 * @timeout Timeout interval, in microseconds. Actual precision is 100000 mcs, due to ff_network_wait_fd usage
93 * @param int_cb Interrupt callback, is checked before each ff_network_wait_fd call
94 * @return 0 if data can be read/written, AVERROR(ETIMEDOUT) if timeout expired, or negative error code
96 int ff_network_wait_fd_timeout(int fd
, int write
, int64_t timeout
, AVIOInterruptCB
*int_cb
);
98 int ff_inet_aton (const char * str
, struct in_addr
* add
);
100 #if !HAVE_STRUCT_SOCKADDR_STORAGE
101 struct sockaddr_storage
{
102 #if HAVE_STRUCT_SOCKADDR_SA_LEN
107 #endif /* HAVE_STRUCT_SOCKADDR_SA_LEN */
112 #endif /* !HAVE_STRUCT_SOCKADDR_STORAGE */
115 #define MSG_NOSIGNAL 0
118 #if !HAVE_STRUCT_ADDRINFO
125 struct sockaddr
*ai_addr
;
127 struct addrinfo
*ai_next
;
129 #endif /* !HAVE_STRUCT_ADDRINFO */
131 /* getaddrinfo constants */
136 #define EAI_BADFLAGS 3
154 #define EAI_SERVICE 9
157 #define EAI_SOCKTYPE 10
165 #define AI_CANONNAME 2
168 #ifndef AI_NUMERICHOST
169 #define AI_NUMERICHOST 4
176 #ifndef NI_NUMERICHOST
177 #define NI_NUMERICHOST 2
184 #ifndef NI_NUMERICSERV
185 #define NI_NUMERICSERV 8
192 #if !HAVE_GETADDRINFO
193 int ff_getaddrinfo(const char *node
, const char *service
,
194 const struct addrinfo
*hints
, struct addrinfo
**res
);
195 void ff_freeaddrinfo(struct addrinfo
*res
);
196 int ff_getnameinfo(const struct sockaddr
*sa
, int salen
,
197 char *host
, int hostlen
,
198 char *serv
, int servlen
, int flags
);
199 #define getaddrinfo ff_getaddrinfo
200 #define freeaddrinfo ff_freeaddrinfo
201 #define getnameinfo ff_getnameinfo
202 #endif /* !HAVE_GETADDRINFO */
204 #if !HAVE_GETADDRINFO || HAVE_WINSOCK2_H
205 const char *ff_gai_strerror(int ecode
);
207 #define gai_strerror ff_gai_strerror
208 #endif /* !HAVE_GETADDRINFO || HAVE_WINSOCK2_H */
210 #ifndef INADDR_LOOPBACK
211 #define INADDR_LOOPBACK 0x7f000001
214 #ifndef INET_ADDRSTRLEN
215 #define INET_ADDRSTRLEN 16
218 #ifndef INET6_ADDRSTRLEN
219 #define INET6_ADDRSTRLEN INET_ADDRSTRLEN
223 #define IN_MULTICAST(a) ((((uint32_t)(a)) & 0xf0000000) == 0xe0000000)
225 #ifndef IN6_IS_ADDR_MULTICAST
226 #define IN6_IS_ADDR_MULTICAST(a) (((uint8_t *) (a))[0] == 0xff)
229 int ff_is_multicast_address(struct sockaddr
*addr
);
231 #define POLLING_TIME 100 /// Time in milliseconds between interrupt check
234 * Bind to a file descriptor and poll for a connection.
236 * @param fd First argument of bind().
237 * @param addr Second argument of bind().
238 * @param addrlen Third argument of bind().
239 * @param timeout Polling timeout in milliseconds.
240 * @param h URLContext providing interrupt check
241 * callback and logging context.
242 * @return A non-blocking file descriptor on success
243 * or an AVERROR on failure.
245 int ff_listen_bind(int fd
, const struct sockaddr
*addr
,
246 socklen_t addrlen
, int timeout
,
250 * Connect to a file descriptor and poll for result.
252 * @param fd First argument of connect(),
253 * will be set as non-blocking.
254 * @param addr Second argument of connect().
255 * @param addrlen Third argument of connect().
256 * @param timeout Polling timeout in milliseconds.
257 * @param h URLContext providing interrupt check
258 * callback and logging context.
259 * @param will_try_next Whether the caller will try to connect to another
260 * address for the same host name, affecting the form of
262 * @return 0 on success, AVERROR on failure.
264 int ff_listen_connect(int fd
, const struct sockaddr
*addr
,
265 socklen_t addrlen
, int timeout
,
266 URLContext
*h
, int will_try_next
);
268 int ff_http_match_no_proxy(const char *no_proxy
, const char *hostname
);
270 int ff_socket(int domain
, int type
, int protocol
);
272 #endif /* AVFORMAT_NETWORK_H */