Net: Add IPv6 Link-Local Address Support
This commit is contained in:
parent
1b2460bd58
commit
eda3d92489
2 changed files with 9 additions and 4 deletions
|
@ -170,7 +170,8 @@ bool static LookupIntern(const char *pszName, std::vector<CNetAddr>& vIP, unsign
|
||||||
if (aiTrav->ai_family == AF_INET6)
|
if (aiTrav->ai_family == AF_INET6)
|
||||||
{
|
{
|
||||||
assert(aiTrav->ai_addrlen >= sizeof(sockaddr_in6));
|
assert(aiTrav->ai_addrlen >= sizeof(sockaddr_in6));
|
||||||
vIP.push_back(CNetAddr(((struct sockaddr_in6*)(aiTrav->ai_addr))->sin6_addr));
|
struct sockaddr_in6* s6 = (struct sockaddr_in6*) aiTrav->ai_addr;
|
||||||
|
vIP.push_back(CNetAddr(s6->sin6_addr, s6->sin6_scope_id));
|
||||||
}
|
}
|
||||||
|
|
||||||
aiTrav = aiTrav->ai_next;
|
aiTrav = aiTrav->ai_next;
|
||||||
|
@ -629,6 +630,7 @@ bool ConnectSocketByName(CService &addr, SOCKET& hSocketRet, const char *pszDest
|
||||||
void CNetAddr::Init()
|
void CNetAddr::Init()
|
||||||
{
|
{
|
||||||
memset(ip, 0, sizeof(ip));
|
memset(ip, 0, sizeof(ip));
|
||||||
|
scopeId = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CNetAddr::SetIP(const CNetAddr& ipIn)
|
void CNetAddr::SetIP(const CNetAddr& ipIn)
|
||||||
|
@ -678,9 +680,10 @@ CNetAddr::CNetAddr(const struct in_addr& ipv4Addr)
|
||||||
SetRaw(NET_IPV4, (const uint8_t*)&ipv4Addr);
|
SetRaw(NET_IPV4, (const uint8_t*)&ipv4Addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
CNetAddr::CNetAddr(const struct in6_addr& ipv6Addr)
|
CNetAddr::CNetAddr(const struct in6_addr& ipv6Addr, const uint32_t scope)
|
||||||
{
|
{
|
||||||
SetRaw(NET_IPV6, (const uint8_t*)&ipv6Addr);
|
SetRaw(NET_IPV6, (const uint8_t*)&ipv6Addr);
|
||||||
|
scopeId = scope;
|
||||||
}
|
}
|
||||||
|
|
||||||
CNetAddr::CNetAddr(const char *pszIp, bool fAllowLookup)
|
CNetAddr::CNetAddr(const char *pszIp, bool fAllowLookup)
|
||||||
|
@ -1099,7 +1102,7 @@ CService::CService(const struct sockaddr_in& addr) : CNetAddr(addr.sin_addr), po
|
||||||
assert(addr.sin_family == AF_INET);
|
assert(addr.sin_family == AF_INET);
|
||||||
}
|
}
|
||||||
|
|
||||||
CService::CService(const struct sockaddr_in6 &addr) : CNetAddr(addr.sin6_addr), port(ntohs(addr.sin6_port))
|
CService::CService(const struct sockaddr_in6 &addr) : CNetAddr(addr.sin6_addr, addr.sin6_scope_id), port(ntohs(addr.sin6_port))
|
||||||
{
|
{
|
||||||
assert(addr.sin6_family == AF_INET6);
|
assert(addr.sin6_family == AF_INET6);
|
||||||
}
|
}
|
||||||
|
@ -1192,6 +1195,7 @@ bool CService::GetSockAddr(struct sockaddr* paddr, socklen_t *addrlen) const
|
||||||
memset(paddrin6, 0, *addrlen);
|
memset(paddrin6, 0, *addrlen);
|
||||||
if (!GetIn6Addr(&paddrin6->sin6_addr))
|
if (!GetIn6Addr(&paddrin6->sin6_addr))
|
||||||
return false;
|
return false;
|
||||||
|
paddrin6->sin6_scope_id = scopeId;
|
||||||
paddrin6->sin6_family = AF_INET6;
|
paddrin6->sin6_family = AF_INET6;
|
||||||
paddrin6->sin6_port = htons(port);
|
paddrin6->sin6_port = htons(port);
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -44,6 +44,7 @@ class CNetAddr
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
unsigned char ip[16]; // in network byte order
|
unsigned char ip[16]; // in network byte order
|
||||||
|
uint32_t scopeId; // for scoped/link-local ipv6 addresses
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CNetAddr();
|
CNetAddr();
|
||||||
|
@ -89,7 +90,7 @@ class CNetAddr
|
||||||
std::vector<unsigned char> GetGroup() const;
|
std::vector<unsigned char> GetGroup() const;
|
||||||
int GetReachabilityFrom(const CNetAddr *paddrPartner = NULL) const;
|
int GetReachabilityFrom(const CNetAddr *paddrPartner = NULL) const;
|
||||||
|
|
||||||
CNetAddr(const struct in6_addr& pipv6Addr);
|
CNetAddr(const struct in6_addr& pipv6Addr, const uint32_t scope = 0);
|
||||||
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);
|
||||||
|
|
Loading…
Reference in a new issue