2 * Copyright (c) 2007 The Libav Project
4 * This file is part of Libav.
6 * Libav 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 * Libav 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 Libav; 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"
40 #ifndef EPROTONOSUPPORT
41 #define EPROTONOSUPPORT WSAEPROTONOSUPPORT
44 #define ETIMEDOUT WSAETIMEDOUT
47 #define ECONNREFUSED WSAECONNREFUSED
50 #define EINPROGRESS WSAEINPROGRESS
53 #define getsockopt(a, b, c, d, e) getsockopt(a, b, c, (char*) d, e)
54 #define setsockopt(a, b, c, d, e) setsockopt(a, b, c, (const char*) d, e)
56 int ff_neterrno(void);
58 #include <sys/types.h>
59 #include <sys/socket.h>
60 #include <netinet/in.h>
63 #define ff_neterrno() AVERROR(errno)
64 #endif /* HAVE_WINSOCK2_H */
67 #include <arpa/inet.h>
74 int ff_socket_nonblock(int socket, int enable);
76 extern int ff_network_inited_globally;
77 int ff_network_init(void);
78 void ff_network_close(void);
80 void ff_tls_init(void);
81 void ff_tls_deinit(void);
83 int ff_network_wait_fd(int fd, int write);
85 int ff_inet_aton (const char * str, struct in_addr * add);
87 #if !HAVE_STRUCT_SOCKADDR_STORAGE
88 struct sockaddr_storage {
89 #if HAVE_STRUCT_SOCKADDR_SA_LEN
94 #endif /* HAVE_STRUCT_SOCKADDR_SA_LEN */
99 #endif /* !HAVE_STRUCT_SOCKADDR_STORAGE */
102 #define MSG_NOSIGNAL 0
105 #if !HAVE_STRUCT_ADDRINFO
112 struct sockaddr *ai_addr;
114 struct addrinfo *ai_next;
116 #endif /* !HAVE_STRUCT_ADDRINFO */
118 /* getaddrinfo constants */
123 #define EAI_BADFLAGS 3
141 #define EAI_SERVICE 9
144 #define EAI_SOCKTYPE 10
152 #define AI_CANONNAME 2
155 #ifndef AI_NUMERICHOST
156 #define AI_NUMERICHOST 4
163 #ifndef NI_NUMERICHOST
164 #define NI_NUMERICHOST 2
171 #ifndef NI_NUMERICSERV
172 #define NI_NUMERICSERV 8
179 #if !HAVE_GETADDRINFO
180 int ff_getaddrinfo(const char *node, const char *service,
181 const struct addrinfo *hints, struct addrinfo **res);
182 void ff_freeaddrinfo(struct addrinfo *res);
183 int ff_getnameinfo(const struct sockaddr *sa, int salen,
184 char *host, int hostlen,
185 char *serv, int servlen, int flags);
186 #define getaddrinfo ff_getaddrinfo
187 #define freeaddrinfo ff_freeaddrinfo
188 #define getnameinfo ff_getnameinfo
189 #endif /* !HAVE_GETADDRINFO */
191 #if !HAVE_GETADDRINFO || HAVE_WINSOCK2_H
192 const char *ff_gai_strerror(int ecode);
194 #define gai_strerror ff_gai_strerror
195 #endif /* !HAVE_GETADDRINFO || HAVE_WINSOCK2_H */
197 #ifndef INADDR_LOOPBACK
198 #define INADDR_LOOPBACK 0x7f000001
201 #ifndef INET_ADDRSTRLEN
202 #define INET_ADDRSTRLEN 16
205 #ifndef INET6_ADDRSTRLEN
206 #define INET6_ADDRSTRLEN INET_ADDRSTRLEN
210 #define IN_MULTICAST(a) ((((uint32_t)(a)) & 0xf0000000) == 0xe0000000)
212 #ifndef IN6_IS_ADDR_MULTICAST
213 #define IN6_IS_ADDR_MULTICAST(a) (((uint8_t *) (a))[0] == 0xff)
216 int ff_is_multicast_address(struct sockaddr *addr);
218 #define POLLING_TIME 100 /// Time in milliseconds between interrupt check
221 * Bind to a file descriptor and poll for a connection.
223 * @param fd First argument of bind().
224 * @param addr Second argument of bind().
225 * @param addrlen Third argument of bind().
226 * @param timeout Polling timeout in milliseconds.
227 * @param h URLContext providing interrupt check
228 * callback and logging context.
229 * @return A non-blocking file descriptor on success
230 * or an AVERROR on failure.
232 int ff_listen_bind(int fd, const struct sockaddr *addr,
233 socklen_t addrlen, int timeout,
237 * Connect to a file descriptor and poll for result.
239 * @param fd First argument of connect(),
240 * will be set as non-blocking.
241 * @param addr Second argument of connect().
242 * @param addrlen Third argument of connect().
243 * @param timeout Polling timeout in milliseconds.
244 * @param h URLContext providing interrupt check
245 * callback and logging context.
246 * @param will_try_next Whether the caller will try to connect to another
247 * address for the same host name, affecting the form of
249 * @return 0 on success, AVERROR on failure.
251 int ff_listen_connect(int fd, const struct sockaddr *addr,
252 socklen_t addrlen, int timeout,
253 URLContext *h, int will_try_next);
255 int ff_http_match_no_proxy(const char *no_proxy, const char *hostname);
257 int ff_socket(int domain, int type, int protocol);
259 #endif /* AVFORMAT_NETWORK_H */