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.

148 lines
3.0KB

  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() errno
  35. #define FF_NETERROR(err) 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. #if !HAVE_INET_ATON
  57. /* in os_support.c */
  58. int inet_aton (const char * str, struct in_addr * add);
  59. #endif
  60. #if !HAVE_STRUCT_SOCKADDR_STORAGE
  61. struct sockaddr_storage {
  62. struct sockaddr_in x;
  63. };
  64. #endif
  65. #if !HAVE_STRUCT_ADDRINFO
  66. struct addrinfo {
  67. int ai_flags;
  68. int ai_family;
  69. int ai_socktype;
  70. int ai_protocol;
  71. int ai_addrlen;
  72. struct sockaddr *ai_addr;
  73. char *ai_canonname;
  74. struct addrinfo *ai_next;
  75. };
  76. #endif
  77. /* getaddrinfo constants */
  78. #ifndef EAI_FAIL
  79. #define EAI_FAIL 4
  80. #endif
  81. #ifndef EAI_FAMILY
  82. #define EAI_FAMILY 5
  83. #endif
  84. #ifndef EAI_NONAME
  85. #define EAI_NONAME 8
  86. #endif
  87. #ifndef AI_PASSIVE
  88. #define AI_PASSIVE 1
  89. #endif
  90. #ifndef AI_CANONNAME
  91. #define AI_CANONNAME 2
  92. #endif
  93. #ifndef AI_NUMERICHOST
  94. #define AI_NUMERICHOST 4
  95. #endif
  96. #ifndef NI_NOFQDN
  97. #define NI_NOFQDN 1
  98. #endif
  99. #ifndef NI_NUMERICHOST
  100. #define NI_NUMERICHOST 2
  101. #endif
  102. #ifndef NI_NAMERQD
  103. #define NI_NAMERQD 4
  104. #endif
  105. #ifndef NI_NUMERICSERV
  106. #define NI_NUMERICSERV 8
  107. #endif
  108. #ifndef NI_DGRAM
  109. #define NI_DGRAM 16
  110. #endif
  111. #if !HAVE_GETADDRINFO
  112. int ff_getaddrinfo(const char *node, const char *service,
  113. const struct addrinfo *hints, struct addrinfo **res);
  114. void ff_freeaddrinfo(struct addrinfo *res);
  115. int ff_getnameinfo(const struct sockaddr *sa, int salen,
  116. char *host, int hostlen,
  117. char *serv, int servlen, int flags);
  118. #define getaddrinfo ff_getaddrinfo
  119. #define freeaddrinfo ff_freeaddrinfo
  120. #define getnameinfo ff_getnameinfo
  121. #endif
  122. #endif /* AVFORMAT_NETWORK_H */