mirror of
https://github.com/moonlight-stream/moonlight-ios.git
synced 2026-06-15 21:21:45 +00:00
Don't send a STUN request when a VPN is connected
This commit is contained in:
@@ -163,6 +163,20 @@ static NSString* NV_SERVICE_TYPE = @"_nvstream._tcp";
|
|||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (BOOL)isActiveNetworkVPN {
|
||||||
|
NSDictionary *dict = CFBridgingRelease(CFNetworkCopySystemProxySettings());
|
||||||
|
NSArray *keys = [dict[@"__SCOPED__"] allKeys];
|
||||||
|
for (NSString *key in keys) {
|
||||||
|
if ([key containsString:@"tap"] ||
|
||||||
|
[key containsString:@"tun"] ||
|
||||||
|
[key containsString:@"ppp"] ||
|
||||||
|
[key containsString:@"ipsec"]) {
|
||||||
|
return YES;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return NO;
|
||||||
|
}
|
||||||
|
|
||||||
- (void)netServiceDidResolveAddress:(NSNetService *)service {
|
- (void)netServiceDidResolveAddress:(NSNetService *)service {
|
||||||
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
|
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
|
||||||
NSArray<NSData*>* addresses = [service addresses];
|
NSArray<NSData*>* addresses = [service addresses];
|
||||||
@@ -180,19 +194,23 @@ static NSString* NV_SERVICE_TYPE = @"_nvstream._tcp";
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Since we discovered this host over IPv4 mDNS, we know we're on the same network
|
// Don't send a STUN request if we're connected to a VPN. We'll likely get the VPN
|
||||||
// as the PC and we can use our current WAN address as a likely candidate
|
// gateway's external address rather than the external address of the LAN.
|
||||||
// for our PC's external address.
|
if (![self isActiveNetworkVPN]) {
|
||||||
struct in_addr wanAddr;
|
// Since we discovered this host over IPv4 mDNS, we know we're on the same network
|
||||||
int err = LiFindExternalAddressIP4("stun.moonlight-stream.org", 3478, &wanAddr.s_addr);
|
// as the PC and we can use our current WAN address as a likely candidate
|
||||||
if (err == 0) {
|
// for our PC's external address.
|
||||||
char addrStr[INET_ADDRSTRLEN];
|
struct in_addr wanAddr;
|
||||||
inet_ntop(AF_INET, &wanAddr, addrStr, sizeof(addrStr));
|
int err = LiFindExternalAddressIP4("stun.moonlight-stream.org", 3478, &wanAddr.s_addr);
|
||||||
host.externalAddress = [NSString stringWithFormat: @"%s", addrStr];
|
if (err == 0) {
|
||||||
Log(LOG_I, @"External IPv4 address (STUN): %@ -> %@", [service hostName], host.externalAddress);
|
char addrStr[INET_ADDRSTRLEN];
|
||||||
}
|
inet_ntop(AF_INET, &wanAddr, addrStr, sizeof(addrStr));
|
||||||
else {
|
host.externalAddress = [NSString stringWithFormat: @"%s", addrStr];
|
||||||
Log(LOG_E, @"STUN failed to get WAN address: %d", err);
|
Log(LOG_I, @"External IPv4 address (STUN): %@ -> %@", [service hostName], host.externalAddress);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Log(LOG_E, @"STUN failed to get WAN address: %d", err);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
host.localAddress = [MDNSManager sockAddrToString:addrData];
|
host.localAddress = [MDNSManager sockAddrToString:addrData];
|
||||||
|
|||||||
Reference in New Issue
Block a user