]> 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
30 #if HAVE_WINSOCK2_H
31 #include <winsock2.h>
32 #include <ws2tcpip.h>
33
34 #ifdef EPROTONOSUPPORT
35 # undef EPROTONOSUPPORT
36 #endif
37 #define EPROTONOSUPPORT WSAEPROTONOSUPPORT
38 #ifdef ETIMEDOUT
39 # undef ETIMEDOUT
40 #endif
41 #define ETIMEDOUT       WSAETIMEDOUT
42 #ifdef ECONNREFUSED
43 # undef ECONNREFUSED
44 #endif
45 #define ECONNREFUSED    WSAECONNREFUSED
46 #ifdef EINPROGRESS
47 # undef EINPROGRESS
48 #endif
49 #define EINPROGRESS     WSAEINPROGRESS
50 #define getsockopt(a, b, c, d, e) getsockopt(a, b, c, (char*) d, e)
51 #define setsockopt(a, b, c, d, e) setsockopt(a, b, c, (const char*) d, e)
52
53 int ff_neterrno(void);
54 #else
55 #include <sys/types.h>
56 #include <sys/socket.h>
57 #include <netinet/in.h>
58 #include <netdb.h>
59
60 #define ff_neterrno() AVERROR(errno)
61 #endif
62
63 #if HAVE_ARPA_INET_H
64 #include <arpa/inet.h>
65 #endif
66
67 #if HAVE_POLL_H
68 #include <poll.h>
69 #endif
70
71 int ff_socket_nonblock(int socket, int enable);
72
73 extern int ff_network_inited_globally;
74 int ff_network_init(void);
75 void ff_network_close(void);
76
77 void ff_tls_init(void);
78 void ff_tls_deinit(void);
79
80 int ff_network_wait_fd(int fd, int write);
81
82 int ff_inet_aton (const char * str, struct in_addr * add);
83
84 #if !HAVE_STRUCT_SOCKADDR_STORAGE
85 struct sockaddr_storage {
86 #if HAVE_STRUCT_SOCKADDR_SA_LEN
87     uint8_t ss_len;
88     uint8_t ss_family;
89 #else
90     uint16_t ss_family;
91 #endif
92     char ss_pad1[6];
93     int64_t ss_align;
94     char ss_pad2[112];
95 };
96 #endif
97
98 #if !HAVE_STRUCT_ADDRINFO
99 struct addrinfo {
100     int ai_flags;
101     int ai_family;
102     int ai_socktype;
103     int ai_protocol;
104     int ai_addrlen;
105     struct sockaddr *ai_addr;
106     char *ai_canonname;
107     struct addrinfo *ai_next;
108 };
109 #endif
110
111 /* getaddrinfo constants */
112 #ifndef EAI_FAIL
113 #define EAI_FAIL 4
114 #endif
115
116 #ifndef EAI_FAMILY
117 #define EAI_FAMILY 5
118 #endif
119
120 #ifndef EAI_NONAME
121 #define EAI_NONAME 8
122 #endif
123
124 #ifndef AI_PASSIVE
125 #define AI_PASSIVE 1
126 #endif
127
128 #ifndef AI_CANONNAME
129 #define AI_CANONNAME 2
130 #endif
131
132 #ifndef AI_NUMERICHOST
133 #define AI_NUMERICHOST 4
134 #endif
135
136 #ifndef NI_NOFQDN
137 #define NI_NOFQDN 1
138 #endif
139
140 #ifndef NI_NUMERICHOST
141 #define NI_NUMERICHOST 2
142 #endif
143
144 #ifndef NI_NAMERQD
145 #define NI_NAMERQD 4
146 #endif
147
148 #ifndef NI_NUMERICSERV
149 #define NI_NUMERICSERV 8
150 #endif
151
152 #ifndef NI_DGRAM
153 #define NI_DGRAM 16
154 #endif
155
156 #if !HAVE_GETADDRINFO
157 int ff_getaddrinfo(const char *node, const char *service,
158                    const struct addrinfo *hints, struct addrinfo **res);
159 void ff_freeaddrinfo(struct addrinfo *res);
160 int ff_getnameinfo(const struct sockaddr *sa, int salen,
161                    char *host, int hostlen,
162                    char *serv, int servlen, int flags);
163 const char *ff_gai_strerror(int ecode);
164 #define getaddrinfo ff_getaddrinfo
165 #define freeaddrinfo ff_freeaddrinfo
166 #define getnameinfo ff_getnameinfo
167 #define gai_strerror ff_gai_strerror
168 #endif
169
170 #ifndef INET6_ADDRSTRLEN
171 #define INET6_ADDRSTRLEN INET_ADDRSTRLEN
172 #endif
173
174 #ifndef IN_MULTICAST
175 #define IN_MULTICAST(a) ((((uint32_t)(a)) & 0xf0000000) == 0xe0000000)
176 #endif
177 #ifndef IN6_IS_ADDR_MULTICAST
178 #define IN6_IS_ADDR_MULTICAST(a) (((uint8_t *) (a))[0] == 0xff)
179 #endif
180
181 int ff_is_multicast_address(struct sockaddr *addr);
182
183 #endif /* AVFORMAT_NETWORK_H */