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 
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 
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
88 #if HAVE_STRUCT_SOCKADDR_SA_LEN
89  uint8_t ss_len;
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;
107  struct sockaddr *ai_addr;
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 */
char ss_pad1[6]
Definition: network.h:94
int ff_network_wait_fd(int fd, int write)
Definition: network.c:139
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:177
uint8_t
miscellaneous OS support macros and functions.
uint16_t ss_family
Definition: network.h:92
void ff_tls_init(void)
Definition: network.c:64
static int flags
Definition: log.c:42
void ff_network_close(void)
Definition: network.c:148
error code definitions
const char * ff_gai_strerror(int ecode)
char * ai_canonname
Definition: network.h:108
void ff_freeaddrinfo(struct addrinfo *res)
int ai_addrlen
Definition: network.h:106
int ff_inet_aton(const char *str, struct in_addr *add)
#define ff_neterrno()
Definition: network.h:62
int ff_socket_nonblock(int socket, int enable)
int64_t ss_align
Definition: network.h:95
int ai_protocol
Definition: network.h:105
void ff_tls_deinit(void)
Definition: network.c:96
int ai_socktype
Definition: network.h:104
int ff_network_inited_globally
Definition: network.c:119
struct addrinfo * ai_next
Definition: network.h:109
int ff_network_init(void)
Definition: network.c:121
char ss_pad2[112]
Definition: network.h:96
int ff_getaddrinfo(const char *node, const char *service, const struct addrinfo *hints, struct addrinfo **res)
int ai_flags
Definition: network.h:102
struct sockaddr * ai_addr
Definition: network.h:107
int ai_family
Definition: network.h:103