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
27 #include "libavutil/error.h"
28 #include "os_support.h"
39 #ifndef EPROTONOSUPPORT
40 #define EPROTONOSUPPORT WSAEPROTONOSUPPORT
43 #define ETIMEDOUT WSAETIMEDOUT
46 #define ECONNREFUSED WSAECONNREFUSED
49 #define EINPROGRESS WSAEINPROGRESS
52 #define getsockopt(a, b, c, d, e) getsockopt(a, b, c, (char*) d, e)
53 #define setsockopt(a, b, c, d, e) setsockopt(a, b, c, (const char*) d, e)
55 int ff_neterrno(void);
57 #include <sys/types.h>
58 #include <sys/socket.h>
59 #include <netinet/in.h>
62 #define ff_neterrno() AVERROR(errno)
66 #include <arpa/inet.h>
73 int ff_socket_nonblock(int socket, int enable);
75 extern int ff_network_inited_globally;
76 int ff_network_init(void);
77 void ff_network_close(void);
79 void ff_tls_init(void);
80 void ff_tls_deinit(void);
82 int ff_network_wait_fd(int fd, int write);
85 * This works similarly to ff_network_wait_fd, but waits up to 'timeout' microseconds
86 * Uses ff_network_wait_fd in a loop
88 * @fd Socket descriptor
89 * @write Set 1 to wait for socket able to be read, 0 to be written
90 * @timeout Timeout interval, in microseconds. Actual precision is 100000 mcs, due to ff_network_wait_fd usage
91 * @param int_cb Interrupt callback, is checked after each ff_network_wait_fd call
92 * @return 0 if data can be read/written, AVERROR(ETIMEDOUT) if timeout expired, or negative error code
94 int ff_network_wait_fd_timeout(int fd, int write, int64_t timeout, AVIOInterruptCB *int_cb);
96 int ff_inet_aton (const char * str, struct in_addr * add);
98 #if !HAVE_STRUCT_SOCKADDR_STORAGE
99 struct sockaddr_storage {
100 #if HAVE_STRUCT_SOCKADDR_SA_LEN
112 #if !HAVE_STRUCT_ADDRINFO
119 struct sockaddr *ai_addr;
121 struct addrinfo *ai_next;
125 /* getaddrinfo constants */
130 #define EAI_BADFLAGS 3
148 #define EAI_SERVICE 9
151 #define EAI_SOCKTYPE 10
159 #define AI_CANONNAME 2
162 #ifndef AI_NUMERICHOST
163 #define AI_NUMERICHOST 4
170 #ifndef NI_NUMERICHOST
171 #define NI_NUMERICHOST 2
178 #ifndef NI_NUMERICSERV
179 #define NI_NUMERICSERV 8
186 #if !HAVE_GETADDRINFO
187 int ff_getaddrinfo(const char *node, const char *service,
188 const struct addrinfo *hints, struct addrinfo **res);
189 void ff_freeaddrinfo(struct addrinfo *res);
190 int ff_getnameinfo(const struct sockaddr *sa, int salen,
191 char *host, int hostlen,
192 char *serv, int servlen, int flags);
193 #define getaddrinfo ff_getaddrinfo
194 #define freeaddrinfo ff_freeaddrinfo
195 #define getnameinfo ff_getnameinfo
197 #if !HAVE_GETADDRINFO || HAVE_WINSOCK2_H
198 const char *ff_gai_strerror(int ecode);
200 #define gai_strerror ff_gai_strerror
203 #ifndef INET6_ADDRSTRLEN
204 #define INET6_ADDRSTRLEN INET_ADDRSTRLEN
208 #define IN_MULTICAST(a) ((((uint32_t)(a)) & 0xf0000000) == 0xe0000000)
210 #ifndef IN6_IS_ADDR_MULTICAST
211 #define IN6_IS_ADDR_MULTICAST(a) (((uint8_t *) (a))[0] == 0xff)
214 int ff_is_multicast_address(struct sockaddr *addr);
216 #endif /* AVFORMAT_NETWORK_H */