Libav
network.h
Go to the documentation of this file.
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 
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
89 #if HAVE_STRUCT_SOCKADDR_SA_LEN
90  uint8_t ss_len;
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;
108  struct sockaddr *ai_addr;
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
215 
216 
228 int ff_listen_bind(int fd, const struct sockaddr *addr,
229  socklen_t addrlen, int timeout,
230  URLContext *h);
231 
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 */
char ss_pad1[6]
Definition: network.h:95
int ff_network_wait_fd(int fd, int write)
Definition: network.c:141
int ff_getnameinfo(const struct sockaddr *sa, int salen, char *host, int hostlen, char *serv, int servlen, int flags)
int ff_is_multicast_address(struct sockaddr *addr)
Definition: network.c:179
uint8_t
miscellaneous OS support macros and functions.
uint16_t ss_family
Definition: network.h:93
void ff_tls_init(void)
Definition: network.c:66
static int flags
Definition: log.c:44
int ff_http_match_no_proxy(const char *no_proxy, const char *hostname)
Definition: network.c:329
void ff_network_close(void)
Definition: network.c:150
const char * ff_gai_strerror(int ecode)
char * ai_canonname
Definition: network.h:109
void ff_freeaddrinfo(struct addrinfo *res)
int ai_addrlen
Definition: network.h:107
int ff_inet_aton(const char *str, struct in_addr *add)
#define ff_neterrno()
Definition: network.h:63
int ff_listen_connect(int fd, const struct sockaddr *addr, socklen_t addrlen, int timeout, URLContext *h, int will_try_next)
Connect to a file descriptor and poll for result.
Definition: network.c:261
int ff_socket_nonblock(int socket, int enable)
int64_t ss_align
Definition: network.h:96
int ff_listen_bind(int fd, const struct sockaddr *addr, socklen_t addrlen, int timeout, URLContext *h)
Bind to a file descriptor and poll for a connection.
Definition: network.c:232
Definition: url.h:41
int ai_protocol
Definition: network.h:106
void ff_tls_deinit(void)
Definition: network.c:98
int ai_socktype
Definition: network.h:105
int ff_network_inited_globally
Definition: network.c:121
struct addrinfo * ai_next
Definition: network.h:110
int ff_network_init(void)
Definition: network.c:123
char ss_pad2[112]
Definition: network.h:97
int ff_getaddrinfo(const char *node, const char *service, const struct addrinfo *hints, struct addrinfo **res)
int ff_socket(int domain, int type, int protocol)
Definition: network.c:214
int ai_flags
Definition: network.h:103
unbuffered private I/O API
struct sockaddr * ai_addr
Definition: network.h:108
int ai_family
Definition: network.h:104