Changeset View
Changeset View
Standalone View
Standalone View
src/seeder/netbase.h
// Copyright (c) 2009-2012 The Bitcoin developers | // Copyright (c) 2009-2012 The Bitcoin developers | ||||
// Distributed under the MIT/X11 software license, see the accompanying | // Distributed under the MIT/X11 software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#ifndef BITCOIN_NETBASE_H | #ifndef BITCOIN_SEEDER_NETBASE_H | ||||
#define BITCOIN_NETBASE_H | #define BITCOIN_SEEDER_NETBASE_H | ||||
#include <string> | |||||
#include <vector> | |||||
#include "compat.h" | #include "compat.h" | ||||
#include "serialize.h" | #include "serialize.h" | ||||
#include <string> | |||||
#include <vector> | |||||
extern int nConnectTimeout; | extern int nConnectTimeout; | ||||
#ifdef WIN32 | #ifdef WIN32 | ||||
// In MSVC, this is defined as a macro, undefine it to prevent a compile and | // In MSVC, this is defined as a macro, undefine it to prevent a compile and | ||||
// link error | // link error | ||||
#undef SetPort | #undef SetPort | ||||
#endif | #endif | ||||
enum Network { | enum Network { | ||||
NET_UNROUTABLE, | NET_UNROUTABLE, | ||||
NET_IPV4, | NET_IPV4, | ||||
NET_IPV6, | NET_IPV6, | ||||
NET_TOR, | NET_TOR, | ||||
NET_I2P, | NET_I2P, | ||||
NET_MAX, | NET_MAX, | ||||
}; | }; | ||||
extern int nConnectTimeout; | extern int nConnectTimeout; | ||||
extern bool fNameLookup; | extern bool fNameLookup; | ||||
/** IP address (IPv6, or IPv4 using mapped IPv6 range (::FFFF:0:0/96)) */ | /** IP address (IPv6, or IPv4 using mapped IPv6 range (::FFFF:0:0/96)) */ | ||||
class CNetAddr { | class CNetAddr { | ||||
protected: | protected: | ||||
unsigned char ip[16]; // in network byte order | uint8_t ip[16]; // in network byte order | ||||
public: | public: | ||||
CNetAddr(); | CNetAddr(); | ||||
CNetAddr(const struct in_addr &ipv4Addr); | CNetAddr(const struct in_addr &ipv4Addr); | ||||
explicit CNetAddr(const char *pszIp, bool fAllowLookup = false); | explicit CNetAddr(const char *pszIp, bool fAllowLookup = false); | ||||
explicit CNetAddr(const std::string &strIp, bool fAllowLookup = false); | explicit CNetAddr(const std::string &strIp, bool fAllowLookup = false); | ||||
void Init(); | void Init(); | ||||
void SetIP(const CNetAddr &ip); | void SetIP(const CNetAddr &ip); | ||||
Show All 19 Lines | public: | ||||
bool IsValid() const; | bool IsValid() const; | ||||
bool IsMulticast() const; | bool IsMulticast() const; | ||||
enum Network GetNetwork() const; | enum Network GetNetwork() const; | ||||
std::string ToString() const; | std::string ToString() const; | ||||
std::string ToStringIP() const; | std::string ToStringIP() const; | ||||
unsigned int GetByte(int n) const; | unsigned int GetByte(int n) const; | ||||
uint64 GetHash() const; | uint64 GetHash() const; | ||||
bool GetInAddr(struct in_addr *pipv4Addr) const; | bool GetInAddr(struct in_addr *pipv4Addr) const; | ||||
std::vector<unsigned char> GetGroup() const; | std::vector<uint8_t> GetGroup() const; | ||||
int GetReachabilityFrom(const CNetAddr *paddrPartner = NULL) const; | int GetReachabilityFrom(const CNetAddr *paddrPartner = nullptr) const; | ||||
void print() const; | void print() const; | ||||
CNetAddr(const struct in6_addr &pipv6Addr); | CNetAddr(const struct in6_addr &pipv6Addr); | ||||
bool GetIn6Addr(struct in6_addr *pipv6Addr) const; | bool GetIn6Addr(struct in6_addr *pipv6Addr) const; | ||||
friend bool operator==(const CNetAddr &a, const CNetAddr &b); | friend bool operator==(const CNetAddr &a, const CNetAddr &b); | ||||
friend bool operator!=(const CNetAddr &a, const CNetAddr &b); | friend bool operator!=(const CNetAddr &a, const CNetAddr &b); | ||||
friend bool operator<(const CNetAddr &a, const CNetAddr &b); | friend bool operator<(const CNetAddr &a, const CNetAddr &b); | ||||
Show All 20 Lines | public: | ||||
void Init(); | void Init(); | ||||
void SetPort(unsigned short portIn); | void SetPort(unsigned short portIn); | ||||
unsigned short GetPort() const; | unsigned short GetPort() const; | ||||
bool GetSockAddr(struct sockaddr *paddr, socklen_t *addrlen) const; | bool GetSockAddr(struct sockaddr *paddr, socklen_t *addrlen) const; | ||||
bool SetSockAddr(const struct sockaddr *paddr); | 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); | 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); | ||||
std::vector<unsigned char> GetKey() const; | std::vector<uint8_t> GetKey() const; | ||||
std::string ToString() const; | std::string ToString() const; | ||||
std::string ToStringPort() const; | std::string ToStringPort() const; | ||||
std::string ToStringIPPort() const; | std::string ToStringIPPort() const; | ||||
void print() const; | void print() const; | ||||
CService(const struct in6_addr &ipv6Addr, unsigned short port); | CService(const struct in6_addr &ipv6Addr, unsigned short port); | ||||
CService(const struct sockaddr_in6 &addr); | CService(const struct sockaddr_in6 &addr); | ||||
Show All 30 Lines |