Use link local address only if necessary

This should solve APIPA address being always selected as preferred local
address on Windows which was causing problems connecting to machines on
the same local network.
Now the link local address is used as fallback only if there is non link
local private address available.
This commit is contained in:
Gioacchino Mazzurco 2018-02-19 23:23:15 +01:00
parent afc43d0ff7
commit 0c99975800
No known key found for this signature in database
GPG key ID: A1FBCA3872E87051
4 changed files with 80 additions and 33 deletions

View file

@ -4,6 +4,7 @@
* Universal Networking Header for RetroShare.
*
* Copyright 2007-2008 by Robert Fernie.
* Copyright (C) 2015-2018 Gioacchino Mazzurco <gio@eigenlab.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
@ -147,25 +148,25 @@ bool isLoopbackNet(const struct in_addr *addr)
return (taddr == (127 << 24 | 1));
}
bool isPrivateNet(const struct in_addr *addr)
bool isPrivateNet(const struct in_addr *addr)
{
in_addr_t taddr = ntohl(addr->s_addr);
// 10.0.0.0/8
// 172.16.0.0/12
// 192.168.0.0/16
// 169.254.0.0/16
if ((taddr>>24 == 10) ||
(taddr>>20 == (172<<4 | 16>>4)) ||
(taddr>>16 == (192<<8 | 168)) ||
(taddr>>16 == (169<<8 | 254)))
{
if ( (taddr>>24 == 10) || // 10.0.0.0/8
(taddr>>20 == (172<<4 | 16>>4)) || // 172.16.0.0/12
(taddr>>16 == (192<<8 | 168)) || // 192.168.0.0/16
(taddr>>16 == (169<<8 | 254)) ) // 169.254.0.0/16
return true;
}
else
{
return false;
}
return false;
}
bool isLinkLocalNet(const struct in_addr *addr)
{
in_addr_t taddr = ntohl(addr->s_addr);
if ( taddr>>16 == (169<<8 | 254) ) return true; // 169.254.0.0/16
return false;
}
bool isExternalNet(const struct in_addr *addr)