]> git.sesse.net Git - ffmpeg/blob - libavformat/network.h
Merge remote-tracking branch 'qatar/master'
[ffmpeg] / libavformat / network.h
1 /*
2  * Copyright (c) 2007 The FFmpeg Project
3  *
4  * This file is part of FFmpeg.
5  *
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.
10  *
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.
15  *
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
19  */
20
21 #ifndef AVFORMAT_NETWORK_H
22 #define AVFORMAT_NETWORK_H
23
24 #include <errno.h>
25
26 #include "config.h"
27 #include "libavutil/error.h"
28 #include "os_support.h"
29 #include "avio.h"
30
31 #if HAVE_UNISTD_H
32 #include <unistd.h>
33 #endif
34
35 #if HAVE_WINSOCK2_H
36 #include <winsock2.h>
37 #include <ws2tcpip.h>
38
39 #ifndef EPROTONOSUPPORT
40 #define EPROTONOSUPPORT WSAEPROTONOSUPPORT
41 #endif
42 #ifndef ETIMEDOUT
43 #define ETIMEDOUT       WSAETIMEDOUT
44 #endif
45 #ifndef ECONNREFUSED
46 #define ECONNREFUSED    WSAECONNREFUSED
47 #endif
48 #ifndef EINPROGRESS
49 #define EINPROGRESS     WSAEINPROGRESS
50 #endif
51
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)
54
55 int ff_neterrno(void);
56 #else
57 #include <sys/types.h>
58 #include <sys/socket.h>
59 #include <netinet/in.h>
60 #include <netdb.h>
61
62 #define ff_neterrno() AVERROR(errno)
63 #endif
64
65 #if HAVE_ARPA_INET_H
66 #include <arpa/inet.h>
67 #endif
68
69 #if HAVE_POLL_H
70 #include <poll.h>
71 #endif
72
73 int ff_socket_nonblock(int socket, int enable);
74
75 extern int ff_network_inited_globally;
76 int ff_network_init(void);
77 void ff_network_close(void);
78
79 void ff_tls_init(void);
80 void ff_tls_deinit(void);
81
82 int ff_network_wait_fd(int fd, int write);
83
84 /**
85  * This works similarly to ff_network_wait_fd, but waits up to 'timeout' microseconds
86  * Uses ff_network_wait_fd in a loop
87  *
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
93  */
94 int ff_network_wait_fd_timeout(int fd, int write, int64_t timeout, AVIOInterruptCB *int_cb);
95
96 int ff_inet_aton (const char * str, struct in_addr * add);
97
98 #if !HAVE_STRUCT_SOCKADDR_STORAGE
99 struct sockaddr_storage {
100 #if HAVE_STRUCT_SOCKADDR_SA_LEN
101     uint8_t ss_len;
102     uint8_t ss_family;
103 #else
104     uint16_t ss_family;
105 #endif
106     char ss_pad1[6];
107     int64_t ss_align;
108     char ss_pad2[112];
109 };
110 #endif
111
112 #if !HAVE_STRUCT_ADDRINFO
113 struct addrinfo {
114     int ai_flags;
115     int ai_family;
116     int ai_socktype;
117     int ai_protocol;
118     int ai_addrlen;
119     struct sockaddr *ai_addr;
120     char *ai_canonname;
121     struct addrinfo *ai_next;
122 };
123 #endif
124
125 /* getaddrinfo constants */
126 #ifndef EAI_AGAIN
127 #define EAI_AGAIN 2
128 #endif
129 #ifndef EAI_BADFLAGS
130 #define EAI_BADFLAGS 3
131 #endif
132 #ifndef EAI_FAIL
133 #define EAI_FAIL 4
134 #endif
135 #ifndef EAI_FAMILY
136 #define EAI_FAMILY 5
137 #endif
138 #ifndef EAI_MEMORY
139 #define EAI_MEMORY 6
140 #endif
141 #ifndef EAI_NODATA
142 #define EAI_NODATA 7
143 #endif
144 #ifndef EAI_NONAME
145 #define EAI_NONAME 8
146 #endif
147 #ifndef EAI_SERVICE
148 #define EAI_SERVICE 9
149 #endif
150 #ifndef EAI_SOCKTYPE
151 #define EAI_SOCKTYPE 10
152 #endif
153
154 #ifndef AI_PASSIVE
155 #define AI_PASSIVE 1
156 #endif
157
158 #ifndef AI_CANONNAME
159 #define AI_CANONNAME 2
160 #endif
161
162 #ifndef AI_NUMERICHOST
163 #define AI_NUMERICHOST 4
164 #endif
165
166 #ifndef NI_NOFQDN
167 #define NI_NOFQDN 1
168 #endif
169
170 #ifndef NI_NUMERICHOST
171 #define NI_NUMERICHOST 2
172 #endif
173
174 #ifndef NI_NAMERQD
175 #define NI_NAMERQD 4
176 #endif
177
178 #ifndef NI_NUMERICSERV
179 #define NI_NUMERICSERV 8
180 #endif
181
182 #ifndef NI_DGRAM
183 #define NI_DGRAM 16
184 #endif
185
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
196 #endif
197 #if !HAVE_GETADDRINFO || HAVE_WINSOCK2_H
198 const char *ff_gai_strerror(int ecode);
199 #undef gai_strerror
200 #define gai_strerror ff_gai_strerror
201 #endif
202
203 #ifndef INET6_ADDRSTRLEN
204 #define INET6_ADDRSTRLEN INET_ADDRSTRLEN
205 #endif
206
207 #ifndef IN_MULTICAST
208 #define IN_MULTICAST(a) ((((uint32_t)(a)) & 0xf0000000) == 0xe0000000)
209 #endif
210 #ifndef IN6_IS_ADDR_MULTICAST
211 #define IN6_IS_ADDR_MULTICAST(a) (((uint8_t *) (a))[0] == 0xff)
212 #endif
213
214 int ff_is_multicast_address(struct sockaddr *addr);
215
216 #endif /* AVFORMAT_NETWORK_H */