network.h 3.6 KB

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