-
-
Notifications
You must be signed in to change notification settings - Fork 154
Open
Labels
Description
macOS ใง Network::IsConnected() ใไฝฟใใจใใซใใจใฉใผใซใชใใพใใ
Undefined symbol: _SCNetworkReachabilityCreateWithName
Undefined symbol: _SCNetworkReachabilityGetFlags
SCNetworkReachability API ใๅปๆญขใใใใใใงใใ
https://developer.apple.com/documentation/systemconfiguration/scnetworkreachability-g7d
Linux ็ใฎๅฎ่ฃ
ใ่ฉฆใใฆใฟใพใใใใ awdl0, llw0, utun0, utun1, ... ใฎใใใชใคใณใฟใผใใงใผในใๅผใฃๆใใใใคใณใฟใผใใใใซๆฅ็ถใใฆใใชใ็ถๆ
ใงใ true ใ่ฟใใพใใใ
๏ผใใใใ Network::IsConnected() ใใคใณใฟใผใใใใซๆฅ็ถใใใฆใใใใใ่ฟใใฆใใใฎใงใใใใ๏ผใWindows ็ใ Linux ็ใฎๅฎ่ฃ
ใฏๅใซใใใใใฏใผใฏใซๆฅ็ถใใใฆใใใใใ่ฟใใฆใใใใใซ่ฆใใพใใ๏ผ
Linux ็ใฎๅฎ่ฃ (ifaddrs) ใ่ฉฆใใณใผใ
# include <Siv3D.hpp>
# include <ifaddrs.h>
# include <net/if.h>
# include <arpa/inet.h>
namespace MyNetwork
{
bool IsConnected()
{
struct ifaddrs* ifaddr;
if (getifaddrs(&ifaddr) == -1)
{
return false;
}
bool result = false;
for (struct ifaddrs* ifa = ifaddr; ifa != nullptr; ifa = ifa->ifa_next)
{
if (ifa->ifa_addr == nullptr)
{
continue;
}
const int family = ifa->ifa_addr->sa_family;
if (((family == AF_INET )|| (family == AF_INET6))
&& (not (ifa->ifa_flags & IFF_LOOPBACK)))
{
result = true;
// break;
// ใใใใฐ
{
String s = Unicode::Widen(ifa->ifa_name);
if (family == AF_INET)
{
s += U": ";
s += Unicode::Widen(inet_ntoa(reinterpret_cast<struct sockaddr_in*>(ifa->ifa_addr)->sin_addr));
}
else if (family == AF_INET6)
{
s += U": ";
std::string buf(INET6_ADDRSTRLEN, U'\0');
inet_ntop(AF_INET6, &reinterpret_cast<struct sockaddr_in6*>(ifa->ifa_addr)->sin6_addr, buf.data(), INET6_ADDRSTRLEN);
s += Unicode::Widen(buf);
}
Print << s;
}
}
}
freeifaddrs(ifaddr);
return result;
}
}
void Main()
{
Print << Network::EnumerateIPv4Addresses();
Print << MyNetwork::IsConnected();
while (System::Update())
{
}
}Reactions are currently unavailable