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.

176 lines
3.8KB

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