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