PageRenderTime 23ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/libretroshare/src/pqi/pqinetwork.h

https://gitlab.com/cave/RetroShare
C Header | 131 lines | 58 code | 38 blank | 35 comment | 0 complexity | b59824bc097544b878866d101abbfae3 MD5 | raw file
Possible License(s): 0BSD, GPL-2.0
  1. /*
  2. * "$Id: pqinetwork.h,v 1.15 2007-04-15 18:45:18 rmf24 Exp $"
  3. *
  4. * 3P/PQI network interface for RetroShare.
  5. *
  6. * Copyright 2004-2006 by Robert Fernie.
  7. *
  8. * This library is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Library General Public
  10. * License Version 2 as published by the Free Software Foundation.
  11. *
  12. * This library is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Library General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Library General Public
  18. * License along with this library; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
  20. * USA.
  21. *
  22. * Please report all bugs and problems to "retroshare@lunamutt.com".
  23. *
  24. */
  25. #ifndef MRK_PQI_NETWORKING_HEADER
  26. #define MRK_PQI_NETWORKING_HEADER
  27. /********************************** WINDOWS/UNIX SPECIFIC PART ******************/
  28. #ifndef WINDOWS_SYS
  29. #include <sys/types.h>
  30. #include <sys/socket.h>
  31. #include <netinet/in.h>
  32. #include <arpa/inet.h>
  33. #include <sys/poll.h>
  34. //socket blocking/options.
  35. #include <fcntl.h>
  36. #include <inttypes.h>
  37. #else
  38. #include "util/rsnet.h" /* more generic networking header */
  39. // Some Network functions that are missing from windows.
  40. in_addr_t inet_netof(struct in_addr addr);
  41. in_addr_t inet_network(const char *inet_name);
  42. int inet_aton(const char *name, struct in_addr *addr);
  43. extern int errno; /* Define extern errno, to duplicate unix behaviour */
  44. /* define the Unix Error Codes that we use...
  45. * NB. we should make the same, but not necessary
  46. */
  47. #define EAGAIN 11
  48. #define EUSERS 87
  49. #define EHOSTDOWN 112
  50. #ifndef __MINGW64_VERSION_MAJOR
  51. #define EWOULDBLOCK EAGAIN
  52. #define ENOTSOCK 88
  53. #define EOPNOTSUPP 95
  54. #define EADDRINUSE 98
  55. #define EADDRNOTAVAIL 99
  56. #define ENETDOWN 100
  57. #define ENETUNREACH 101
  58. #define ECONNRESET 104
  59. #define ETIMEDOUT 10060 // value from pthread.h
  60. #define ECONNREFUSED 111
  61. #define EHOSTUNREACH 113
  62. #define EALREADY 114
  63. #define EINPROGRESS 115
  64. #endif
  65. #endif
  66. /********************************** WINDOWS/UNIX SPECIFIC PART ******************/
  67. #include <iostream>
  68. #include <string>
  69. #include <list>
  70. // Same def - different functions...
  71. void showSocketError(std::string &out);
  72. std::string socket_errorType(int err);
  73. int sockaddr_cmp(struct sockaddr_in &addr1, struct sockaddr_in &addr2 );
  74. int inaddr_cmp(struct sockaddr_in addr1, struct sockaddr_in addr2 );
  75. int inaddr_cmp(struct sockaddr_in addr1, unsigned long);
  76. bool getPreferredInterface(struct sockaddr_storage &existAddr, struct sockaddr_storage &prefAddr); // returns best addr.
  77. bool getLocalInterfaces(struct sockaddr_storage &existAddr, std::list<struct sockaddr_storage> &addrs); // returns all possible addrs.
  78. // checks (addr1 & 255.255.255.0) == (addr2 & 255.255.255.0)
  79. bool isSameSubnet(struct in_addr *addr1, struct in_addr *addr2);
  80. bool sameNet(const struct in_addr *addr, const struct in_addr *addr2);
  81. in_addr_t pqi_inet_netof(struct in_addr addr); // our implementation.
  82. bool LookupDNSAddr(std::string name, struct sockaddr_in &addr);
  83. /* universal socket interface */
  84. int unix_close(int sockfd);
  85. int unix_socket(int domain, int type, int protocol);
  86. int unix_fcntl_nonblock(int sockfd);
  87. int unix_connect(int sockfd, const struct sockaddr *serv_addr, socklen_t addrlen);
  88. int unix_getsockopt_error(int sockfd, int *err);
  89. #ifdef WINDOWS_SYS // WINDOWS
  90. /******************* WINDOWS SPECIFIC PART ******************/
  91. int WinToUnixError(int error);
  92. #endif
  93. #endif