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.

netbase.h 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // Copyright (c) 2009-2016 The Starwels developers
  2. // Distributed under the MIT software license, see the accompanying
  3. // file COPYING or http://www.opensource.org/licenses/mit-license.php.
  4. #ifndef STARWELS_NETBASE_H
  5. #define STARWELS_NETBASE_H
  6. #if defined(HAVE_CONFIG_H)
  7. #include "config/starwels-config.h"
  8. #endif
  9. #include "compat.h"
  10. #include "netaddress.h"
  11. #include "serialize.h"
  12. #include <stdint.h>
  13. #include <string>
  14. #include <vector>
  15. extern int nConnectTimeout;
  16. extern bool fNameLookup;
  17. //! -timeout default
  18. static const int DEFAULT_CONNECT_TIMEOUT = 5000;
  19. //! -dns default
  20. static const int DEFAULT_NAME_LOOKUP = true;
  21. class proxyType
  22. {
  23. public:
  24. proxyType(): randomize_credentials(false) {}
  25. proxyType(const CService &_proxy, bool _randomize_credentials=false): proxy(_proxy), randomize_credentials(_randomize_credentials) {}
  26. bool IsValid() const { return proxy.IsValid(); }
  27. CService proxy;
  28. bool randomize_credentials;
  29. };
  30. enum Network ParseNetwork(std::string net);
  31. std::string GetNetworkName(enum Network net);
  32. bool SetProxy(enum Network net, const proxyType &addrProxy);
  33. bool GetProxy(enum Network net, proxyType &proxyInfoOut);
  34. bool IsProxy(const CNetAddr &addr);
  35. bool SetNameProxy(const proxyType &addrProxy);
  36. bool HaveNameProxy();
  37. bool LookupHost(const char *pszName, std::vector<CNetAddr>& vIP, unsigned int nMaxSolutions, bool fAllowLookup);
  38. bool LookupHost(const char *pszName, CNetAddr& addr, bool fAllowLookup);
  39. bool Lookup(const char *pszName, CService& addr, int portDefault, bool fAllowLookup);
  40. bool Lookup(const char *pszName, std::vector<CService>& vAddr, int portDefault, bool fAllowLookup, unsigned int nMaxSolutions);
  41. CService LookupNumeric(const char *pszName, int portDefault = 0);
  42. bool LookupSubNet(const char *pszName, CSubNet& subnet);
  43. bool ConnectSocket(const CService &addr, SOCKET& hSocketRet, int nTimeout, bool *outProxyConnectionFailed = 0);
  44. bool ConnectSocketByName(CService &addr, SOCKET& hSocketRet, const char *pszDest, int portDefault, int nTimeout, bool *outProxyConnectionFailed = 0);
  45. /** Return readable error string for a network error code */
  46. std::string NetworkErrorString(int err);
  47. /** Close socket and set hSocket to INVALID_SOCKET */
  48. bool CloseSocket(SOCKET& hSocket);
  49. /** Disable or enable blocking-mode for a socket */
  50. bool SetSocketNonBlocking(const SOCKET& hSocket, bool fNonBlocking);
  51. /** Set the TCP_NODELAY flag on a socket */
  52. bool SetSocketNoDelay(const SOCKET& hSocket);
  53. /**
  54. * Convert milliseconds to a struct timeval for e.g. select.
  55. */
  56. struct timeval MillisToTimeval(int64_t nTimeout);
  57. void InterruptSocks5(bool interrupt);
  58. #endif // STARWELS_NETBASE_H