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