2 * Copyright (c) 2007 The Libav Project
4 * This file is part of Libav.
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.
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.
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
21 #ifndef AVFORMAT_NETWORK_H
22 #define AVFORMAT_NETWORK_H
25 #include "os_support.h"
31 #define EPROTONOSUPPORT WSAEPROTONOSUPPORT
32 #define ETIMEDOUT WSAETIMEDOUT
33 #define ECONNREFUSED WSAECONNREFUSED
34 #define EINPROGRESS WSAEINPROGRESS
36 static inline int ff_neterrno() {
37 int err = WSAGetLastError();
40 return AVERROR(EAGAIN);
42 return AVERROR(EINTR);
47 #include <sys/types.h>
48 #include <sys/socket.h>
49 #include <netinet/in.h>
52 #define ff_neterrno() AVERROR(errno)
56 #include <arpa/inet.h>
63 int ff_socket_nonblock(int socket, int enable);
65 static inline int ff_network_init(void)
69 if (WSAStartup(MAKEWORD(1,1), &wsaData))
75 static inline int ff_network_wait_fd(int fd, int write)
77 int ev = write ? POLLOUT : POLLIN;
78 struct pollfd p = { .fd = fd, .events = ev, .revents = 0 };
80 ret = poll(&p, 1, 100);
81 return ret < 0 ? ff_neterrno() : p.revents & ev ? 0 : AVERROR(EAGAIN);
84 static inline void ff_network_close(void)
91 int ff_inet_aton (const char * str, struct in_addr * add);
93 #if !HAVE_STRUCT_SOCKADDR_STORAGE
94 struct sockaddr_storage {
95 #if HAVE_STRUCT_SOCKADDR_SA_LEN
107 #if !HAVE_STRUCT_ADDRINFO
114 struct sockaddr *ai_addr;
116 struct addrinfo *ai_next;
120 /* getaddrinfo constants */
138 #define AI_CANONNAME 2
141 #ifndef AI_NUMERICHOST
142 #define AI_NUMERICHOST 4
149 #ifndef NI_NUMERICHOST
150 #define NI_NUMERICHOST 2
157 #ifndef NI_NUMERICSERV
158 #define NI_NUMERICSERV 8
165 #if !HAVE_GETADDRINFO
166 int ff_getaddrinfo(const char *node, const char *service,
167 const struct addrinfo *hints, struct addrinfo **res);
168 void ff_freeaddrinfo(struct addrinfo *res);
169 int ff_getnameinfo(const struct sockaddr *sa, int salen,
170 char *host, int hostlen,
171 char *serv, int servlen, int flags);
172 const char *ff_gai_strerror(int ecode);
173 #define getaddrinfo ff_getaddrinfo
174 #define freeaddrinfo ff_freeaddrinfo
175 #define getnameinfo ff_getnameinfo
176 #define gai_strerror ff_gai_strerror
179 #ifndef INET6_ADDRSTRLEN
180 #define INET6_ADDRSTRLEN INET_ADDRSTRLEN
184 #define IN_MULTICAST(a) ((((uint32_t)(a)) & 0xf0000000) == 0xe0000000)
186 #ifndef IN6_IS_ADDR_MULTICAST
187 #define IN6_IS_ADDR_MULTICAST(a) (((uint8_t *) (a))[0] == 0xff)
190 static inline int ff_is_multicast_address(struct sockaddr *addr)
192 if (addr->sa_family == AF_INET) {
193 return IN_MULTICAST(ntohl(((struct sockaddr_in *)addr)->sin_addr.s_addr));
195 #if HAVE_STRUCT_SOCKADDR_IN6
196 if (addr->sa_family == AF_INET6) {
197 return IN6_IS_ADDR_MULTICAST(&((struct sockaddr_in6 *)addr)->sin6_addr);
204 #endif /* AVFORMAT_NETWORK_H */