network.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. #endif /* AVFORMAT_NETWORK_H */