network: Don't redefine error codes if they already exist in errno.h
[libav.git] / libavformat / network.h
CommitLineData
42572ef5 1/*
2912e87a 2 * Copyright (c) 2007 The Libav Project
42572ef5 3 *
2912e87a 4 * This file is part of Libav.
42572ef5 5 *
2912e87a 6 * Libav is free software; you can redistribute it and/or
42572ef5
RP
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 *
2912e87a 11 * Libav is distributed in the hope that it will be useful,
42572ef5
RP
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
2912e87a 17 * License along with Libav; if not, write to the Free Software
42572ef5
RP
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
98790382
SS
21#ifndef AVFORMAT_NETWORK_H
22#define AVFORMAT_NETWORK_H
42572ef5 23
8d459acc
DB
24#include <errno.h>
25
da837937 26#include "config.h"
8d459acc 27#include "libavutil/error.h"
a2031251 28#include "os_support.h"
da837937 29
39dba5aa
MS
30#if HAVE_UNISTD_H
31#include <unistd.h>
32#endif
33
b250f9c6 34#if HAVE_WINSOCK2_H
5676d140
AB
35#include <winsock2.h>
36#include <ws2tcpip.h>
37
4b1b1449 38#ifndef EPROTONOSUPPORT
28c4741a 39#define EPROTONOSUPPORT WSAEPROTONOSUPPORT
4b1b1449
RB
40#endif
41#ifndef ETIMEDOUT
28c4741a 42#define ETIMEDOUT WSAETIMEDOUT
4b1b1449
RB
43#endif
44#ifndef ECONNREFUSED
28c4741a 45#define ECONNREFUSED WSAECONNREFUSED
4b1b1449
RB
46#endif
47#ifndef EINPROGRESS
28c4741a 48#define EINPROGRESS WSAEINPROGRESS
4b1b1449
RB
49#endif
50
56168769
MS
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)
28c4741a 53
f6d37100 54int ff_neterrno(void);
5676d140 55#else
42572ef5
RP
56#include <sys/types.h>
57#include <sys/socket.h>
58#include <netinet/in.h>
42572ef5
RP
59#include <netdb.h>
60
4aecee7f 61#define ff_neterrno() AVERROR(errno)
5676d140
AB
62#endif
63
b250f9c6 64#if HAVE_ARPA_INET_H
5676d140
AB
65#include <arpa/inet.h>
66#endif
8da4034f 67
ebba2b3e
LB
68#if HAVE_POLL_H
69#include <poll.h>
70#endif
71
ba472aaf
AB
72int ff_socket_nonblock(int socket, int enable);
73
ce145690 74extern int ff_network_inited_globally;
f6d37100
MS
75int ff_network_init(void);
76void ff_network_close(void);
77
48e59ad8
MS
78void ff_tls_init(void);
79void ff_tls_deinit(void);
80
f6d37100 81int ff_network_wait_fd(int fd, int write);
1642cb6b 82
ac11d562 83int ff_inet_aton (const char * str, struct in_addr * add);
c9fdab0d 84
34a65f1f
MS
85#if !HAVE_STRUCT_SOCKADDR_STORAGE
86struct sockaddr_storage {
3d7b42f9
MS
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];
34a65f1f
MS
96};
97#endif
98
fa053ca7
MS
99#if !HAVE_STRUCT_ADDRINFO
100struct 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
5d629b72
MS
117#ifndef EAI_FAMILY
118#define EAI_FAMILY 5
119#endif
120
121#ifndef EAI_NONAME
122#define EAI_NONAME 8
123#endif
124
fa053ca7
MS
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
5d629b72
MS
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
fa053ca7
MS
157#if !HAVE_GETADDRINFO
158int ff_getaddrinfo(const char *node, const char *service,
159 const struct addrinfo *hints, struct addrinfo **res);
160void ff_freeaddrinfo(struct addrinfo *res);
5d629b72
MS
161int ff_getnameinfo(const struct sockaddr *sa, int salen,
162 char *host, int hostlen,
163 char *serv, int servlen, int flags);
04a2b04b 164const char *ff_gai_strerror(int ecode);
fa053ca7
MS
165#define getaddrinfo ff_getaddrinfo
166#define freeaddrinfo ff_freeaddrinfo
5d629b72 167#define getnameinfo ff_getnameinfo
04a2b04b 168#define gai_strerror ff_gai_strerror
fa053ca7
MS
169#endif
170
f0d8ac52
RB
171#ifndef INET6_ADDRSTRLEN
172#define INET6_ADDRSTRLEN INET_ADDRSTRLEN
173#endif
174
f63630cd
MS
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
f6d37100 182int ff_is_multicast_address(struct sockaddr *addr);
7ac57fa5 183
98790382 184#endif /* AVFORMAT_NETWORK_H */