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.

217 lines
4.9KB

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