]> git.sesse.net Git - ffmpeg/blob - libavformat/network.h
lavf: Add functions for SRTP decryption/encryption
[ffmpeg] / libavformat / network.h
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
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 int ff_inet_aton (const char * str, struct in_addr * add);
85
86 #if !HAVE_STRUCT_SOCKADDR_STORAGE
87 struct sockaddr_storage {
88 #if HAVE_STRUCT_SOCKADDR_SA_LEN
89     uint8_t ss_len;
90     uint8_t ss_family;
91 #else
92     uint16_t ss_family;
93 #endif
94     char ss_pad1[6];
95     int64_t ss_align;
96     char ss_pad2[112];
97 };
98 #endif
99
100 #if !HAVE_STRUCT_ADDRINFO
101 struct addrinfo {
102     int ai_flags;
103     int ai_family;
104     int ai_socktype;
105     int ai_protocol;
106     int ai_addrlen;
107     struct sockaddr *ai_addr;
108     char *ai_canonname;
109     struct addrinfo *ai_next;
110 };
111 #endif
112
113 /* getaddrinfo constants */
114 #ifndef EAI_AGAIN
115 #define EAI_AGAIN 2
116 #endif
117 #ifndef EAI_BADFLAGS
118 #define EAI_BADFLAGS 3
119 #endif
120 #ifndef EAI_FAIL
121 #define EAI_FAIL 4
122 #endif
123 #ifndef EAI_FAMILY
124 #define EAI_FAMILY 5
125 #endif
126 #ifndef EAI_MEMORY
127 #define EAI_MEMORY 6
128 #endif
129 #ifndef EAI_NODATA
130 #define EAI_NODATA 7
131 #endif
132 #ifndef EAI_NONAME
133 #define EAI_NONAME 8
134 #endif
135 #ifndef EAI_SERVICE
136 #define EAI_SERVICE 9
137 #endif
138 #ifndef EAI_SOCKTYPE
139 #define EAI_SOCKTYPE 10
140 #endif
141
142 #ifndef AI_PASSIVE
143 #define AI_PASSIVE 1
144 #endif
145
146 #ifndef AI_CANONNAME
147 #define AI_CANONNAME 2
148 #endif
149
150 #ifndef AI_NUMERICHOST
151 #define AI_NUMERICHOST 4
152 #endif
153
154 #ifndef NI_NOFQDN
155 #define NI_NOFQDN 1
156 #endif
157
158 #ifndef NI_NUMERICHOST
159 #define NI_NUMERICHOST 2
160 #endif
161
162 #ifndef NI_NAMERQD
163 #define NI_NAMERQD 4
164 #endif
165
166 #ifndef NI_NUMERICSERV
167 #define NI_NUMERICSERV 8
168 #endif
169
170 #ifndef NI_DGRAM
171 #define NI_DGRAM 16
172 #endif
173
174 #if !HAVE_GETADDRINFO
175 int ff_getaddrinfo(const char *node, const char *service,
176                    const struct addrinfo *hints, struct addrinfo **res);
177 void ff_freeaddrinfo(struct addrinfo *res);
178 int ff_getnameinfo(const struct sockaddr *sa, int salen,
179                    char *host, int hostlen,
180                    char *serv, int servlen, int flags);
181 #define getaddrinfo ff_getaddrinfo
182 #define freeaddrinfo ff_freeaddrinfo
183 #define getnameinfo ff_getnameinfo
184 #endif
185 #if !HAVE_GETADDRINFO || HAVE_WINSOCK2_H
186 const char *ff_gai_strerror(int ecode);
187 #undef gai_strerror
188 #define gai_strerror ff_gai_strerror
189 #endif
190
191 #ifndef INADDR_LOOPBACK
192 #define INADDR_LOOPBACK 0x7f000001
193 #endif
194
195 #ifndef INET_ADDRSTRLEN
196 #define INET_ADDRSTRLEN 16
197 #endif
198
199 #ifndef INET6_ADDRSTRLEN
200 #define INET6_ADDRSTRLEN INET_ADDRSTRLEN
201 #endif
202
203 #ifndef IN_MULTICAST
204 #define IN_MULTICAST(a) ((((uint32_t)(a)) & 0xf0000000) == 0xe0000000)
205 #endif
206 #ifndef IN6_IS_ADDR_MULTICAST
207 #define IN6_IS_ADDR_MULTICAST(a) (((uint8_t *) (a))[0] == 0xff)
208 #endif
209
210 int ff_is_multicast_address(struct sockaddr *addr);
211
212 #endif /* AVFORMAT_NETWORK_H */