2 * Copyright (c) 2007 The FFmpeg Project
4 * This file is part of FFmpeg.
6 * FFmpeg 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 * FFmpeg 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 FFmpeg; 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
30 #define EPROTONOSUPPORT WSAEPROTONOSUPPORT
31 #define ETIMEDOUT WSAETIMEDOUT
32 #define ECONNREFUSED WSAECONNREFUSED
33 #define EINPROGRESS WSAEINPROGRESS
35 static inline int ff_neterrno() {
36 int err = WSAGetLastError();
39 return AVERROR(EAGAIN);
41 return AVERROR(EINTR);
46 #include <sys/types.h>
47 #include <sys/socket.h>
48 #include <netinet/in.h>
51 #define ff_neterrno() AVERROR(errno)
55 #include <arpa/inet.h>
58 int ff_socket_nonblock(int socket, int enable);
60 static inline int ff_network_init(void)
64 if (WSAStartup(MAKEWORD(1,1), &wsaData))
70 static inline void ff_network_close(void)
77 int ff_inet_aton (const char * str, struct in_addr * add);
79 #if !HAVE_STRUCT_SOCKADDR_STORAGE
80 struct sockaddr_storage {
81 #if HAVE_STRUCT_SOCKADDR_SA_LEN
93 #if !HAVE_STRUCT_ADDRINFO
100 struct sockaddr *ai_addr;
102 struct addrinfo *ai_next;
106 /* getaddrinfo constants */
124 #define AI_CANONNAME 2
127 #ifndef AI_NUMERICHOST
128 #define AI_NUMERICHOST 4
135 #ifndef NI_NUMERICHOST
136 #define NI_NUMERICHOST 2
143 #ifndef NI_NUMERICSERV
144 #define NI_NUMERICSERV 8
151 #if !HAVE_GETADDRINFO
152 int ff_getaddrinfo(const char *node, const char *service,
153 const struct addrinfo *hints, struct addrinfo **res);
154 void ff_freeaddrinfo(struct addrinfo *res);
155 int ff_getnameinfo(const struct sockaddr *sa, int salen,
156 char *host, int hostlen,
157 char *serv, int servlen, int flags);
158 const char *ff_gai_strerror(int ecode);
159 #define getaddrinfo ff_getaddrinfo
160 #define freeaddrinfo ff_freeaddrinfo
161 #define getnameinfo ff_getnameinfo
162 #define gai_strerror ff_gai_strerror
165 #ifndef INET6_ADDRSTRLEN
166 #define INET6_ADDRSTRLEN INET_ADDRSTRLEN
170 #define IN_MULTICAST(a) ((((uint32_t)(a)) & 0xf0000000) == 0xe0000000)
172 #ifndef IN6_IS_ADDR_MULTICAST
173 #define IN6_IS_ADDR_MULTICAST(a) (((uint8_t *) (a))[0] == 0xff)
176 static inline int ff_is_multicast_address(struct sockaddr *addr)
178 if (addr->sa_family == AF_INET) {
179 return IN_MULTICAST(ntohl(((struct sockaddr_in *)addr)->sin_addr.s_addr));
181 #if HAVE_STRUCT_SOCKADDR_IN6
182 if (addr->sa_family == AF_INET6) {
183 return IN6_IS_ADDR_MULTICAST(&((struct sockaddr_in6 *)addr)->sin6_addr);
190 #endif /* AVFORMAT_NETWORK_H */