network.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. // This file is part of BOINC.
  2. // http://boinc.berkeley.edu
  3. // Copyright (C) 2008 University of California
  4. //
  5. // BOINC is free software; you can redistribute it and/or modify it
  6. // under the terms of the GNU Lesser General Public License
  7. // as published by the Free Software Foundation,
  8. // either version 3 of the License, or (at your option) any later version.
  9. //
  10. // BOINC is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. // See the GNU Lesser General Public License for more details.
  14. //
  15. // You should have received a copy of the GNU Lesser General Public License
  16. // along with BOINC. If not, see <http://www.gnu.org/licenses/>.
  17. #ifndef BOINC_NETWORK_H
  18. #define BOINC_NETWORK_H
  19. #include <string.h>
  20. #ifdef _WIN32
  21. #include "boinc_win.h"
  22. // WxWidgets can't deal with modern network code (winsock2.h)
  23. // so use old code on Win
  24. #define sockaddr_storage sockaddr_in
  25. #else
  26. #include <sys/select.h>
  27. #include <sys/socket.h>
  28. #include <unistd.h>
  29. #endif
  30. struct FDSET_GROUP {
  31. fd_set read_fds;
  32. fd_set write_fds;
  33. fd_set exc_fds;
  34. int max_fd;
  35. void zero() {
  36. FD_ZERO(&read_fds);
  37. FD_ZERO(&write_fds);
  38. FD_ZERO(&exc_fds);
  39. max_fd = -1;
  40. }
  41. };
  42. extern bool is_localhost(sockaddr_storage& s);
  43. extern bool same_ip_addr(sockaddr_storage& s1, sockaddr_storage& s2);
  44. extern int resolve_hostname(const char* hostname, sockaddr_storage& ip_addr);
  45. extern int resolve_hostname_or_ip_addr(const char* hostname, sockaddr_storage& ip_addr);
  46. extern int boinc_socket(int& sock, int protocol=AF_INET);
  47. // create a stream-mode socket of the given family
  48. extern int boinc_socket_asynch(int sock, bool asynch);
  49. // make an existing socket asynchronous or synchronous
  50. extern void boinc_close_socket(int sock);
  51. extern int get_socket_error(int fd);
  52. extern const char* socket_error_str();
  53. extern void reset_dns();
  54. extern int boinc_get_port(bool is_remote, int& port);
  55. #if defined(_WIN32) && !defined(__CYGWIN32__)
  56. typedef int BOINC_SOCKLEN_T;
  57. #else
  58. typedef socklen_t BOINC_SOCKLEN_T;
  59. #endif
  60. #if defined(_WIN32) && defined(USE_WINSOCK)
  61. extern int WinsockInitialize();
  62. extern int WinsockCleanup();
  63. #endif
  64. #endif