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.

182 lines
3.8KB

  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. #if HAVE_WINSOCK2_H
  27. #include <winsock2.h>
  28. #include <ws2tcpip.h>
  29. #ifdef EPROTONOSUPPORT
  30. # undef EPROTONOSUPPORT
  31. #endif
  32. #define EPROTONOSUPPORT WSAEPROTONOSUPPORT
  33. #ifdef ETIMEDOUT
  34. # undef ETIMEDOUT
  35. #endif
  36. #define ETIMEDOUT WSAETIMEDOUT
  37. #ifdef ECONNREFUSED
  38. # undef ECONNREFUSED
  39. #endif
  40. #define ECONNREFUSED WSAECONNREFUSED
  41. #ifdef EINPROGRESS
  42. # undef EINPROGRESS
  43. #endif
  44. #define EINPROGRESS WSAEINPROGRESS
  45. int ff_neterrno(void);
  46. #else
  47. #include <sys/types.h>
  48. #include <sys/socket.h>
  49. #include <netinet/in.h>
  50. #include <netdb.h>
  51. #define ff_neterrno() AVERROR(errno)
  52. #endif
  53. #if HAVE_ARPA_INET_H
  54. #include <arpa/inet.h>
  55. #endif
  56. #if HAVE_POLL_H
  57. #include <poll.h>
  58. #endif
  59. int ff_socket_nonblock(int socket, int enable);
  60. extern int ff_network_inited_globally;
  61. int ff_network_init(void);
  62. void ff_network_close(void);
  63. void ff_tls_init(void);
  64. void ff_tls_deinit(void);
  65. int ff_network_wait_fd(int fd, int write);
  66. int ff_inet_aton (const char * str, struct in_addr * add);
  67. #if !HAVE_STRUCT_SOCKADDR_STORAGE
  68. struct sockaddr_storage {
  69. #if HAVE_STRUCT_SOCKADDR_SA_LEN
  70. uint8_t ss_len;
  71. uint8_t ss_family;
  72. #else
  73. uint16_t ss_family;
  74. #endif
  75. char ss_pad1[6];
  76. int64_t ss_align;
  77. char ss_pad2[112];
  78. };
  79. #endif
  80. #if !HAVE_STRUCT_ADDRINFO
  81. struct addrinfo {
  82. int ai_flags;
  83. int ai_family;
  84. int ai_socktype;
  85. int ai_protocol;
  86. int ai_addrlen;
  87. struct sockaddr *ai_addr;
  88. char *ai_canonname;
  89. struct addrinfo *ai_next;
  90. };
  91. #endif
  92. /* getaddrinfo constants */
  93. #ifndef EAI_FAIL
  94. #define EAI_FAIL 4
  95. #endif
  96. #ifndef EAI_FAMILY
  97. #define EAI_FAMILY 5
  98. #endif
  99. #ifndef EAI_NONAME
  100. #define EAI_NONAME 8
  101. #endif
  102. #ifndef AI_PASSIVE
  103. #define AI_PASSIVE 1
  104. #endif
  105. #ifndef AI_CANONNAME
  106. #define AI_CANONNAME 2
  107. #endif
  108. #ifndef AI_NUMERICHOST
  109. #define AI_NUMERICHOST 4
  110. #endif
  111. #ifndef NI_NOFQDN
  112. #define NI_NOFQDN 1
  113. #endif
  114. #ifndef NI_NUMERICHOST
  115. #define NI_NUMERICHOST 2
  116. #endif
  117. #ifndef NI_NAMERQD
  118. #define NI_NAMERQD 4
  119. #endif
  120. #ifndef NI_NUMERICSERV
  121. #define NI_NUMERICSERV 8
  122. #endif
  123. #ifndef NI_DGRAM
  124. #define NI_DGRAM 16
  125. #endif
  126. #if !HAVE_GETADDRINFO
  127. int ff_getaddrinfo(const char *node, const char *service,
  128. const struct addrinfo *hints, struct addrinfo **res);
  129. void ff_freeaddrinfo(struct addrinfo *res);
  130. int ff_getnameinfo(const struct sockaddr *sa, int salen,
  131. char *host, int hostlen,
  132. char *serv, int servlen, int flags);
  133. const char *ff_gai_strerror(int ecode);
  134. #define getaddrinfo ff_getaddrinfo
  135. #define freeaddrinfo ff_freeaddrinfo
  136. #define getnameinfo ff_getnameinfo
  137. #define gai_strerror ff_gai_strerror
  138. #endif
  139. #ifndef INET6_ADDRSTRLEN
  140. #define INET6_ADDRSTRLEN INET_ADDRSTRLEN
  141. #endif
  142. #ifndef IN_MULTICAST
  143. #define IN_MULTICAST(a) ((((uint32_t)(a)) & 0xf0000000) == 0xe0000000)
  144. #endif
  145. #ifndef IN6_IS_ADDR_MULTICAST
  146. #define IN6_IS_ADDR_MULTICAST(a) (((uint8_t *) (a))[0] == 0xff)
  147. #endif
  148. int ff_is_multicast_address(struct sockaddr *addr);
  149. #endif /* AVFORMAT_NETWORK_H */