00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef AVFORMAT_NETWORK_H
00022 #define AVFORMAT_NETWORK_H
00023
00024 #include <errno.h>
00025 #include <stdint.h>
00026
00027 #include "config.h"
00028 #include "libavutil/error.h"
00029 #include "os_support.h"
00030 #include "avio.h"
00031
00032 #if HAVE_UNISTD_H
00033 #include <unistd.h>
00034 #endif
00035
00036 #if HAVE_WINSOCK2_H
00037 #include <winsock2.h>
00038 #include <ws2tcpip.h>
00039
00040 #ifndef EPROTONOSUPPORT
00041 #define EPROTONOSUPPORT WSAEPROTONOSUPPORT
00042 #endif
00043 #ifndef ETIMEDOUT
00044 #define ETIMEDOUT WSAETIMEDOUT
00045 #endif
00046 #ifndef ECONNREFUSED
00047 #define ECONNREFUSED WSAECONNREFUSED
00048 #endif
00049 #ifndef EINPROGRESS
00050 #define EINPROGRESS WSAEINPROGRESS
00051 #endif
00052
00053 #define getsockopt(a, b, c, d, e) getsockopt(a, b, c, (char*) d, e)
00054 #define setsockopt(a, b, c, d, e) setsockopt(a, b, c, (const char*) d, e)
00055
00056 int ff_neterrno(void);
00057 #else
00058 #include <sys/types.h>
00059 #include <sys/socket.h>
00060 #include <netinet/in.h>
00061 #include <netdb.h>
00062
00063 #define ff_neterrno() AVERROR(errno)
00064 #endif
00065
00066 #if HAVE_ARPA_INET_H
00067 #include <arpa/inet.h>
00068 #endif
00069
00070 #if HAVE_POLL_H
00071 #include <poll.h>
00072 #endif
00073
00074 int ff_socket_nonblock(int socket, int enable);
00075
00076 extern int ff_network_inited_globally;
00077 int ff_network_init(void);
00078 void ff_network_close(void);
00079
00080 void ff_tls_init(void);
00081 void ff_tls_deinit(void);
00082
00083 int ff_network_wait_fd(int fd, int write);
00084
00095 int ff_network_wait_fd_timeout(int fd, int write, int64_t timeout, AVIOInterruptCB *int_cb);
00096
00097 int ff_inet_aton (const char * str, struct in_addr * add);
00098
00099 #if !HAVE_STRUCT_SOCKADDR_STORAGE
00100 struct sockaddr_storage {
00101 #if HAVE_STRUCT_SOCKADDR_SA_LEN
00102 uint8_t ss_len;
00103 uint8_t ss_family;
00104 #else
00105 uint16_t ss_family;
00106 #endif
00107 char ss_pad1[6];
00108 int64_t ss_align;
00109 char ss_pad2[112];
00110 };
00111 #endif
00112
00113 #if !HAVE_STRUCT_ADDRINFO
00114 struct addrinfo {
00115 int ai_flags;
00116 int ai_family;
00117 int ai_socktype;
00118 int ai_protocol;
00119 int ai_addrlen;
00120 struct sockaddr *ai_addr;
00121 char *ai_canonname;
00122 struct addrinfo *ai_next;
00123 };
00124 #endif
00125
00126
00127 #ifndef EAI_AGAIN
00128 #define EAI_AGAIN 2
00129 #endif
00130 #ifndef EAI_BADFLAGS
00131 #define EAI_BADFLAGS 3
00132 #endif
00133 #ifndef EAI_FAIL
00134 #define EAI_FAIL 4
00135 #endif
00136 #ifndef EAI_FAMILY
00137 #define EAI_FAMILY 5
00138 #endif
00139 #ifndef EAI_MEMORY
00140 #define EAI_MEMORY 6
00141 #endif
00142 #ifndef EAI_NODATA
00143 #define EAI_NODATA 7
00144 #endif
00145 #ifndef EAI_NONAME
00146 #define EAI_NONAME 8
00147 #endif
00148 #ifndef EAI_SERVICE
00149 #define EAI_SERVICE 9
00150 #endif
00151 #ifndef EAI_SOCKTYPE
00152 #define EAI_SOCKTYPE 10
00153 #endif
00154
00155 #ifndef AI_PASSIVE
00156 #define AI_PASSIVE 1
00157 #endif
00158
00159 #ifndef AI_CANONNAME
00160 #define AI_CANONNAME 2
00161 #endif
00162
00163 #ifndef AI_NUMERICHOST
00164 #define AI_NUMERICHOST 4
00165 #endif
00166
00167 #ifndef NI_NOFQDN
00168 #define NI_NOFQDN 1
00169 #endif
00170
00171 #ifndef NI_NUMERICHOST
00172 #define NI_NUMERICHOST 2
00173 #endif
00174
00175 #ifndef NI_NAMERQD
00176 #define NI_NAMERQD 4
00177 #endif
00178
00179 #ifndef NI_NUMERICSERV
00180 #define NI_NUMERICSERV 8
00181 #endif
00182
00183 #ifndef NI_DGRAM
00184 #define NI_DGRAM 16
00185 #endif
00186
00187 #if !HAVE_GETADDRINFO
00188 int ff_getaddrinfo(const char *node, const char *service,
00189 const struct addrinfo *hints, struct addrinfo **res);
00190 void ff_freeaddrinfo(struct addrinfo *res);
00191 int ff_getnameinfo(const struct sockaddr *sa, int salen,
00192 char *host, int hostlen,
00193 char *serv, int servlen, int flags);
00194 #define getaddrinfo ff_getaddrinfo
00195 #define freeaddrinfo ff_freeaddrinfo
00196 #define getnameinfo ff_getnameinfo
00197 #endif
00198 #if !HAVE_GETADDRINFO || HAVE_WINSOCK2_H
00199 const char *ff_gai_strerror(int ecode);
00200 #undef gai_strerror
00201 #define gai_strerror ff_gai_strerror
00202 #endif
00203
00204 #ifndef INADDR_LOOPBACK
00205 #define INADDR_LOOPBACK 0x7f000001
00206 #endif
00207
00208 #ifndef INET_ADDRSTRLEN
00209 #define INET_ADDRSTRLEN 16
00210 #endif
00211
00212 #ifndef INET6_ADDRSTRLEN
00213 #define INET6_ADDRSTRLEN INET_ADDRSTRLEN
00214 #endif
00215
00216 #ifndef IN_MULTICAST
00217 #define IN_MULTICAST(a) ((((uint32_t)(a)) & 0xf0000000) == 0xe0000000)
00218 #endif
00219 #ifndef IN6_IS_ADDR_MULTICAST
00220 #define IN6_IS_ADDR_MULTICAST(a) (((uint8_t *) (a))[0] == 0xff)
00221 #endif
00222
00223 int ff_is_multicast_address(struct sockaddr *addr);
00224
00225 #endif