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