X-Git-Url: https://git.novaco.in/?p=novacoin.git;a=blobdiff_plain;f=src%2Fnetbase.h;h=95f93e97d17b249c4226ce9d6b2983f1623f882d;hp=e65e138ef5e3a3c167f511a855ab3dc3cfa93bd6;hb=a0bfbd64a8dc93eb87a452843f76dbb9dec9f30b;hpb=882164196e5b1971313493f95a6d027f05e2ec92 diff --git a/src/netbase.h b/src/netbase.h index e65e138..95f93e9 100644 --- a/src/netbase.h +++ b/src/netbase.h @@ -1,36 +1,37 @@ // Copyright (c) 2009-2012 The Bitcoin developers // Distributed under the MIT/X11 software license, see the accompanying -// file license.txt or http://www.opensource.org/licenses/mit-license.php. +// file COPYING or http://www.opensource.org/licenses/mit-license.php. #ifndef BITCOIN_NETBASE_H #define BITCOIN_NETBASE_H #include #include -#ifdef WIN32 -#define _WIN32_WINNT 0x0501 -#include -#include -#include -#else -#include -#include -#include -#include -#include -#include -#endif -#ifdef BSD -#include -#endif - #include "serialize.h" #include "compat.h" extern int nConnectTimeout; +#ifdef WIN32 +// In MSVC, this is defined as a macro, undefine it to prevent a compile and link error +#undef SetPort +#endif + +enum Network +{ + NET_UNROUTABLE, + NET_IPV4, + NET_IPV6, + NET_TOR, + NET_I2P, + + NET_MAX +}; -// IP address (IPv6, or IPv4 using mapped IPv6 range (::FFFF:0:0/96)) +extern int nConnectTimeout; +extern bool fNameLookup; + +/** IP address (IPv6, or IPv4 using mapped IPv6 range (::FFFF:0:0/96)) */ class CNetAddr { protected: @@ -43,28 +44,33 @@ class CNetAddr explicit CNetAddr(const std::string &strIp, bool fAllowLookup = false); void Init(); void SetIP(const CNetAddr& ip); + bool SetSpecial(const std::string &strName); // for Tor and I2P addresses bool IsIPv4() const; // IPv4 mapped address (::FFFF:0:0/96, 0.0.0.0/0) + bool IsIPv6() const; // IPv6 address (not mapped IPv4, not Tor/I2P) bool IsRFC1918() const; // IPv4 private networks (10.0.0.0/8, 192.168.0.0/16, 172.16.0.0/12) bool IsRFC3849() const; // IPv6 documentation address (2001:0DB8::/32) bool IsRFC3927() const; // IPv4 autoconfig (169.254.0.0/16) - bool IsRFC3964() const; // IPv6 6to4 tunneling (2002::/16) + bool IsRFC3964() const; // IPv6 6to4 tunnelling (2002::/16) bool IsRFC4193() const; // IPv6 unique local (FC00::/15) - bool IsRFC4380() const; // IPv6 Teredo tunneling (2001::/32) + bool IsRFC4380() const; // IPv6 Teredo tunnelling (2001::/32) bool IsRFC4843() const; // IPv6 ORCHID (2001:10::/28) bool IsRFC4862() const; // IPv6 autoconfig (FE80::/64) bool IsRFC6052() const; // IPv6 well-known prefix (64:FF9B::/96) bool IsRFC6145() const; // IPv6 IPv4-translated address (::FFFF:0:0:0/96) + bool IsTor() const; + bool IsI2P() const; bool IsLocal() const; bool IsRoutable() const; bool IsValid() const; bool IsMulticast() const; + enum Network GetNetwork() const; std::string ToString() const; std::string ToStringIP() const; - int GetByte(int n) const; - int64 GetHash() const; + uint8_t GetByte(int n) const; + uint64_t GetHash() const; bool GetInAddr(struct in_addr* pipv4Addr) const; std::vector GetGroup() const; - void print() const; + int GetReachabilityFrom(const CNetAddr *paddrPartner = NULL) const; #ifdef USE_IPV6 CNetAddr(const struct in6_addr& pipv6Addr); @@ -81,6 +87,7 @@ class CNetAddr ) }; +/** A combination of a network address (CNetAddr) and a (TCP) port */ class CService : public CNetAddr { protected: @@ -88,17 +95,18 @@ class CService : public CNetAddr public: CService(); - CService(const CNetAddr& ip, unsigned short port); - CService(const struct in_addr& ipv4Addr, unsigned short port); + CService(const CNetAddr& ip, uint16_t port); + CService(const struct in_addr& ipv4Addr, uint16_t port); CService(const struct sockaddr_in& addr); - explicit CService(const char *pszIpPort, int portDefault, bool fAllowLookup = false); + explicit CService(const char *pszIpPort, uint16_t portDefault, bool fAllowLookup = false); explicit CService(const char *pszIpPort, bool fAllowLookup = false); - explicit CService(const std::string& strIpPort, int portDefault, bool fAllowLookup = false); + explicit CService(const std::string& strIpPort, uint16_t portDefault, bool fAllowLookup = false); explicit CService(const std::string& strIpPort, bool fAllowLookup = false); void Init(); - void SetPort(unsigned short portIn); + void SetPort(uint16_t portIn); unsigned short GetPort() const; - bool GetSockAddr(struct sockaddr_in* paddr) const; + bool GetSockAddr(struct sockaddr* paddr, socklen_t *addrlen) const; + bool SetSockAddr(const struct sockaddr* paddr); friend bool operator==(const CService& a, const CService& b); friend bool operator!=(const CService& a, const CService& b); friend bool operator<(const CService& a, const CService& b); @@ -106,11 +114,9 @@ class CService : public CNetAddr std::string ToString() const; std::string ToStringPort() const; std::string ToStringIPPort() const; - void print() const; #ifdef USE_IPV6 - CService(const struct in6_addr& ipv6Addr, unsigned short port); - bool GetSockAddr6(struct sockaddr_in6* paddr) const; + CService(const struct in6_addr& ipv6Addr, uint16_t port); CService(const struct sockaddr_in6& addr); #endif @@ -125,15 +131,22 @@ class CService : public CNetAddr ) }; -bool LookupHost(const char *pszName, std::vector& vIP, int nMaxSolutions = 0, bool fAllowLookup = true); -bool LookupHostNumeric(const char *pszName, std::vector& vIP, int nMaxSolutions = 0); -bool Lookup(const char *pszName, CService& addr, int portDefault = 0, bool fAllowLookup = true); -bool Lookup(const char *pszName, std::vector& vAddr, int portDefault = 0, bool fAllowLookup = true, int nMaxSolutions = 0); -bool LookupNumeric(const char *pszName, CService& addr, int portDefault = 0); +typedef std::pair proxyType; + +enum Network ParseNetwork(std::string net); +void SplitHostPort(std::string in, uint16_t &portOut, std::string &hostOut); +bool SetProxy(enum Network net, CService addrProxy, int nSocksVersion = 5); +bool GetProxy(enum Network net, proxyType &proxyInfoOut); +bool IsProxy(const CNetAddr &addr); +bool SetNameProxy(CService addrProxy, int nSocksVersion = 5); +bool HaveNameProxy(); +bool LookupHost(const char *pszName, std::vector& vIP, unsigned int nMaxSolutions = 0, bool fAllowLookup = true); +bool Lookup(const char *pszName, CService& addr, uint16_t portDefault = 0, bool fAllowLookup = true); +bool Lookup(const char *pszName, std::vector& vAddr, uint16_t portDefault = 0, bool fAllowLookup = true, unsigned int nMaxSolutions = 0); +bool LookupNumeric(const char *pszName, CService& addr, uint16_t portDefault = 0); bool ConnectSocket(const CService &addr, SOCKET& hSocketRet, int nTimeout = nConnectTimeout); +bool ConnectSocketByName(CService &addr, SOCKET& hSocketRet, const char *pszDest, uint16_t portDefault = 0, int nTimeout = nConnectTimeout); +/** Close socket and set hSocket to INVALID_SOCKET */ +bool CloseSocket(SOCKET& hSocket); -// Settings -extern int fUseProxy; -extern CService addrProxy; - -#endif +#endif \ No newline at end of file