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