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