You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

226 lines
5.0KB

  1. /*
  2. * Copyright (c) 2007 The FFmpeg Project
  3. *
  4. * This file is part of FFmpeg.
  5. *
  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.
  10. *
  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.
  15. *
  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
  19. */
  20. #ifndef AVFORMAT_NETWORK_H
  21. #define AVFORMAT_NETWORK_H
  22. #include <errno.h>
  23. #include <stdint.h>
  24. #include "config.h"
  25. #include "libavutil/error.h"
  26. #include "os_support.h"
  27. #include "avio.h"
  28. #if HAVE_UNISTD_H
  29. #include <unistd.h>
  30. #endif
  31. #if HAVE_WINSOCK2_H
  32. #include <winsock2.h>
  33. #include <ws2tcpip.h>
  34. #ifndef EPROTONOSUPPORT
  35. #define EPROTONOSUPPORT WSAEPROTONOSUPPORT
  36. #endif
  37. #ifndef ETIMEDOUT
  38. #define ETIMEDOUT WSAETIMEDOUT
  39. #endif
  40. #ifndef ECONNREFUSED
  41. #define ECONNREFUSED WSAECONNREFUSED
  42. #endif
  43. #ifndef EINPROGRESS
  44. #define EINPROGRESS WSAEINPROGRESS
  45. #endif
  46. #define getsockopt(a, b, c, d, e) getsockopt(a, b, c, (char*) d, e)
  47. #define setsockopt(a, b, c, d, e) setsockopt(a, b, c, (const char*) d, e)
  48. int ff_neterrno(void);
  49. #else
  50. #include <sys/types.h>
  51. #include <sys/socket.h>
  52. #include <netinet/in.h>
  53. #include <netdb.h>
  54. #define ff_neterrno() AVERROR(errno)
  55. #endif
  56. #if HAVE_ARPA_INET_H
  57. #include <arpa/inet.h>
  58. #endif
  59. #if HAVE_POLL_H
  60. #include <poll.h>
  61. #endif
  62. int ff_socket_nonblock(int socket, int enable);
  63. extern int ff_network_inited_globally;
  64. int ff_network_init(void);
  65. void ff_network_close(void);
  66. void ff_tls_init(void);
  67. void ff_tls_deinit(void);
  68. int ff_network_wait_fd(int fd, int write);
  69. /**
  70. * This works similarly to ff_network_wait_fd, but waits up to 'timeout' microseconds
  71. * Uses ff_network_wait_fd in a loop
  72. *
  73. * @fd Socket descriptor
  74. * @write Set 1 to wait for socket able to be read, 0 to be written
  75. * @timeout Timeout interval, in microseconds. Actual precision is 100000 mcs, due to ff_network_wait_fd usage
  76. * @param int_cb Interrupt callback, is checked after each ff_network_wait_fd call
  77. * @return 0 if data can be read/written, AVERROR(ETIMEDOUT) if timeout expired, or negative error code
  78. */
  79. int ff_network_wait_fd_timeout(int fd, int write, int64_t timeout, AVIOInterruptCB *int_cb);
  80. int ff_inet_aton (const char * str, struct in_addr * add);
  81. #if !HAVE_STRUCT_SOCKADDR_STORAGE
  82. struct sockaddr_storage {
  83. #if HAVE_STRUCT_SOCKADDR_SA_LEN
  84. uint8_t ss_len;
  85. uint8_t ss_family;
  86. #else
  87. uint16_t ss_family;
  88. #endif
  89. char ss_pad1[6];
  90. int64_t ss_align;
  91. char ss_pad2[112];
  92. };
  93. #endif
  94. #if !HAVE_STRUCT_ADDRINFO
  95. struct addrinfo {
  96. int ai_flags;
  97. int ai_family;
  98. int ai_socktype;
  99. int ai_protocol;
  100. int ai_addrlen;
  101. struct sockaddr *ai_addr;
  102. char *ai_canonname;
  103. struct addrinfo *ai_next;
  104. };
  105. #endif
  106. /* getaddrinfo constants */
  107. #ifndef EAI_AGAIN
  108. #define EAI_AGAIN 2
  109. #endif
  110. #ifndef EAI_BADFLAGS
  111. #define EAI_BADFLAGS 3
  112. #endif
  113. #ifndef EAI_FAIL
  114. #define EAI_FAIL 4
  115. #endif
  116. #ifndef EAI_FAMILY
  117. #define EAI_FAMILY 5
  118. #endif
  119. #ifndef EAI_MEMORY
  120. #define EAI_MEMORY 6
  121. #endif
  122. #ifndef EAI_NODATA
  123. #define EAI_NODATA 7
  124. #endif
  125. #ifndef EAI_NONAME
  126. #define EAI_NONAME 8
  127. #endif
  128. #ifndef EAI_SERVICE
  129. #define EAI_SERVICE 9
  130. #endif
  131. #ifndef EAI_SOCKTYPE
  132. #define EAI_SOCKTYPE 10
  133. #endif
  134. #ifndef AI_PASSIVE
  135. #define AI_PASSIVE 1
  136. #endif
  137. #ifndef AI_CANONNAME
  138. #define AI_CANONNAME 2
  139. #endif
  140. #ifndef AI_NUMERICHOST
  141. #define AI_NUMERICHOST 4
  142. #endif
  143. #ifndef NI_NOFQDN
  144. #define NI_NOFQDN 1
  145. #endif
  146. #ifndef NI_NUMERICHOST
  147. #define NI_NUMERICHOST 2
  148. #endif
  149. #ifndef NI_NAMERQD
  150. #define NI_NAMERQD 4
  151. #endif
  152. #ifndef NI_NUMERICSERV
  153. #define NI_NUMERICSERV 8
  154. #endif
  155. #ifndef NI_DGRAM
  156. #define NI_DGRAM 16
  157. #endif
  158. #if !HAVE_GETADDRINFO
  159. int ff_getaddrinfo(const char *node, const char *service,
  160. const struct addrinfo *hints, struct addrinfo **res);
  161. void ff_freeaddrinfo(struct addrinfo *res);
  162. int ff_getnameinfo(const struct sockaddr *sa, int salen,
  163. char *host, int hostlen,
  164. char *serv, int servlen, int flags);
  165. #define getaddrinfo ff_getaddrinfo
  166. #define freeaddrinfo ff_freeaddrinfo
  167. #define getnameinfo ff_getnameinfo
  168. #endif
  169. #if !HAVE_GETADDRINFO || HAVE_WINSOCK2_H
  170. const char *ff_gai_strerror(int ecode);
  171. #undef gai_strerror
  172. #define gai_strerror ff_gai_strerror
  173. #endif
  174. #ifndef INADDR_LOOPBACK
  175. #define INADDR_LOOPBACK 0x7f000001
  176. #endif
  177. #ifndef INET_ADDRSTRLEN
  178. #define INET_ADDRSTRLEN 16
  179. #endif
  180. #ifndef INET6_ADDRSTRLEN
  181. #define INET6_ADDRSTRLEN INET_ADDRSTRLEN
  182. #endif
  183. #ifndef IN_MULTICAST
  184. #define IN_MULTICAST(a) ((((uint32_t)(a)) & 0xf0000000) == 0xe0000000)
  185. #endif
  186. #ifndef IN6_IS_ADDR_MULTICAST
  187. #define IN6_IS_ADDR_MULTICAST(a) (((uint8_t *) (a))[0] == 0xff)
  188. #endif
  189. int ff_is_multicast_address(struct sockaddr *addr);
  190. #endif /* AVFORMAT_NETWORK_H */