]> git.sesse.net Git - ffmpeg/blob - libavformat/network.h
dsputil: Move ff_zigzag_direct and ff_crop_tab declarations to mathops.h
[ffmpeg] / libavformat / network.h
1 /*
2  * Copyright (c) 2007 The Libav Project
3  *
4  * This file is part of Libav.
5  *
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.
10  *
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.
15  *
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
19  */
20
21 #ifndef AVFORMAT_NETWORK_H
22 #define AVFORMAT_NETWORK_H
23
24 #include <errno.h>
25 #include <stdint.h>
26
27 #include "config.h"
28 #include "libavutil/error.h"
29 #include "os_support.h"
30 #include "url.h"
31
32 #if HAVE_UNISTD_H
33 #include <unistd.h>
34 #endif
35
36 #if HAVE_WINSOCK2_H
37 #include <winsock2.h>
38 #include <ws2tcpip.h>
39
40 #ifndef EPROTONOSUPPORT
41 #define EPROTONOSUPPORT WSAEPROTONOSUPPORT
42 #endif
43 #ifndef ETIMEDOUT
44 #define ETIMEDOUT       WSAETIMEDOUT
45 #endif
46 #ifndef ECONNREFUSED
47 #define ECONNREFUSED    WSAECONNREFUSED
48 #endif
49 #ifndef EINPROGRESS
50 #define EINPROGRESS     WSAEINPROGRESS
51 #endif
52
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)
55
56 int ff_neterrno(void);
57 #else
58 #include <sys/types.h>
59 #include <sys/socket.h>
60 #include <netinet/in.h>
61 #include <netdb.h>
62
63 #define ff_neterrno() AVERROR(errno)
64 #endif /* HAVE_WINSOCK2_H */
65
66 #if HAVE_ARPA_INET_H
67 #include <arpa/inet.h>
68 #endif
69
70 #if HAVE_POLL_H
71 #include <poll.h>
72 #endif
73
74 int ff_socket_nonblock(int socket, int enable);
75
76 extern int ff_network_inited_globally;
77 int ff_network_init(void);
78 void ff_network_close(void);
79
80 void ff_tls_init(void);
81 void ff_tls_deinit(void);
82
83 int ff_network_wait_fd(int fd, int write);
84
85 int ff_inet_aton (const char * str, struct in_addr * add);
86
87 #if !HAVE_STRUCT_SOCKADDR_STORAGE
88 struct sockaddr_storage {
89 #if HAVE_STRUCT_SOCKADDR_SA_LEN
90     uint8_t ss_len;
91     uint8_t ss_family;
92 #else
93     uint16_t ss_family;
94 #endif /* HAVE_STRUCT_SOCKADDR_SA_LEN */
95     char ss_pad1[6];
96     int64_t ss_align;
97     char ss_pad2[112];
98 };
99 #endif /* !HAVE_STRUCT_SOCKADDR_STORAGE */
100
101 #if !HAVE_STRUCT_ADDRINFO
102 struct addrinfo {
103     int ai_flags;
104     int ai_family;
105     int ai_socktype;
106     int ai_protocol;
107     int ai_addrlen;
108     struct sockaddr *ai_addr;
109     char *ai_canonname;
110     struct addrinfo *ai_next;
111 };
112 #endif /* !HAVE_STRUCT_ADDRINFO */
113
114 /* getaddrinfo constants */
115 #ifndef EAI_AGAIN
116 #define EAI_AGAIN 2
117 #endif
118 #ifndef EAI_BADFLAGS
119 #define EAI_BADFLAGS 3
120 #endif
121 #ifndef EAI_FAIL
122 #define EAI_FAIL 4
123 #endif
124 #ifndef EAI_FAMILY
125 #define EAI_FAMILY 5
126 #endif
127 #ifndef EAI_MEMORY
128 #define EAI_MEMORY 6
129 #endif
130 #ifndef EAI_NODATA
131 #define EAI_NODATA 7
132 #endif
133 #ifndef EAI_NONAME
134 #define EAI_NONAME 8
135 #endif
136 #ifndef EAI_SERVICE
137 #define EAI_SERVICE 9
138 #endif
139 #ifndef EAI_SOCKTYPE
140 #define EAI_SOCKTYPE 10
141 #endif
142
143 #ifndef AI_PASSIVE
144 #define AI_PASSIVE 1
145 #endif
146
147 #ifndef AI_CANONNAME
148 #define AI_CANONNAME 2
149 #endif
150
151 #ifndef AI_NUMERICHOST
152 #define AI_NUMERICHOST 4
153 #endif
154
155 #ifndef NI_NOFQDN
156 #define NI_NOFQDN 1
157 #endif
158
159 #ifndef NI_NUMERICHOST
160 #define NI_NUMERICHOST 2
161 #endif
162
163 #ifndef NI_NAMERQD
164 #define NI_NAMERQD 4
165 #endif
166
167 #ifndef NI_NUMERICSERV
168 #define NI_NUMERICSERV 8
169 #endif
170
171 #ifndef NI_DGRAM
172 #define NI_DGRAM 16
173 #endif
174
175 #if !HAVE_GETADDRINFO
176 int ff_getaddrinfo(const char *node, const char *service,
177                    const struct addrinfo *hints, struct addrinfo **res);
178 void ff_freeaddrinfo(struct addrinfo *res);
179 int ff_getnameinfo(const struct sockaddr *sa, int salen,
180                    char *host, int hostlen,
181                    char *serv, int servlen, int flags);
182 #define getaddrinfo ff_getaddrinfo
183 #define freeaddrinfo ff_freeaddrinfo
184 #define getnameinfo ff_getnameinfo
185 #endif /* !HAVE_GETADDRINFO */
186
187 #if !HAVE_GETADDRINFO || HAVE_WINSOCK2_H
188 const char *ff_gai_strerror(int ecode);
189 #undef gai_strerror
190 #define gai_strerror ff_gai_strerror
191 #endif /* !HAVE_GETADDRINFO || HAVE_WINSOCK2_H */
192
193 #ifndef INADDR_LOOPBACK
194 #define INADDR_LOOPBACK 0x7f000001
195 #endif
196
197 #ifndef INET_ADDRSTRLEN
198 #define INET_ADDRSTRLEN 16
199 #endif
200
201 #ifndef INET6_ADDRSTRLEN
202 #define INET6_ADDRSTRLEN INET_ADDRSTRLEN
203 #endif
204
205 #ifndef IN_MULTICAST
206 #define IN_MULTICAST(a) ((((uint32_t)(a)) & 0xf0000000) == 0xe0000000)
207 #endif
208 #ifndef IN6_IS_ADDR_MULTICAST
209 #define IN6_IS_ADDR_MULTICAST(a) (((uint8_t *) (a))[0] == 0xff)
210 #endif
211
212 int ff_is_multicast_address(struct sockaddr *addr);
213
214 #define POLLING_TIME 100 /// Time in milliseconds between interrupt check
215
216 /**
217  * Bind to a file descriptor and poll for a connection.
218  *
219  * @param fd      First argument of bind().
220  * @param addr    Second argument of bind().
221  * @param addrlen Third argument of bind().
222  * @param timeout Polling timeout in milliseconds.
223  * @param h       URLContext providing interrupt check
224  *                callback and logging context.
225  * @return        A non-blocking file descriptor on success
226  *                or an AVERROR on failure.
227  */
228 int ff_listen_bind(int fd, const struct sockaddr *addr,
229                    socklen_t addrlen, int timeout,
230                    URLContext *h);
231
232 /**
233  * Connect to a file descriptor and poll for result.
234  *
235  * @param fd       First argument of connect(),
236  *                 will be set as non-blocking.
237  * @param addr     Second argument of connect().
238  * @param addrlen  Third argument of connect().
239  * @param timeout  Polling timeout in milliseconds.
240  * @param h        URLContext providing interrupt check
241  *                 callback and logging context.
242  * @param will_try_next Whether the caller will try to connect to another
243  *                 address for the same host name, affecting the form of
244  *                 logged errors.
245  * @return         0 on success, AVERROR on failure.
246  */
247 int ff_listen_connect(int fd, const struct sockaddr *addr,
248                       socklen_t addrlen, int timeout,
249                       URLContext *h, int will_try_next);
250
251 int ff_http_match_no_proxy(const char *no_proxy, const char *hostname);
252
253 int ff_socket(int domain, int type, int protocol);
254
255 #endif /* AVFORMAT_NETWORK_H */