network.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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 "config.h"
  23. #if HAVE_WINSOCK2_H
  24. #include <winsock2.h>
  25. #include <ws2tcpip.h>
  26. #define ff_neterrno() (-WSAGetLastError())
  27. #define FF_NETERROR(err) (-WSA##err)
  28. #define WSAEAGAIN WSAEWOULDBLOCK
  29. #else
  30. #include <sys/types.h>
  31. #include <sys/socket.h>
  32. #include <netinet/in.h>
  33. #include <netdb.h>
  34. #define ff_neterrno() AVERROR(errno)
  35. #define FF_NETERROR(err) AVERROR(err)
  36. #endif
  37. #if HAVE_ARPA_INET_H
  38. #include <arpa/inet.h>
  39. #endif
  40. int ff_socket_nonblock(int socket, int enable);
  41. static inline int ff_network_init(void)
  42. {
  43. #if HAVE_WINSOCK2_H
  44. WSADATA wsaData;
  45. if (WSAStartup(MAKEWORD(1,1), &wsaData))
  46. return 0;
  47. #endif
  48. return 1;
  49. }
  50. static inline void ff_network_close(void)
  51. {
  52. #if HAVE_WINSOCK2_H
  53. WSACleanup();
  54. #endif
  55. }
  56. int ff_inet_aton (const char * str, struct in_addr * add);
  57. #if !HAVE_STRUCT_SOCKADDR_STORAGE
  58. struct sockaddr_storage {
  59. #if HAVE_STRUCT_SOCKADDR_SA_LEN
  60. uint8_t ss_len;
  61. uint8_t ss_family;
  62. #else
  63. uint16_t ss_family;
  64. #endif
  65. char ss_pad1[6];
  66. int64_t ss_align;
  67. char ss_pad2[112];
  68. };
  69. #endif
  70. #if !HAVE_STRUCT_ADDRINFO
  71. struct addrinfo {
  72. int ai_flags;
  73. int ai_family;
  74. int ai_socktype;
  75. int ai_protocol;
  76. int ai_addrlen;
  77. struct sockaddr *ai_addr;
  78. char *ai_canonname;
  79. struct addrinfo *ai_next;
  80. };
  81. #endif
  82. /* getaddrinfo constants */
  83. #ifndef EAI_FAIL
  84. #define EAI_FAIL 4
  85. #endif
  86. #ifndef EAI_FAMILY
  87. #define EAI_FAMILY 5
  88. #endif
  89. #ifndef EAI_NONAME
  90. #define EAI_NONAME 8
  91. #endif
  92. #ifndef AI_PASSIVE
  93. #define AI_PASSIVE 1
  94. #endif
  95. #ifndef AI_CANONNAME
  96. #define AI_CANONNAME 2
  97. #endif
  98. #ifndef AI_NUMERICHOST
  99. #define AI_NUMERICHOST 4
  100. #endif
  101. #ifndef NI_NOFQDN
  102. #define NI_NOFQDN 1
  103. #endif
  104. #ifndef NI_NUMERICHOST
  105. #define NI_NUMERICHOST 2
  106. #endif
  107. #ifndef NI_NAMERQD
  108. #define NI_NAMERQD 4
  109. #endif
  110. #ifndef NI_NUMERICSERV
  111. #define NI_NUMERICSERV 8
  112. #endif
  113. #ifndef NI_DGRAM
  114. #define NI_DGRAM 16
  115. #endif
  116. #if !HAVE_GETADDRINFO
  117. int ff_getaddrinfo(const char *node, const char *service,
  118. const struct addrinfo *hints, struct addrinfo **res);
  119. void ff_freeaddrinfo(struct addrinfo *res);
  120. int ff_getnameinfo(const struct sockaddr *sa, int salen,
  121. char *host, int hostlen,
  122. char *serv, int servlen, int flags);
  123. const char *ff_gai_strerror(int ecode);
  124. #define getaddrinfo ff_getaddrinfo
  125. #define freeaddrinfo ff_freeaddrinfo
  126. #define getnameinfo ff_getnameinfo
  127. #define gai_strerror ff_gai_strerror
  128. #endif
  129. #endif /* AVFORMAT_NETWORK_H */