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.

213 lines
4.4KB

  1. /*
  2. * Copyright (c) 2007 The Libav Project
  3. *
  4. * This file is part of Libav.
  5. *
  6. * Libav 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. * Libav 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 Libav; 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. #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. int ff_inet_aton (const char * str, struct in_addr * add);
  69. #if !HAVE_STRUCT_SOCKADDR_STORAGE
  70. struct sockaddr_storage {
  71. #if HAVE_STRUCT_SOCKADDR_SA_LEN
  72. uint8_t ss_len;
  73. uint8_t ss_family;
  74. #else
  75. uint16_t ss_family;
  76. #endif
  77. char ss_pad1[6];
  78. int64_t ss_align;
  79. char ss_pad2[112];
  80. };
  81. #endif
  82. #if !HAVE_STRUCT_ADDRINFO
  83. struct addrinfo {
  84. int ai_flags;
  85. int ai_family;
  86. int ai_socktype;
  87. int ai_protocol;
  88. int ai_addrlen;
  89. struct sockaddr *ai_addr;
  90. char *ai_canonname;
  91. struct addrinfo *ai_next;
  92. };
  93. #endif
  94. /* getaddrinfo constants */
  95. #ifndef EAI_AGAIN
  96. #define EAI_AGAIN 2
  97. #endif
  98. #ifndef EAI_BADFLAGS
  99. #define EAI_BADFLAGS 3
  100. #endif
  101. #ifndef EAI_FAIL
  102. #define EAI_FAIL 4
  103. #endif
  104. #ifndef EAI_FAMILY
  105. #define EAI_FAMILY 5
  106. #endif
  107. #ifndef EAI_MEMORY
  108. #define EAI_MEMORY 6
  109. #endif
  110. #ifndef EAI_NODATA
  111. #define EAI_NODATA 7
  112. #endif
  113. #ifndef EAI_NONAME
  114. #define EAI_NONAME 8
  115. #endif
  116. #ifndef EAI_SERVICE
  117. #define EAI_SERVICE 9
  118. #endif
  119. #ifndef EAI_SOCKTYPE
  120. #define EAI_SOCKTYPE 10
  121. #endif
  122. #ifndef AI_PASSIVE
  123. #define AI_PASSIVE 1
  124. #endif
  125. #ifndef AI_CANONNAME
  126. #define AI_CANONNAME 2
  127. #endif
  128. #ifndef AI_NUMERICHOST
  129. #define AI_NUMERICHOST 4
  130. #endif
  131. #ifndef NI_NOFQDN
  132. #define NI_NOFQDN 1
  133. #endif
  134. #ifndef NI_NUMERICHOST
  135. #define NI_NUMERICHOST 2
  136. #endif
  137. #ifndef NI_NAMERQD
  138. #define NI_NAMERQD 4
  139. #endif
  140. #ifndef NI_NUMERICSERV
  141. #define NI_NUMERICSERV 8
  142. #endif
  143. #ifndef NI_DGRAM
  144. #define NI_DGRAM 16
  145. #endif
  146. #if !HAVE_GETADDRINFO
  147. int ff_getaddrinfo(const char *node, const char *service,
  148. const struct addrinfo *hints, struct addrinfo **res);
  149. void ff_freeaddrinfo(struct addrinfo *res);
  150. int ff_getnameinfo(const struct sockaddr *sa, int salen,
  151. char *host, int hostlen,
  152. char *serv, int servlen, int flags);
  153. #define getaddrinfo ff_getaddrinfo
  154. #define freeaddrinfo ff_freeaddrinfo
  155. #define getnameinfo ff_getnameinfo
  156. #endif
  157. #if !HAVE_GETADDRINFO || HAVE_WINSOCK2_H
  158. const char *ff_gai_strerror(int ecode);
  159. #undef gai_strerror
  160. #define gai_strerror ff_gai_strerror
  161. #endif
  162. #ifndef INADDR_LOOPBACK
  163. #define INADDR_LOOPBACK 0x7f000001
  164. #endif
  165. #ifndef INET_ADDRSTRLEN
  166. #define INET_ADDRSTRLEN 16
  167. #endif
  168. #ifndef INET6_ADDRSTRLEN
  169. #define INET6_ADDRSTRLEN INET_ADDRSTRLEN
  170. #endif
  171. #ifndef IN_MULTICAST
  172. #define IN_MULTICAST(a) ((((uint32_t)(a)) & 0xf0000000) == 0xe0000000)
  173. #endif
  174. #ifndef IN6_IS_ADDR_MULTICAST
  175. #define IN6_IS_ADDR_MULTICAST(a) (((uint8_t *) (a))[0] == 0xff)
  176. #endif
  177. int ff_is_multicast_address(struct sockaddr *addr);
  178. #endif /* AVFORMAT_NETWORK_H */