network.h 4.3 KB

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