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 #ifndef MSG_NOSIGNAL
102 #define MSG_NOSIGNAL 0
103 #endif
104 
105 #if !HAVE_STRUCT_ADDRINFO
106 struct addrinfo {
107  int ai_flags;
112  struct sockaddr *ai_addr;
114  struct addrinfo *ai_next;
115 };
116 #endif /* !HAVE_STRUCT_ADDRINFO */
117 
118 /* getaddrinfo constants */
119 #ifndef EAI_AGAIN
120 #define EAI_AGAIN 2
121 #endif
122 #ifndef EAI_BADFLAGS
123 #define EAI_BADFLAGS 3
124 #endif
125 #ifndef EAI_FAIL
126 #define EAI_FAIL 4
127 #endif
128 #ifndef EAI_FAMILY
129 #define EAI_FAMILY 5
130 #endif
131 #ifndef EAI_MEMORY
132 #define EAI_MEMORY 6
133 #endif
134 #ifndef EAI_NODATA
135 #define EAI_NODATA 7
136 #endif
137 #ifndef EAI_NONAME
138 #define EAI_NONAME 8
139 #endif
140 #ifndef EAI_SERVICE
141 #define EAI_SERVICE 9
142 #endif
143 #ifndef EAI_SOCKTYPE
144 #define EAI_SOCKTYPE 10
145 #endif
146 
147 #ifndef AI_PASSIVE
148 #define AI_PASSIVE 1
149 #endif
150 
151 #ifndef AI_CANONNAME
152 #define AI_CANONNAME 2
153 #endif
154 
155 #ifndef AI_NUMERICHOST
156 #define AI_NUMERICHOST 4
157 #endif
158 
159 #ifndef NI_NOFQDN
160 #define NI_NOFQDN 1
161 #endif
162 
163 #ifndef NI_NUMERICHOST
164 #define NI_NUMERICHOST 2
165 #endif
166 
167 #ifndef NI_NAMERQD
168 #define NI_NAMERQD 4
169 #endif
170 
171 #ifndef NI_NUMERICSERV
172 #define NI_NUMERICSERV 8
173 #endif
174 
175 #ifndef NI_DGRAM
176 #define NI_DGRAM 16
177 #endif
178 
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 */
190 
191 #if !HAVE_GETADDRINFO || HAVE_WINSOCK2_H
192 const char *ff_gai_strerror(int ecode);
193 #undef gai_strerror
194 #define gai_strerror ff_gai_strerror
195 #endif /* !HAVE_GETADDRINFO || HAVE_WINSOCK2_H */
196 
197 #ifndef INADDR_LOOPBACK
198 #define INADDR_LOOPBACK 0x7f000001
199 #endif
200 
201 #ifndef INET_ADDRSTRLEN
202 #define INET_ADDRSTRLEN 16
203 #endif
204 
205 #ifndef INET6_ADDRSTRLEN
206 #define INET6_ADDRSTRLEN INET_ADDRSTRLEN
207 #endif
208 
209 #ifndef IN_MULTICAST
210 #define IN_MULTICAST(a) ((((uint32_t)(a)) & 0xf0000000) == 0xe0000000)
211 #endif
212 #ifndef IN6_IS_ADDR_MULTICAST
213 #define IN6_IS_ADDR_MULTICAST(a) (((uint8_t *) (a))[0] == 0xff)
214 #endif
215 
216 int ff_is_multicast_address(struct sockaddr *addr);
217 
218 #define POLLING_TIME 100
219 
220 
232 int ff_listen_bind(int fd, const struct sockaddr *addr,
233  socklen_t addrlen, int timeout,
234  URLContext *h);
235 
251 int ff_listen_connect(int fd, const struct sockaddr *addr,
252  socklen_t addrlen, int timeout,
253  URLContext *h, int will_try_next);
254 
255 int ff_http_match_no_proxy(const char *no_proxy, const char *hostname);
256 
257 int ff_socket(int domain, int type, int protocol);
258 
259 #endif /* AVFORMAT_NETWORK_H */
char ss_pad1[6]
Definition: network.h:95
int ff_network_wait_fd(int fd, int write)
Definition: network.c:68
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:106
uint8_t
miscellaneous OS support macros and functions.
uint16_t ss_family
Definition: network.h:93
void ff_tls_init(void)
Definition: network.c:28
static int flags
Definition: log.c:50
int ff_http_match_no_proxy(const char *no_proxy, const char *hostname)
Definition: network.c:260
void ff_network_close(void)
Definition: network.c:77
error code definitions
const char * ff_gai_strerror(int ecode)
char * ai_canonname
Definition: network.h:113
void ff_freeaddrinfo(struct addrinfo *res)
int ai_addrlen
Definition: network.h:111
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:192
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:163
Definition: url.h:38
int ai_protocol
Definition: network.h:110
void ff_tls_deinit(void)
Definition: network.c:38
int ai_socktype
Definition: network.h:109
int ff_network_inited_globally
Definition: network.c:48
struct addrinfo * ai_next
Definition: network.h:114
int ff_network_init(void)
Definition: network.c:50
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:141
int ai_flags
Definition: network.h:107
unbuffered private I/O API
struct sockaddr * ai_addr
Definition: network.h:112
int ai_family
Definition: network.h:108