mirror of
https://github.com/moonlight-stream/moonlight-ios.git
synced 2026-04-03 06:26:09 +00:00
Handle IPv6-only servers
This commit is contained in:
@@ -175,6 +175,21 @@ static NSString* NV_SERVICE_TYPE = @"_nvstream._tcp";
|
||||
continue;
|
||||
}
|
||||
|
||||
// Since we discovered this host over IPv4 mDNS, we know we're on the same network
|
||||
// as the PC and we can use our current WAN address as a likely candidate
|
||||
// for our PC's external address.
|
||||
struct in_addr wanAddr;
|
||||
int err = LiFindExternalAddressIP4("stun.moonlight-stream.org", 3478, &wanAddr.s_addr);
|
||||
if (err == 0) {
|
||||
char addrStr[INET_ADDRSTRLEN];
|
||||
inet_ntop(AF_INET, &wanAddr, addrStr, sizeof(addrStr));
|
||||
host.externalAddress = [NSString stringWithFormat: @"%s", addrStr];
|
||||
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];
|
||||
Log(LOG_I, @"Local address chosen: %@ -> %@", [service hostName], host.localAddress);
|
||||
break;
|
||||
@@ -194,20 +209,6 @@ static NSString* NV_SERVICE_TYPE = @"_nvstream._tcp";
|
||||
host.ipv6Address = [MDNSManager getBestIpv6Address:addresses];
|
||||
Log(LOG_I, @"IPv6 address chosen: %@ -> %@", [service hostName], host.ipv6Address);
|
||||
|
||||
// Since we discovered this host over mDNS, we know we're on the same network
|
||||
// as the PC and we can use our current WAN address as a likely candidate
|
||||
// for our PC's external address.
|
||||
struct in_addr wanAddr;
|
||||
int err = LiFindExternalAddressIP4("stun.moonlight-stream.org", 3478, &wanAddr.s_addr);
|
||||
if (err == 0) {
|
||||
char addrStr[INET_ADDRSTRLEN];
|
||||
inet_ntop(AF_INET, &wanAddr, addrStr, sizeof(addrStr));
|
||||
host.externalAddress = [NSString stringWithFormat: @"%s", addrStr];
|
||||
}
|
||||
else {
|
||||
Log(LOG_E, @"STUN failed to get WAN address: %d", err);
|
||||
}
|
||||
|
||||
host.activeAddress = host.localAddress;
|
||||
host.name = service.hostName;
|
||||
[self.callback updateHost:host];
|
||||
|
||||
@@ -19,11 +19,16 @@
|
||||
|
||||
- (void) populateHost:(TemporaryHost*)host {
|
||||
host.name = [[self getStringTag:TAG_HOSTNAME] trim];
|
||||
host.localAddress = [[self getStringTag:TAG_LOCAL_IP] trim];
|
||||
host.uuid = [[self getStringTag:TAG_UNIQUE_ID] trim];
|
||||
host.mac = [[self getStringTag:TAG_MAC_ADDRESS] trim];
|
||||
host.currentGame = [[self getStringTag:TAG_CURRENT_GAME] trim];
|
||||
|
||||
// We might get an IPv4 loopback address if we're using GS IPv6 Forwarder
|
||||
NSString *lanAddr = [[self getStringTag:TAG_LOCAL_IP] trim];
|
||||
if (![lanAddr hasPrefix:@"127."]) {
|
||||
host.localAddress = lanAddr;
|
||||
}
|
||||
|
||||
// Modern GFE versions don't actually give us a WAN address anymore
|
||||
// so we leave the one that we populated from mDNS discovery via STUN.
|
||||
NSString *wanAddr = [[self getStringTag:TAG_EXTERNAL_IP] trim];
|
||||
|
||||
Reference in New Issue
Block a user