Compare commits

...
50 Commits
Author SHA1 Message Date
Cameron Gutman 620aa4b6d1 Version 4.1 2019-07-30 22:20:01 -07:00
Cameron Gutman b93ef55b65 Fix displaying broken ports when running IPv6-only 2019-07-30 22:12:45 -07:00
Cameron Gutman fdb033f550 Reduce wait time for UDP to offset retransmission delays 2019-07-30 21:48:48 -07:00
Cameron Gutman efdcaed4c1 Don't proceed after WSAEADDRINUSE for the loopback relay to avoid false positives 2019-07-30 21:47:29 -07:00
Cameron Gutman 5a2edb9a36 Add note about log for Discord 2019-07-30 21:45:26 -07:00
Cameron Gutman 798be5fd0a Implement heuristics for falling through to v4 detection even with working v6 2019-07-30 21:31:28 -07:00
Cameron Gutman b0941fee90 Update README.md 2019-07-29 22:54:53 -07:00
Cameron Gutman ebc7703bf2 Update error message text 2019-07-29 22:02:27 -07:00
Cameron Gutman bbf16383f5 Fix uninitialized sin_family field returned from CheckWANAccess() 2019-07-29 21:59:18 -07:00
Cameron Gutman dee2daac5a Fix invalid free on getaddrinfo() failure 2019-07-29 21:58:16 -07:00
Cameron Gutman 51e953c092 Test using the relay even if we believe it may be a double-NAT configuration 2019-07-29 21:25:40 -07:00
Cameron Gutman acb3f5a059 Add support for IPv6-only environments 2019-07-29 21:20:30 -07:00
Cameron Gutman 0bd212e6f1 Fix addrinfo leak 2019-07-29 21:06:18 -07:00
Cameron Gutman d076f881eb Print dialog text to the console 2019-07-29 21:04:17 -07:00
Cameron Gutman 46c2236342 Add support for getting local IPv6 address 2019-07-29 21:01:55 -07:00
Cameron Gutman 8158c85a23 Add support for IPv6 testing 2019-07-28 18:33:33 -07:00
Cameron Gutman 6f3898e4b4 Untabify source 2019-07-28 13:25:51 -07:00
Cameron Gutman b1a1352bbf Retransmit UDP test packets a few times to be safe 2019-07-28 13:16:22 -07:00
Cameron Gutman 069b0c7656 Add more periodic test output to avoid looking like the test is hung 2019-07-28 13:11:04 -07:00
Cameron Gutman 42df15c567 Switch stderr and stdout to prevent miniupnp warnings from appearing on the console 2019-07-28 13:09:48 -07:00
Cameron Gutman 96a88b55db Prepare to swap stdout and stderr for console output 2019-07-28 12:46:45 -07:00
Cameron Gutman 2d31cd0420 Rename Internet Streaming Helper to Internet Hosting Tool 2019-07-28 12:33:05 -07:00
Cameron Gutman ebb8c9fb68 Version 4.0 2019-07-13 15:21:23 -07:00
Cameron Gutman b31d257566 Integrate GSv6Fwd into MISH 2019-07-13 15:04:20 -07:00
Cameron Gutman 51dc3142ca Retarget to VS2019 2019-07-13 11:29:55 -07:00
Cameron Gutman c8ab32812f Version 3.0 2019-04-05 01:42:05 -07:00
Cameron Gutman 21802eac19 Improve messages to be less confusing 2019-04-05 01:41:55 -07:00
Cameron Gutman dab033ee3b Avoid testing UDP 48002 and UDP 48010 since they are currently unused 2019-04-05 00:39:51 -07:00
Cameron Gutman 204dde8a73 Avoid attempting to delete UPnP rules if the description doesn't match 2019-04-05 00:39:27 -07:00
Cameron Gutman 3d9e14fb56 Use a loopback relay if NAT reflection is unavailable 2019-04-05 00:38:47 -07:00
Cameron Gutman 771e09973f Print both old and new MISS logs 2019-03-28 19:46:34 -07:00
Cameron Gutman 1bc6cc5634 Fix log rotation 2019-03-28 19:42:09 -07:00
Cameron Gutman 0941cc5bc1 Set additional version attributes 2019-03-28 19:41:14 -07:00
Cameron Gutman a7e41d15f5 Add UTC time prefix to logs 2019-03-28 19:37:46 -07:00
Cameron Gutman 6916cfd0de Version 2.3 2019-03-09 16:03:46 -08:00
Cameron Gutman bae92c6c95 Allow the service access to its log folder 2019-03-09 16:00:10 -08:00
Cameron Gutman c8de19a3b6 Reduce service permissions 2019-03-09 15:02:14 -08:00
Cameron Gutman 1da8f371aa Update miniupnpc build to 4912dc37e30927eefd5d7bf0778d77172ef94803 2019-03-09 15:01:21 -08:00
Cameron Gutman cb55a02599 Fix parsing XOR-MAPPED-ADDRESS if the optional comprehension bit is set 2019-01-22 17:42:09 -08:00
Cameron Gutman dc820bdbf6 Version 2.2 2019-01-04 23:08:44 -08:00
Cameron Gutman 106960cbb5 Check for null help URL 2019-01-04 23:06:37 -08:00
Cameron Gutman 3c92a79fe2 Fix parsing bug handling empty SSDP headers 2019-01-04 23:02:07 -08:00
Cameron Gutman 2c2f275c3d Add help button to error dialogs 2019-01-04 22:49:02 -08:00
Cameron Gutman 156940cc5b Retry STUN over TCP on UDP failure 2019-01-04 20:46:48 -08:00
Cameron Gutman a835cf43a5 Require STUN public IP address to proceed with testing 2019-01-04 20:39:20 -08:00
Cameron Gutman 18b704b85a Use moonlight-stream.org instead of google.com to avoid issues in China 2019-01-04 19:22:46 -08:00
Cameron Gutman cd4adae22b Use stun.moonlight-stream.org for STUN 2019-01-04 19:17:31 -08:00
Cameron Gutman ef59e2858b Fix incorrect error message on STUN receive timeout 2018-11-30 00:33:48 -08:00
Cameron Gutman 218c0d7385 Increase SSDP UDP socket recv buffer size 2018-11-30 00:32:57 -08:00
Cameron Gutman e7f03cfa93 Add missing check for PCP version 2018-11-29 23:57:14 -08:00
29 changed files with 742 additions and 259 deletions
+3
View File
@@ -0,0 +1,3 @@
[submodule "GS-IPv6-Forwarder"]
path = GS-IPv6-Forwarder
url = https://github.com/moonlight-stream/GS-IPv6-Forwarder.git
+1
Submodule GS-IPv6-Forwarder added at 7b395a9f2f
+2 -1
View File
@@ -1,4 +1,4 @@
# Moonlight Internet Streaming Helper
# Moonlight Internet Hosting Tool
* Enable Moonlight streaming from your PC over the Internet with no configuration required
* Troubleshoot streaming issues with the included testing tool
@@ -8,5 +8,6 @@
# Technical Features
- Supports all major port forwarding protocols (UPnP, NAT-PMP, and PCP) for the best possible router compatibility
- Supports streaming on IPv4-only, IPv6-only, and dual-stack Internet connections
- Supports successful forwarding in double-NAT environments by configuring port mappings on all NATs found on the way to the Internet
- Supports forwarding on Carrier-Grade NATs (CGNs) by directly using PCP when the ISP doesn't implement UPnP-PCP interoperability
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+20
View File
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"
xmlns:bal="http://schemas.microsoft.com/wix/BalExtension">
<Bundle Name="Moonlight Internet Hosting Tool" Manufacturer="Moonlight Game Streaming Project" Version="!(bind.packageVersion.mish)" UpgradeCode="a2ce5056-1114-44b9-b79b-952ef46d3d50">
<BootstrapperApplicationRef Id="WixStandardBootstrapperApplication.RtfLicense">
<bal:WixStandardBootstrapperApplication
LicenseFile="license.rtf"
ShowVersion="yes"
SuppressOptionsUI="yes"
/>
</BootstrapperApplicationRef>
<WixVariable Id="WixUILicenseRtf" Value="" />
<Chain>
<MsiPackage Id="mish" SourceFile="$(var.mish.TargetPath)" />
<MsiPackage SourceFile="$(var.GSv6FwdSetup.TargetPath)" />
</Chain>
</Bundle>
</Wix>
+61
View File
@@ -0,0 +1,61 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" InitialTargets="EnsureWixToolsetInstalled" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
<ProductVersion>3.10</ProductVersion>
<ProjectGuid>a2ce5056-1114-44b9-b79b-952ef46d3d50</ProjectGuid>
<SchemaVersion>2.0</SchemaVersion>
<OutputName>InternetHostingToolSetup</OutputName>
<OutputType>Bundle</OutputType>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
<OutputPath>bin\$(Configuration)\</OutputPath>
<IntermediateOutputPath>obj\$(Configuration)\</IntermediateOutputPath>
<DefineConstants>Debug</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
<OutputPath>bin\$(Configuration)\</OutputPath>
<IntermediateOutputPath>obj\$(Configuration)\</IntermediateOutputPath>
</PropertyGroup>
<ItemGroup>
<Compile Include="Bundle.wxs" />
</ItemGroup>
<ItemGroup>
<WixExtension Include="WixBalExtension">
<HintPath>$(WixExtDir)\WixBalExtension.dll</HintPath>
<Name>WixBalExtension</Name>
</WixExtension>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\GS-IPv6-Forwarder\GSv6FwdSetup\GSv6FwdSetup.wixproj">
<Name>GSv6FwdSetup</Name>
<Project>{f8171b99-f5f9-4abf-9fe5-6753539611af}</Project>
<Private>True</Private>
<DoNotHarvest>True</DoNotHarvest>
<RefProjectOutputGroups>Binaries;Content;Satellites</RefProjectOutputGroups>
<RefTargetDir>INSTALLFOLDER</RefTargetDir>
</ProjectReference>
<ProjectReference Include="..\mish\mish.wixproj">
<Name>mish</Name>
<Project>{f0dee5f3-4b62-47a3-b00b-61c614c924fd}</Project>
<Private>True</Private>
<DoNotHarvest>True</DoNotHarvest>
<RefProjectOutputGroups>Binaries;Content;Satellites</RefProjectOutputGroups>
<RefTargetDir>INSTALLFOLDER</RefTargetDir>
</ProjectReference>
</ItemGroup>
<Import Project="$(WixTargetsPath)" Condition=" '$(WixTargetsPath)' != '' " />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\WiX\v3.x\Wix.targets" Condition=" '$(WixTargetsPath)' == '' AND Exists('$(MSBuildExtensionsPath32)\Microsoft\WiX\v3.x\Wix.targets') " />
<Target Name="EnsureWixToolsetInstalled" Condition=" '$(WixTargetsImported)' != 'true' ">
<Error Text="The WiX Toolset v3.11 (or newer) build tools must be installed to build this project. To download the WiX Toolset, see http://wixtoolset.org/releases/" />
</Target>
<!--
To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Wix.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
+28 -2
View File
@@ -1,7 +1,7 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.28010.2046
# Visual Studio Version 16
VisualStudioVersion = 16.0.29102.190
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "miss", "miss\miss.vcxproj", "{B71C4E7F-0D92-4E19-BBD2-D33F0EF879B1}"
EndProject
@@ -9,6 +9,12 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mist", "mist\mist.vcxproj",
EndProject
Project("{930C7802-8A8C-48F9-8165-68863BCCD9DD}") = "mish", "mish\mish.wixproj", "{F0DEE5F3-4B62-47A3-B00B-61C614C924FD}"
EndProject
Project("{930C7802-8A8C-48F9-8165-68863BCCD9DD}") = "mish-setup", "mish-setup\mish-setup.wixproj", "{A2CE5056-1114-44B9-B79B-952EF46D3D50}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "GSv6Fwd", "GS-IPv6-Forwarder\GSv6Fwd\GSv6Fwd.vcxproj", "{87DEAE49-7638-4CDB-88EB-054B1F3CB0D2}"
EndProject
Project("{930C7802-8A8C-48F9-8165-68863BCCD9DD}") = "GSv6FwdSetup", "GS-IPv6-Forwarder\GSv6FwdSetup\GSv6FwdSetup.wixproj", "{F8171B99-F5F9-4ABF-9FE5-6753539611AF}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
@@ -39,6 +45,26 @@ Global
{F0DEE5F3-4B62-47A3-B00B-61C614C924FD}.Release|x64.ActiveCfg = Release|x86
{F0DEE5F3-4B62-47A3-B00B-61C614C924FD}.Release|x86.ActiveCfg = Release|x86
{F0DEE5F3-4B62-47A3-B00B-61C614C924FD}.Release|x86.Build.0 = Release|x86
{A2CE5056-1114-44B9-B79B-952EF46D3D50}.Debug|x64.ActiveCfg = Debug|x86
{A2CE5056-1114-44B9-B79B-952EF46D3D50}.Debug|x86.ActiveCfg = Debug|x86
{A2CE5056-1114-44B9-B79B-952EF46D3D50}.Debug|x86.Build.0 = Debug|x86
{A2CE5056-1114-44B9-B79B-952EF46D3D50}.Release|x64.ActiveCfg = Release|x86
{A2CE5056-1114-44B9-B79B-952EF46D3D50}.Release|x86.ActiveCfg = Release|x86
{A2CE5056-1114-44B9-B79B-952EF46D3D50}.Release|x86.Build.0 = Release|x86
{87DEAE49-7638-4CDB-88EB-054B1F3CB0D2}.Debug|x64.ActiveCfg = Debug|x64
{87DEAE49-7638-4CDB-88EB-054B1F3CB0D2}.Debug|x64.Build.0 = Debug|x64
{87DEAE49-7638-4CDB-88EB-054B1F3CB0D2}.Debug|x86.ActiveCfg = Debug|Win32
{87DEAE49-7638-4CDB-88EB-054B1F3CB0D2}.Debug|x86.Build.0 = Debug|Win32
{87DEAE49-7638-4CDB-88EB-054B1F3CB0D2}.Release|x64.ActiveCfg = Release|x64
{87DEAE49-7638-4CDB-88EB-054B1F3CB0D2}.Release|x64.Build.0 = Release|x64
{87DEAE49-7638-4CDB-88EB-054B1F3CB0D2}.Release|x86.ActiveCfg = Release|Win32
{87DEAE49-7638-4CDB-88EB-054B1F3CB0D2}.Release|x86.Build.0 = Release|Win32
{F8171B99-F5F9-4ABF-9FE5-6753539611AF}.Debug|x64.ActiveCfg = Debug|x86
{F8171B99-F5F9-4ABF-9FE5-6753539611AF}.Debug|x86.ActiveCfg = Debug|x86
{F8171B99-F5F9-4ABF-9FE5-6753539611AF}.Debug|x86.Build.0 = Debug|x86
{F8171B99-F5F9-4ABF-9FE5-6753539611AF}.Release|x64.ActiveCfg = Release|x86
{F8171B99-F5F9-4ABF-9FE5-6753539611AF}.Release|x86.ActiveCfg = Release|x86
{F8171B99-F5F9-4ABF-9FE5-6753539611AF}.Release|x86.Build.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
+12 -10
View File
@@ -1,16 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"
xmlns:fire="http://schemas.microsoft.com/wix/FirewallExtension">
<Product Id="*" Name="Moonlight Internet Streaming Helper" Language="1033" Version="!(bind.fileVersion.MistExe)"
xmlns:fire="http://schemas.microsoft.com/wix/FirewallExtension"
xmlns:util="http://schemas.microsoft.com/wix/UtilExtension">
<Product Id="*" Name="Moonlight Internet Hosting Tool" Language="1033" Version="!(bind.fileVersion.MistExe)"
Manufacturer="Moonlight Game Streaming Project" UpgradeCode="cfc2fb53-88e2-4867-851d-9ed9fe7ab2a3">
<Package InstallerVersion="500" Compressed="yes" InstallScope="perMachine" />
<MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />
<MediaTemplate EmbedCab="yes" />
<WixVariable Id="WixUILicenseRtf" Value="license.rtf" />
<UIRef Id="WixUI_Minimal" />
<Feature Id="ProductFeature" Title="MISHSetup" Level="1">
<ComponentGroupRef Id="ProductComponents" />
</Feature>
@@ -19,10 +17,10 @@
<Fragment>
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFilesFolder">
<Directory Id="INSTALLFOLDER" Name="Moonlight Internet Streaming Helper" />
<Directory Id="INSTALLFOLDER" Name="Moonlight Internet Hosting Tool" />
</Directory>
<Directory Id="ProgramMenuFolder">
<Directory Id="ApplicationProgramsFolder" Name="Moonlight Internet Streaming Helper" />
<Directory Id="ApplicationProgramsFolder" Name="Moonlight Internet Hosting Tool" />
</Directory>
<Directory Id="CommonAppDataFolder">
<Directory Name="MISS" Id="MISSLogFolder" />
@@ -38,16 +36,20 @@
Scope="any"
Name="Moonlight Internet Streaming Service"/>
</File>
<CreateFolder Directory="MISSLogFolder" />
<CreateFolder Directory="MISSLogFolder">
<util:PermissionEx User="NT SERVICE\MISS" GenericAll="yes" />
</CreateFolder>
<ServiceInstall Type="ownProcess"
Name="MISS"
DisplayName="Moonlight Internet Streaming Service"
Description="Automatically manages router port forwarding rules required to use Moonlight over the Internet"
Start="auto"
Account="LocalSystem"
Account="NT AUTHORITY\LocalService"
ErrorControl="ignore"
Interactive="no">
<ServiceConfig DelayedAutoStart="no" OnInstall="yes" OnReinstall="yes" />
<ServiceConfig DelayedAutoStart="no" OnInstall="yes" OnReinstall="yes" ServiceSid="restricted">
<RequiredPrivilege>SeChangeNotifyPrivilege</RequiredPrivilege>
</ServiceConfig>
</ServiceInstall>
<ServiceControl Id="StartService" Start="install" Stop="both" Remove="uninstall" Name="MISS" Wait="yes" />
</Component>
+4
View File
@@ -48,6 +48,10 @@
<HintPath>$(WixExtDir)\WixUIExtension.dll</HintPath>
<Name>WixUIExtension</Name>
</WixExtension>
<WixExtension Include="WixUtilExtension">
<HintPath>$(WixExtDir)\WixUtilExtension.dll</HintPath>
<Name>WixUtilExtension</Name>
</WixExtension>
</ItemGroup>
<Import Project="$(WixTargetsPath)" Condition=" '$(WixTargetsPath)' != '' " />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\WiX\v3.x\Wix.targets" Condition=" '$(WixTargetsPath)' == '' AND Exists('$(MSBuildExtensionsPath32)\Microsoft\WiX\v3.x\Wix.targets') " />
+13 -4
View File
@@ -97,7 +97,8 @@ bool UPnPMapPort(struct UPNPUrls* urls, struct IGDdatas* data, int proto, const
printf("NOT FOUND" NL);
}
else if (err == UPNPCOMMAND_SUCCESS) {
if (!strcmp(intClient, myAddr) && !strcmp(desc, myDesc)) {
// Some routers change the description, so we can't check that here
if (!strcmp(intClient, myAddr)) {
if (atoi(leaseDuration) == 0) {
printf("OK (Permanent)" NL);
}
@@ -746,21 +747,29 @@ void ResetLogFile()
{
char oldLogFilePath[MAX_PATH + 1];
char currentLogFilePath[MAX_PATH + 1];
char timeString[MAX_PATH + 1] = {};
SYSTEMTIME time;
ExpandEnvironmentStringsA("%ProgramData%\\MISS\\miss-old.log", oldLogFilePath, sizeof(oldLogFilePath));
ExpandEnvironmentStringsA("%ProgramData%\\MISS\\miss-current.log", currentLogFilePath, sizeof(currentLogFilePath));
// Delete the old log file
DeleteFileA(oldLogFilePath);
// Close the existing stdout handle. This is important because otherwise
// it may still be open as stdout when we try to MoveFileEx below.
fclose(stdout);
// Rotate the current to the old log file
MoveFileA(currentLogFilePath, oldLogFilePath);
MoveFileExA(currentLogFilePath, oldLogFilePath, MOVEFILE_REPLACE_EXISTING);
// Redirect stdout to this new file
freopen(currentLogFilePath, "w", stdout);
// Print a log header
printf("Moonlight Internet Streaming Service v" VER_VERSION_STR NL);
// Print the current time
GetSystemTime(&time);
GetTimeFormatA(LOCALE_SYSTEM_DEFAULT, 0, &time, "hh':'mm':'ss tt", timeString, ARRAYSIZE(timeString));
printf("The current UTC time is: %s" NL, timeString);
}
DWORD WINAPI GameStreamStateChangeThread(PVOID Context)
+3
View File
@@ -3,6 +3,7 @@
VS_VERSION_INFO VERSIONINFO
FILEVERSION VER_VERSION
PRODUCTVERSION VER_VERSION
BEGIN
BLOCK "StringFileInfo"
BEGIN
@@ -11,6 +12,8 @@ BEGIN
VALUE "CompanyName", VER_COMPANYNAME_STR
VALUE "FileDescription", "Moonlight Internet Streaming Service"
VALUE "ProductName", VER_PRODUCTNAME_STR
VALUE "FileVersion", VER_VERSION_STR
VALUE "ProductVersion", VER_VERSION_STR
END
END
+5 -5
View File
@@ -23,32 +23,32 @@
<ProjectGuid>{B71C4E7F-0D92-4E19-BBD2-D33F0EF879B1}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>miss</RootNamespace>
<WindowsTargetPlatformVersion>10.0.17134.0</WindowsTargetPlatformVersion>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>NotSet</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>NotSet</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>NotSet</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>NotSet</CharacterSet>
</PropertyGroup>
+4
View File
@@ -244,6 +244,10 @@ bool PCPMapPort(PSOCKADDR_STORAGE localAddr, int localAddrLen, PSOCKADDR_STORAGE
printf("PCP message truncated: %d\n", bytesRead);
goto fail;
}
else if (resp.hdr.hdr.version != PCP_VERSION) {
printf("PCP version mismatch: %x\n", resp.hdr.hdr.version);
goto fail;
}
else if (resp.hdr.hdr.opcode != OPCODE_MAP_RESPONSE) {
printf("PCP message type mismatch: %x\n", resp.hdr.hdr.opcode);
goto fail;
+83 -28
View File
@@ -22,6 +22,55 @@ static const char* k_SsdpSearchFormatString =
"MX: 5\r\n"
"\r\n";
// Based on logic in https://github.com/miniupnp/miniupnp/blob/master/miniupnpc/minissdpc.c
static void
parseReply(const char* reply, int size,
const char** location, int *locationsize,
const char** st, int* stsize,
const char** usn, int* usnsize)
{
int lineStartIdx = 0;
int headerEndIdx = 0;
for (int i = 0; i < size; i++) {
switch (reply[i])
{
case ':':
// Stop parsing the header at the first colon, but ignore subsequent colons
if (headerEndIdx == 0) {
headerEndIdx = i;
}
break;
case '\r':
case '\n':
if (headerEndIdx != 0) {
// Skip the colon and spaces
do { headerEndIdx++; } while (reply[headerEndIdx] == ' ');
// Check if it's one of the values we care about
if (!_strnicmp(reply + lineStartIdx, "location:", 9)) {
*location = reply + headerEndIdx;
*locationsize = i - headerEndIdx;
}
else if (!_strnicmp(reply + lineStartIdx, "st:", 3)) {
*st = reply + headerEndIdx;
*stsize = i - headerEndIdx;
}
else if (!_strnicmp(reply + lineStartIdx, "usn:", 4)) {
*usn = reply + headerEndIdx;
*usnsize = i - headerEndIdx;
}
// Move on to the next header value
headerEndIdx = 0;
}
lineStartIdx = i + 1;
break;
default:
break;
}
}
}
struct UPNPDev* getUPnPDevicesByAddress(IN_ADDR address)
{
SOCKET s;
@@ -47,6 +96,13 @@ struct UPNPDev* getUPnPDevicesByAddress(IN_ADDR address)
return nullptr;
}
// We will be reading all responses at the end, so ensure we have ample buffer space
// to allow responses to accumulate without loss.
int recvBufferSize = 65535;
if (setsockopt(s, SOL_SOCKET, SO_RCVBUF, (char*)&recvBufferSize, sizeof(recvBufferSize)) == SOCKET_ERROR) {
printf("setsockopt() failed: %d\n", WSAGetLastError());
}
// Send the first search message with HOST set properly
chars = snprintf(searchBuffer, ARRAYSIZE(searchBuffer), k_SsdpSearchFormatString, inet_ntoa(address));
if (send(s, searchBuffer, chars, 0) == SOCKET_ERROR) {
@@ -115,38 +171,37 @@ struct UPNPDev* getUPnPDevicesByAddress(IN_ADDR address)
}
// Parse the header options
// SERVER: FreeBSD/11.2-RELEASE-p2 UPnP/1.1 MiniUPnPd/2.0\r\n
char* location = nullptr;
char* st = nullptr;
while (char* headerName = strtok(nullptr, "\r\n:")) {
char* headerValue = strtok(nullptr, "\r");
if (headerValue == nullptr) {
printf("Unexpected end of SSDP header\n");
break;
}
char* remainder = strtok(nullptr, "");
const char* loc = nullptr;
const char* st = nullptr;
const char* usn = ""; // Initialize to empty since it's optional
int locSize = 0;
int stSize = 0;
int usnSize = 0;
parseReply(remainder, strlen(remainder),
&loc, &locSize, &st, &stSize, &usn, &usnSize);
// Skip leading spaces
while (*headerValue == ' ') headerValue++;
if (!_stricmp(headerName, "LOCATION")) {
location = headerValue;
}
else if (!_stricmp(headerName, "ST")) {
st = headerValue;
}
}
if (!location || location[0] == 0 || !st || st[0] == 0) {
printf("Required value missing: \"%s\" \"%s\"\n", location, st);
if (!loc || locSize == 0 || !st || stSize == 0) {
printf("Required value missing: %d %d\n", locSize, stSize);
continue;
}
struct UPNPDev* newDev = (struct UPNPDev*)malloc(sizeof(*newDev) + strlen(location) + strlen(st) + 2);
struct UPNPDev* newDev = (struct UPNPDev*)malloc(sizeof(*newDev) + usnSize + locSize + stSize + 3);
newDev->pNext = deviceList;
newDev->usn = &newDev->buffer[0]; newDev->buffer[0] = 0;
newDev->descURL = strcpy(newDev->usn + strlen(newDev->usn) + 1, location);
newDev->st = strcpy(newDev->descURL + strlen(newDev->descURL) + 1, st);
newDev->usn = &newDev->buffer[0];
memcpy(newDev->usn, usn, usnSize);
newDev->usn[usnSize] = 0;
newDev->descURL = newDev->usn + usnSize + 1;
memcpy(newDev->descURL, loc, locSize);
newDev->descURL[locSize] = 0;
newDev->st = newDev->descURL + locSize + 1;
memcpy(newDev->st, st, stSize);
newDev->st[stSize] = 0;
newDev->scope_id = 0; // IPv6 only
deviceList = newDev;
@@ -170,7 +225,7 @@ bool getHopsIP4(IN_ADDR* hopAddress, int* hopAddressCount)
char replyBuffer[128];
};
host = gethostbyname("google.com");
host = gethostbyname("moonlight-stream.org");
if (host == nullptr) {
printf("gethostbyname() failed: %d\n", WSAGetLastError());
return false;
+450 -174
View File
@@ -1,23 +1,17 @@
#define _CRT_RAND_S
#define _CRT_SECURE_NO_WARNINGS
#include <stdlib.h>
#include "mist.h"
#define WIN32_LEAN_AND_MEAN
#define _WINSOCK_DEPRECATED_NO_WARNINGS
#include <Windows.h>
#include <WinSock2.h>
#include <Ws2tcpip.h>
#include <stdio.h>
#include <assert.h>
#include <shellapi.h>
#include <objbase.h>
#include "..\version.h"
#include <WinInet.h>
#pragma comment(lib, "miniupnpc.lib")
#pragma comment(lib, "libnatpmp.lib")
#pragma comment(lib, "ws2_32.lib")
#pragma comment(lib, "iphlpapi.lib")
#pragma comment(lib, "wininet.lib")
#define MINIUPNP_STATICLIB
#include <miniupnpc/miniupnpc.h>
@@ -27,8 +21,6 @@
#define NATPMP_STATICLIB
#include <natpmp.h>
bool getExternalAddressPortIP4(int proto, unsigned short localPort, PSOCKADDR_IN wanAddr);
static struct port_entry {
int proto;
int port;
@@ -40,8 +32,13 @@ static struct port_entry {
{IPPROTO_UDP, 47998, true},
{IPPROTO_UDP, 47999, true},
{IPPROTO_UDP, 48000, true},
#if 0
// These are not currently used, so let's
// avoid testing them for now.
{IPPROTO_UDP, 48002, true},
{IPPROTO_UDP, 48010, true}
#endif
};
char logFilePath[MAX_PATH + 1];
@@ -52,49 +49,124 @@ enum MessagePriority {
MpError
};
void DisplayMessage(const char* message, MessagePriority priority = MpError, bool terminal = true)
VOID CALLBACK MsgBoxHelpCallback(LPHELPINFO lpHelpInfo)
{
printf("%s\n", message);
const char* helpUrl = (const char*)lpHelpInfo->dwContextId;
if (!helpUrl) {
return;
}
// It's recommended to initialize COM before calling ShellExecute()
CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
ShellExecuteA(nullptr, "open", helpUrl, nullptr, nullptr, SW_SHOWNORMAL);
}
void DisplayMessage(const char* message, const char* helpUrl = nullptr, MessagePriority priority = MpError, bool terminal = true)
{
fprintf(CONSOLE_OUT, "%s\n", message);
fprintf(LOG_OUT, "%s\n", message);
if (terminal) {
printf("--------------- MISS LOG -------------------\n");
char logPath[MAX_PATH + 1];
FILE* f;
char missPath[MAX_PATH + 1];
ExpandEnvironmentStringsA("%ProgramData%\\MISS\\miss-current.log", missPath, sizeof(missPath));
FILE* f = fopen(missPath, "r");
fprintf(LOG_OUT, "--------------- CURRENT MISS LOG -------------------\n");
ExpandEnvironmentStringsA("%ProgramData%\\MISS\\miss-current.log", logPath, sizeof(logPath));
f = fopen(logPath, "r");
if (f != nullptr) {
char buffer[1024];
while (!feof(f)) {
int bytesRead = fread(buffer, 1, ARRAYSIZE(buffer), f);
fwrite(buffer, 1, bytesRead, stdout);
fwrite(buffer, 1, bytesRead, LOG_OUT);
}
fclose(f);
}
else {
printf("Failed to find MISS log\n");
fprintf(LOG_OUT, "Failed to find current MISS log\n");
}
fflush(stdout);
fprintf(LOG_OUT, "\n----------------- OLD MISS LOG ---------------------\n");
ExpandEnvironmentStringsA("%ProgramData%\\MISS\\miss-old.log", logPath, sizeof(logPath));
f = fopen(logPath, "r");
if (f != nullptr) {
char buffer[1024];
while (!feof(f)) {
int bytesRead = fread(buffer, 1, ARRAYSIZE(buffer), f);
fwrite(buffer, 1, bytesRead, LOG_OUT);
}
fclose(f);
}
else {
fprintf(LOG_OUT, "Failed to find old MISS log\n");
}
fprintf(LOG_OUT, "--------------- CURRENT GSV6FWD LOG -------------------\n");
ExpandEnvironmentStringsA("%ProgramData%\\MISS\\GSv6Fwd-current.log", logPath, sizeof(logPath));
f = fopen(logPath, "r");
if (f != nullptr) {
char buffer[1024];
while (!feof(f)) {
int bytesRead = fread(buffer, 1, ARRAYSIZE(buffer), f);
fwrite(buffer, 1, bytesRead, LOG_OUT);
}
fclose(f);
}
else {
fprintf(LOG_OUT, "Failed to find current GSv6Fwd log\n");
}
fprintf(LOG_OUT, "\n----------------- OLD GSV6FWD LOG ---------------------\n");
ExpandEnvironmentStringsA("%ProgramData%\\MISS\\GSv6Fwd-old.log", logPath, sizeof(logPath));
f = fopen(logPath, "r");
if (f != nullptr) {
char buffer[1024];
while (!feof(f)) {
int bytesRead = fread(buffer, 1, ARRAYSIZE(buffer), f);
fwrite(buffer, 1, bytesRead, LOG_OUT);
}
fclose(f);
}
else {
fprintf(LOG_OUT, "Failed to find old GSv6Fwd log\n");
}
fflush(LOG_OUT);
}
DWORD flags = MB_OK | MB_TOPMOST | MB_SETFOREGROUND;
MSGBOXPARAMSA msgParams;
msgParams.cbSize = sizeof(msgParams);
msgParams.hwndOwner = nullptr;
msgParams.hInstance = nullptr;
msgParams.lpszText = message;
msgParams.lpszCaption = "Moonlight Internet Streaming Tester";
msgParams.dwStyle = MB_OK | MB_TOPMOST | MB_SETFOREGROUND;
if (helpUrl) {
msgParams.dwStyle |= MB_HELP;
}
switch (priority) {
case MpInfo:
flags |= MB_ICONINFORMATION;
msgParams.dwStyle |= MB_ICONINFORMATION;
break;
case MpWarn:
flags |= MB_ICONWARNING;
msgParams.dwStyle |= MB_ICONWARNING;
break;
case MpError:
flags |= MB_ICONERROR;
msgParams.dwStyle |= MB_ICONERROR;
break;
}
MessageBoxA(nullptr, message, "Moonlight Internet Streaming Tester", flags);
msgParams.lpfnMsgBoxCallback = MsgBoxHelpCallback;
msgParams.dwContextHelpId = (DWORD_PTR)helpUrl;
msgParams.dwLanguageId = MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT);
MessageBoxIndirectA(&msgParams);
if (priority != MpInfo && terminal) {
flags = MB_YESNO | MB_TOPMOST | MB_SETFOREGROUND | MB_ICONINFORMATION;
switch (MessageBoxA(nullptr, "Would you like to view the troubleshooting log?",
UINT flags = MB_YESNO | MB_TOPMOST | MB_SETFOREGROUND | MB_ICONINFORMATION;
switch (MessageBoxA(nullptr, "Would you like to view the troubleshooting log?\n\nYou will need to provide this log if you ask for help on the Moonlight Discord server.",
"Moonlight Internet Streaming Tester", flags))
{
case IDYES:
@@ -115,8 +187,9 @@ bool IsGameStreamEnabled()
error = RegOpenKeyExA(HKEY_LOCAL_MACHINE, "Software\\NVIDIA Corporation\\NvStream", 0, KEY_READ | KEY_WOW64_64KEY, &key);
if (error != ERROR_SUCCESS) {
printf("RegOpenKeyEx() failed: %d\n", error);
DisplayMessage("GeForce Experience was not detected on this PC. Make sure you're installing this utility on your GeForce GameStream-compatible PC, not the device running Moonlight.");
fprintf(LOG_OUT, "RegOpenKeyEx() failed: %d\n", error);
DisplayMessage("GeForce Experience was not detected on this PC. Make sure you're installing this utility on your GeForce GameStream-compatible PC, not the device running Moonlight.",
"https://github.com/moonlight-stream/moonlight-docs/wiki/Setup-Guide");
return false;
}
@@ -126,13 +199,14 @@ bool IsGameStreamEnabled()
if (error != ERROR_SUCCESS || !enabled) {
// GFE may not even write EnableStreaming until the user enables GameStream for the first time
if (error != ERROR_SUCCESS) {
printf("RegQueryValueExA() failed: %d\n", error);
fprintf(LOG_OUT, "RegQueryValueExA() failed: %d\n", error);
}
DisplayMessage("GameStream is not enabled in GeForce Experience. Please open GeForce Experience settings, navigate to the Shield tab, and turn GameStream on.");
DisplayMessage("GameStream is not enabled in GeForce Experience. Please open GeForce Experience settings, navigate to the Shield tab, and turn GameStream on.",
"https://github.com/moonlight-stream/moonlight-docs/wiki/Setup-Guide");
return false;
}
else {
printf("GeForce Experience installed and GameStream is enabled\n");
fprintf(LOG_OUT, "GeForce Experience installed and GameStream is enabled\n");
return true;
}
}
@@ -142,21 +216,23 @@ enum PortTestStatus {
PortTestError,
PortTestUnknown
};
PortTestStatus TestPort(PSOCKADDR_STORAGE addr, int proto, int port, bool withServer)
PortTestStatus TestPort(PSOCKADDR_STORAGE addr, int proto, int port, bool withServer, bool isLoopbackRelay)
{
SOCKET clientSock = INVALID_SOCKET, serverSock = INVALID_SOCKET;
int err;
clientSock = socket(addr->ss_family, proto == IPPROTO_TCP ? SOCK_STREAM : SOCK_DGRAM, proto);
if (clientSock == INVALID_SOCKET) {
printf("socket() failed: %d\n", WSAGetLastError());
fprintf(LOG_OUT, "socket() failed: %d\n", WSAGetLastError());
return PortTestError;
}
if (withServer) {
serverSock = socket(addr->ss_family, proto == IPPROTO_TCP ? SOCK_STREAM : SOCK_DGRAM, proto);
// Even if we are testing IPv6, our server socket should still be on IPv4 to allow the
// IPv6 relay to do its job (since it's already bound to all GFE ports on v6)
serverSock = socket(AF_INET, proto == IPPROTO_TCP ? SOCK_STREAM : SOCK_DGRAM, proto);
if (serverSock == INVALID_SOCKET) {
printf("socket() failed: %d\n", WSAGetLastError());
fprintf(LOG_OUT, "socket() failed: %d\n", WSAGetLastError());
closesocket(clientSock);
return PortTestError;
}
@@ -168,21 +244,22 @@ PortTestStatus TestPort(PSOCKADDR_STORAGE addr, int proto, int port, bool withSe
if (err == SOCKET_ERROR) {
if (WSAGetLastError() == WSAEADDRINUSE) {
// If someone is already listening (perhaps GFE is currently streaming),
// we can proceed if it's a TCP connection.
if (proto == IPPROTO_TCP) {
// we can proceed if it's a TCP connection unless it's a loopback relay
// which would give us a false positive result.
if (proto == IPPROTO_TCP && !isLoopbackRelay) {
closesocket(serverSock);
serverSock = INVALID_SOCKET;
}
else {
// We can't continue to test for UDP ports.
printf("Unknown (in use)\n");
fprintf(LOG_OUT, "Unknown (in use)\n");
closesocket(clientSock);
closesocket(serverSock);
return PortTestUnknown;
}
}
else {
printf("bind() failed: %d\n", WSAGetLastError());
fprintf(LOG_OUT, "bind() failed: %d\n", WSAGetLastError());
closesocket(clientSock);
closesocket(serverSock);
return PortTestError;
@@ -192,7 +269,7 @@ PortTestStatus TestPort(PSOCKADDR_STORAGE addr, int proto, int port, bool withSe
if (proto == IPPROTO_TCP && serverSock != INVALID_SOCKET) {
err = listen(serverSock, 1);
if (err == SOCKET_ERROR) {
printf("listen() failed: %d\n", WSAGetLastError());
fprintf(LOG_OUT, "listen() failed: %d\n", WSAGetLastError());
closesocket(clientSock);
closesocket(serverSock);
return PortTestError;
@@ -203,7 +280,7 @@ PortTestStatus TestPort(PSOCKADDR_STORAGE addr, int proto, int port, bool withSe
ULONG nbIo = 1;
err = ioctlsocket(clientSock, FIONBIO, &nbIo);
if (err == SOCKET_ERROR) {
printf("ioctlsocket() failed: %d\n", WSAGetLastError());
fprintf(LOG_OUT, "ioctlsocket() failed: %d\n", WSAGetLastError());
closesocket(clientSock);
if (serverSock != INVALID_SOCKET) {
closesocket(serverSock);
@@ -221,27 +298,38 @@ PortTestStatus TestPort(PSOCKADDR_STORAGE addr, int proto, int port, bool withSe
if (proto == IPPROTO_TCP) {
err = connect(clientSock, (struct sockaddr*)&sin6, addrLen);
if (err == SOCKET_ERROR && WSAGetLastError() != WSAEWOULDBLOCK) {
printf("connect() failed: %d\n", WSAGetLastError());
fprintf(LOG_OUT, "connect() failed: %d\n", WSAGetLastError());
}
else {
struct timeval timeout = {};
fd_set fds;
FD_ZERO(&fds);
FD_SET(clientSock, &fds);
if (serverSock != INVALID_SOCKET) {
FD_SET(serverSock, &fds);
}
else {
FD_SET(clientSock, &fds);
}
// If we have a server socket, listen for the accept() instead of the
// connect() so we can be compatible with the loopback relay.
timeout.tv_sec = 3;
err = select(0, nullptr, &fds, nullptr, &timeout);
err = select(0,
serverSock != INVALID_SOCKET ? &fds : nullptr,
serverSock == INVALID_SOCKET ? &fds : nullptr,
nullptr, &timeout);
if (err == 1) {
// Our FD was signalled for connect() completion
printf("Success\n");
// Our FD was signalled for connect() or accept() completion
fprintf(LOG_OUT, "Success\n");
}
else if (err == 0) {
// Timed out
printf("Timeout\n");
fprintf(LOG_OUT, "Timeout\n");
}
else {
printf("select() failed: %d\n", WSAGetLastError());
fprintf(LOG_OUT, "select() failed: %d\n", WSAGetLastError());
}
}
@@ -254,12 +342,18 @@ PortTestStatus TestPort(PSOCKADDR_STORAGE addr, int proto, int port, bool withSe
}
else {
const char testMsg[] = "moonlight-test";
err = sendto(clientSock, testMsg, sizeof(testMsg), 0, (struct sockaddr*)&sin6, addrLen);
if (err == SOCKET_ERROR) {
printf("sendto() failed: %d\n", WSAGetLastError());
closesocket(clientSock);
closesocket(serverSock);
return PortTestError;
// Send several test packets to ensure a random lost packet doesn't make the test fail
for (int i = 0; i < 5; i++) {
err = sendto(clientSock, testMsg, sizeof(testMsg), 0, (struct sockaddr*)&sin6, addrLen);
if (err == SOCKET_ERROR) {
fprintf(LOG_OUT, "sendto() failed: %d\n", WSAGetLastError());
closesocket(clientSock);
closesocket(serverSock);
return PortTestError;
}
Sleep(200);
}
struct timeval timeout = {};
@@ -268,18 +362,18 @@ PortTestStatus TestPort(PSOCKADDR_STORAGE addr, int proto, int port, bool withSe
FD_ZERO(&fds);
FD_SET(serverSock, &fds);
timeout.tv_sec = 3;
timeout.tv_sec = 2;
err = select(0, &fds, nullptr, nullptr, &timeout);
if (err == 1) {
// Our FD was signalled for data available
printf("Success\n");
fprintf(LOG_OUT, "Success\n");
}
else if (err == 0) {
// Timed out
printf("Timeout\n");
fprintf(LOG_OUT, "Timeout\n");
}
else {
printf("select() failed: %d\n", WSAGetLastError());
fprintf(LOG_OUT, "select() failed: %d\n", WSAGetLastError());
}
closesocket(clientSock);
@@ -289,76 +383,173 @@ PortTestStatus TestPort(PSOCKADDR_STORAGE addr, int proto, int port, bool withSe
}
}
bool TestAllPorts(PSOCKADDR_STORAGE addr, char* portMsg, int portMsgLen)
PortTestStatus TestHttpPort(PSOCKADDR_STORAGE addr, int port)
{
HINTERNET hInternet;
HINTERNET hRequest;
char url[1024];
hInternet = InternetOpenA("MIST", 0, nullptr, nullptr, 0);
if (hInternet == nullptr) {
fprintf(LOG_OUT, "InternetOpen() failed: %d\n", GetLastError());
return PortTestError;
}
char addrStr[INET6_ADDRSTRLEN + 2];
if (addr->ss_family == AF_INET) {
inet_ntop(AF_INET, &((struct sockaddr_in*)addr)->sin_addr, addrStr, sizeof(addrStr));
}
else {
// The address string must be escaped for usage in URLs
addrStr[0] = '[';
inet_ntop(AF_INET6, &((struct sockaddr_in6*)addr)->sin6_addr, &addrStr[1], INET6_ADDRSTRLEN);
strcat_s(addrStr, "]");
}
sprintf(url, "%s://%s:%d/",
port == 47989 ? "http" : "https",
addrStr,
port);
hRequest = InternetOpenUrlA(hInternet, url, nullptr, 0,
INTERNET_FLAG_IGNORE_CERT_DATE_INVALID | INTERNET_FLAG_NO_UI | INTERNET_FLAG_NO_AUTH | INTERNET_FLAG_NO_COOKIES | INTERNET_FLAG_RELOAD,
NULL);
if (hRequest == nullptr) {
if (GetLastError() == ERROR_INTERNET_CLIENT_AUTH_CERT_NEEDED) {
// This is expected for our HTTPS connection
fprintf(LOG_OUT, "Success\n");
}
else {
// CANNOT_CONNECT is the "expected" error
if (GetLastError() == ERROR_INTERNET_CANNOT_CONNECT) {
fprintf(LOG_OUT, "Failed\n");
}
else {
fprintf(LOG_OUT, "Failed: %d\n", GetLastError());
}
InternetCloseHandle(hInternet);
return PortTestError;
}
}
else {
fprintf(LOG_OUT, "Success\n");
InternetCloseHandle(hRequest);
}
InternetCloseHandle(hInternet);
return PortTestOk;
}
bool TestAllPorts(PSOCKADDR_STORAGE addr, char* portMsg, int portMsgLen, bool isLoopbackRelay, bool consolePrint, bool* allPortsFailed = nullptr)
{
bool ret = true;
if (allPortsFailed) {
*allPortsFailed = true;
}
for (int i = 0; i < ARRAYSIZE(k_Ports); i++) {
printf("Testing %s %d...",
fprintf(LOG_OUT, "Testing %s %d...",
k_Ports[i].proto == IPPROTO_TCP ? "TCP" : "UDP",
k_Ports[i].port);
PortTestStatus status = TestPort(addr, k_Ports[i].proto, k_Ports[i].port, k_Ports[i].withServer);
if (consolePrint) {
fprintf(CONSOLE_OUT, "\tTesting %s %d...\n",
k_Ports[i].proto == IPPROTO_TCP ? "TCP" : "UDP",
k_Ports[i].port);
}
PortTestStatus status = TestPort(addr, k_Ports[i].proto, k_Ports[i].port, k_Ports[i].withServer, isLoopbackRelay);
if (status != PortTestError && !k_Ports[i].withServer) {
// Test using a real HTTP client if the port wasn't totally dead.
// This is required to confirm functionality with the loopback relay.
// TestHttpPort() can take significantly longer to timeout than TestPort(),
// so we only do this test if we believe we're likely to get a response.
fprintf(LOG_OUT, "Testing TCP %d with HTTP traffic...", k_Ports[i].port);
status = TestHttpPort(addr, k_Ports[i].port);
}
if (status != PortTestOk) {
// If we got an unknown result, assume it matches with whatever
// we've gotten so far.
if (status == PortTestError || !ret) {
int msgLen = snprintf(portMsg, portMsgLen, "%s %d\n",
k_Ports[i].proto == IPPROTO_TCP ? "TCP" : "UDP",
k_Ports[i].port);
portMsg += msgLen;
portMsgLen -= msgLen;
if (portMsg != NULL && portMsgLen > 0) {
int msgLen = snprintf(portMsg, portMsgLen, "%s %d\n",
k_Ports[i].proto == IPPROTO_TCP ? "TCP" : "UDP",
k_Ports[i].port);
portMsg += msgLen;
portMsgLen -= msgLen;
}
// Keep going to check all ports and report the failing ones
ret = false;
}
}
else if (allPortsFailed) {
*allPortsFailed = false;
}
}
return ret;
}
bool FindLocalInterfaceIP4Address(PSOCKADDR_IN addr)
bool FindLocalInterfaceIPAddress(int family, PSOCKADDR_STORAGE addr)
{
SOCKET s;
struct hostent* host;
struct addrinfo hint = {};
struct addrinfo* result;
int err;
printf("Finding local IP address...");
fprintf(LOG_OUT, "Finding local %s address...", family == AF_INET ? "IPv4" : "IPv6");
host = gethostbyname("google.com");
if (host == nullptr) {
printf("gethostbyname() failed: %d\n", WSAGetLastError());
hint.ai_family = family;
hint.ai_socktype = SOCK_STREAM;
hint.ai_protocol = IPPROTO_TCP;
hint.ai_flags = AI_ADDRCONFIG;
err = getaddrinfo("moonlight-stream.org", "https", &hint, &result);
if (err != 0 || result == NULL) {
fprintf(LOG_OUT, "getaddrinfo() failed: %d\n", err);
return false;
}
s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
s = socket(result->ai_family, result->ai_socktype, result->ai_protocol);
if (s == INVALID_SOCKET) {
printf("socket() failed: %d\n", WSAGetLastError());
fprintf(LOG_OUT, "socket() failed: %d\n", WSAGetLastError());
freeaddrinfo(result);
return false;
}
SOCKADDR_IN sin = {};
sin.sin_family = AF_INET;
sin.sin_port = htons(443);
sin.sin_addr = *(struct in_addr*)host->h_addr;
int err = connect(s, (struct sockaddr*)&sin, sizeof(sin));
err = connect(s, (struct sockaddr*)result->ai_addr, result->ai_addrlen);
if (err == SOCKET_ERROR) {
printf("connect() failed: %d\n", WSAGetLastError());
fprintf(LOG_OUT, "connect() failed: %d\n", WSAGetLastError());
closesocket(s);
freeaddrinfo(result);
return false;
}
freeaddrinfo(result);
// Determine which local interface we bound to
int nameLen = sizeof(*addr);
err = getsockname(s, (struct sockaddr*)addr, &nameLen);
if (err == SOCKET_ERROR) {
printf("getsockname() failed: %d\n", WSAGetLastError());
fprintf(LOG_OUT, "getsockname() failed: %d\n", WSAGetLastError());
closesocket(s);
return false;
}
char addrStr[64];
inet_ntop(AF_INET, &addr->sin_addr, addrStr, sizeof(addrStr));
printf("%s\n", addrStr);
char addrStr[INET6_ADDRSTRLEN];
if (addr->ss_family == AF_INET) {
inet_ntop(AF_INET, &((struct sockaddr_in*)addr)->sin_addr, addrStr, sizeof(addrStr));
}
else {
inet_ntop(AF_INET6, &((struct sockaddr_in6*)addr)->sin6_addr, addrStr, sizeof(addrStr));
}
fprintf(LOG_OUT, "%s\n", addrStr);
return true;
}
@@ -393,28 +584,28 @@ UPnPPortStatus UPnPCheckPort(struct UPNPUrls* urls, struct IGDdatas* data, int p
return ERRORED;
}
printf("Checking for UPnP port mapping for %s %s -> %s...", protoStr, portStr, myAddr);
fprintf(LOG_OUT, "Checking for UPnP port mapping for %s %s -> %s...", protoStr, portStr, myAddr);
int err = UPNP_GetSpecificPortMappingEntry(
urls->controlURL, data->first.servicetype, portStr, protoStr, nullptr,
intClient, intPort, desc, enabled, leaseDuration);
if (err == 714) {
// NoSuchEntryInArray
printf("NOT FOUND\n");
fprintf(LOG_OUT, "NOT FOUND\n");
return NOT_FOUND;
}
else if (err == UPNPCOMMAND_SUCCESS) {
if (!strcmp(myAddr, intClient)) {
printf("OK\n");
fprintf(LOG_OUT, "OK\n");
return OK;
}
else {
printf("CONFLICT - %s %s\n", desc, intClient);
fprintf(LOG_OUT, "CONFLICT - %s %s\n", desc, intClient);
snprintf(conflictMessage, 128, "%s (%s)", desc, intClient);
return CONFLICTED;
}
}
else {
printf("ERROR %d\n", err);
fprintf(LOG_OUT, "ERROR %d\n", err);
return ERRORED;
}
}
@@ -424,23 +615,27 @@ bool CheckWANAccess(PSOCKADDR_IN wanAddr, PSOCKADDR_IN reportedWanAddr, bool* fo
natpmp_t natpmp;
bool foundUpnpIgd = false;
wanAddr->sin_family = AF_INET;
reportedWanAddr->sin_family = AF_INET;
*foundPortForwardingRules = false;
*igdDisconnected = false;
bool gotReportedWanAddress = false;
int natPmpErr = initnatpmp(&natpmp, 0, 0);
if (natPmpErr != 0) {
printf("initnatpmp() failed: %d\n", natPmpErr);
fprintf(LOG_OUT, "initnatpmp() failed: %d\n", natPmpErr);
}
else {
natPmpErr = sendpublicaddressrequest(&natpmp);
if (natPmpErr < 0) {
printf("sendpublicaddressrequest() failed: %d\n", natPmpErr);
fprintf(LOG_OUT, "sendpublicaddressrequest() failed: %d\n", natPmpErr);
closenatpmp(&natpmp);
}
}
{
fprintf(CONSOLE_OUT, "\tTesting UPnP...\n");
int upnpErr;
struct UPNPDev* ipv4Devs = upnpDiscoverAll(5000, nullptr, nullptr, UPNP_LOCAL_PORT_ANY, 0, 2, &upnpErr);
@@ -456,19 +651,19 @@ bool CheckWANAccess(PSOCKADDR_IN wanAddr, PSOCKADDR_IN reportedWanAddr, bool* fo
if (ret == 2) {
*igdDisconnected = true;
}
printf("Discovered UPnP IGD at: %s\n", urls.controlURL);
printf("Detecting WAN IP address via UPnP...");
fprintf(LOG_OUT, "Discovered UPnP IGD at: %s\n", urls.controlURL);
fprintf(LOG_OUT, "Detecting WAN IP address via UPnP...");
ret = UPNP_GetExternalIPAddress(urls.controlURL, data.first.servicetype, wanAddrStr);
if (ret == UPNPCOMMAND_SUCCESS && strlen(wanAddrStr) > 0) {
reportedWanAddr->sin_addr.S_un.S_addr = wanAddr->sin_addr.S_un.S_addr = inet_addr(wanAddrStr);
printf("%s\n", wanAddrStr);
reportedWanAddr->sin_addr.S_un.S_addr = inet_addr(wanAddrStr);
fprintf(LOG_OUT, "%s\n", wanAddrStr);
if (wanAddr->sin_addr.S_un.S_addr != 0) {
if (reportedWanAddr->sin_addr.S_un.S_addr != 0) {
gotReportedWanAddress = true;
}
}
else {
printf("FAILED %d\n", ret);
fprintf(LOG_OUT, "FAILED %d\n", ret);
}
char conflictMessage[512];
@@ -484,7 +679,7 @@ bool CheckWANAccess(PSOCKADDR_IN wanAddr, PSOCKADDR_IN reportedWanAddr, bool* fo
case CONFLICTED:
snprintf(conflictMessage, sizeof(conflictMessage),
"Detected a port forwarding conflict with another PC on your network: %s\n\n"
"Remove that PC from your network or uninstall the Moonlight Internet Streaming Service from it, then restart your router.",
"Remove that PC from your network or uninstall the Moonlight Internet Streaming Helper from it, then restart your router.",
conflictEntry);
DisplayMessage(conflictMessage);
return false;
@@ -494,19 +689,21 @@ bool CheckWANAccess(PSOCKADDR_IN wanAddr, PSOCKADDR_IN reportedWanAddr, bool* fo
}
}
else {
printf("No UPnP IGD detected\n");
fprintf(LOG_OUT, "No UPnP IGD detected\n");
}
FreeUPNPUrls(&urls);
}
else {
printf("No UPnP devices detected\n");
fprintf(LOG_OUT, "No UPnP devices detected\n");
}
}
// Use the delay of upnpDiscoverAll() to also allow the NAT-PMP endpoint time to respond
if (natPmpErr >= 0) {
printf("Detecting WAN IP address via NAT-PMP...");
fprintf(CONSOLE_OUT, "\tTesting NAT-PMP...\n");
fprintf(LOG_OUT, "Detecting WAN IP address via NAT-PMP...");
natpmpresp_t response;
natPmpErr = readnatpmpresponseorretry(&natpmp, &response);
@@ -514,10 +711,10 @@ bool CheckWANAccess(PSOCKADDR_IN wanAddr, PSOCKADDR_IN reportedWanAddr, bool* fo
if (natPmpErr == 0) {
char addrStr[64];
reportedWanAddr->sin_addr = wanAddr->sin_addr = response.pnu.publicaddress.addr;
reportedWanAddr->sin_addr = response.pnu.publicaddress.addr;
inet_ntop(AF_INET, &response.pnu.publicaddress.addr, addrStr, sizeof(addrStr));
printf("%s\n", addrStr);
if (wanAddr->sin_addr.S_un.S_addr != 0) {
fprintf(LOG_OUT, "%s\n", addrStr);
if (reportedWanAddr->sin_addr.S_un.S_addr != 0) {
gotReportedWanAddress = true;
if (!foundUpnpIgd) {
@@ -528,21 +725,21 @@ bool CheckWANAccess(PSOCKADDR_IN wanAddr, PSOCKADDR_IN reportedWanAddr, bool* fo
}
}
else {
printf("FAILED %d\n", natPmpErr);
fprintf(LOG_OUT, "FAILED %d\n", natPmpErr);
}
}
printf("Detecting WAN IP address via STUN...");
if (!getExternalAddressPortIP4(IPPROTO_UDP, 0, wanAddr)) {
if (!gotReportedWanAddress) {
DisplayMessage("Unable to determine your public IP address. Please check your Internet connection.");
return false;
}
fprintf(LOG_OUT, "Detecting WAN IP address via STUN...");
fprintf(CONSOLE_OUT, "\tTesting STUN...\n");
if (!getExternalAddressPortIP4(IPPROTO_UDP, 0, wanAddr) && !getExternalAddressPortIP4(IPPROTO_TCP, 0, wanAddr)) {
DisplayMessage("Unable to determine your public IP address. Please check your Internet connection or try again in a few minutes.");
return false;
}
else {
char addrStr[64];
inet_ntop(AF_INET, &wanAddr->sin_addr, addrStr, sizeof(addrStr));
printf("%s\n", addrStr);
fprintf(LOG_OUT, "%s\n", addrStr);
if (!gotReportedWanAddress) {
// If we didn't get anything from UPnP or NAT-PMP, just populate the reported
@@ -593,18 +790,25 @@ bool IsDoubleNAT(PSOCKADDR_IN wanAddr)
int main(int argc, char* argv[])
{
WSADATA wsaData;
SYSTEMTIME time;
char timeString[MAX_PATH + 1] = {};
char tempPath[MAX_PATH + 1];
GetTempPathA(sizeof(tempPath), tempPath);
snprintf(logFilePath, sizeof(logFilePath), "%s\\%s", tempPath, "mis-test.log");
freopen(logFilePath, "w", stdout);
freopen(logFilePath, "w", LOG_OUT);
// Print a log header
printf("Moonlight Internet Streaming Tester v" VER_VERSION_STR "\n");
fprintf(LOG_OUT, "Moonlight Internet Streaming Tester v" VER_VERSION_STR "\n");
// Print the current time
GetSystemTime(&time);
GetTimeFormatA(LOCALE_SYSTEM_DEFAULT, 0, &time, "hh':'mm':'ss tt", timeString, ARRAYSIZE(timeString));
fprintf(LOG_OUT, "The current UTC time is: %s\n", timeString);
// Print a console header
fprintf(stderr, "Moonlight Internet Streaming Tester v" VER_VERSION_STR "\n\n");
fprintf(CONSOLE_OUT, "Moonlight Internet Streaming Tester v" VER_VERSION_STR "\n\n");
int err = WSAStartup(MAKEWORD(2, 2), &wsaData);
if (err != NO_ERROR) {
@@ -612,7 +816,7 @@ int main(int argc, char* argv[])
return err;
}
fprintf(stderr, "Checking if GameStream is enabled...\n");
fprintf(CONSOLE_OUT, "Checking if GameStream is enabled...\n");
// First check if GameStream is enabled
if (!IsGameStreamEnabled()) {
@@ -627,92 +831,164 @@ int main(int argc, char* argv[])
char msgBuf[2048];
char portMsgBuf[512];
fprintf(stderr, "Testing local GameStream connectivity...\n");
fprintf(CONSOLE_OUT, "Testing GameStream connectivity on this PC...\n");
// Try to connect via IPv4 loopback
ss = {};
sin.sin_family = AF_INET;
sin.sin_addr = in4addr_loopback;
printf("Testing GameStream ports via loopback\n");
if (!TestAllPorts(&ss, portMsgBuf, sizeof(portMsgBuf))) {
fprintf(LOG_OUT, "Testing GameStream ports via loopback\n");
if (!TestAllPorts(&ss, portMsgBuf, sizeof(portMsgBuf), false, true)) {
snprintf(msgBuf, sizeof(msgBuf),
"Local GameStream connectivity check failed. Please try reinstalling GeForce Experience.\n\nThe following ports were not working:\n%s",
portMsgBuf);
DisplayMessage(msgBuf);
"Local GameStream connectivity check failed.\n\nFirst, try reinstalling GeForce Experience. If that doesn't resolve the problem, try temporarily disabling your antivirus and firewall.");
DisplayMessage(msgBuf, "https://github.com/moonlight-stream/moonlight-docs/wiki/Troubleshooting");
return -1;
}
if (!FindLocalInterfaceIP4Address(&sin)) {
if (!FindLocalInterfaceIPAddress(AF_INET, &ss) && !FindLocalInterfaceIPAddress(AF_INET6, &ss)) {
DisplayMessage("Unable to perform GameStream connectivity check. Please check your Internet connection and try again.");
return -1;
}
fprintf(stderr, "Testing network GameStream connectivity...\n");
fprintf(CONSOLE_OUT, "Testing GameStream connectivity on your local network...\n");
// Try to connect via LAN IPv4 address
printf("Testing GameStream ports via local network\n");
if (!TestAllPorts(&ss, portMsgBuf, sizeof(portMsgBuf))) {
// Try to connect via LAN address
fprintf(LOG_OUT, "Testing GameStream ports via local network\n");
if (!TestAllPorts(&ss, portMsgBuf, sizeof(portMsgBuf), false, true)) {
snprintf(msgBuf, sizeof(msgBuf),
"Local network GameStream connectivity check failed. Try temporarily disabling your firewall software or adding firewall exceptions for the following ports:\n%s",
portMsgBuf);
DisplayMessage(msgBuf);
"Local network GameStream connectivity check failed. This is almost always caused by a firewall on your computer blocking the connection.\n\nTry temporarily disabling your antivirus and firewall.");
DisplayMessage(msgBuf, "https://github.com/moonlight-stream/moonlight-docs/wiki/Troubleshooting");
return -1;
}
fprintf(stderr, "Detecting public IP address...\n");
bool rulesFound, igdDisconnected;
bool igdDisconnected;
SOCKADDR_IN locallyReportedWanAddr;
if (!CheckWANAccess(&sin, &locallyReportedWanAddr, &rulesFound, &igdDisconnected)) {
return -1;
char wanAddrStr[INET_ADDRSTRLEN];
if (ss.ss_family == AF_INET) {
bool rulesFound;
fprintf(CONSOLE_OUT, "Detecting public IP address...\n");
if (!CheckWANAccess(&sin, &locallyReportedWanAddr, &rulesFound, &igdDisconnected)) {
return -1;
}
fprintf(CONSOLE_OUT, "Testing GameStream connectivity over the Internet...\n");
// Detect a double NAT by detecting STUN and and UPnP mismatches
if (sin.sin_addr.S_un.S_addr != locallyReportedWanAddr.sin_addr.S_un.S_addr) {
fprintf(LOG_OUT, "Testing GameStream ports via UPnP/NAT-PMP reported WAN address\n");
// We don't actually care about the outcome here but it's nice to have in logs
// to determine whether solving the double NAT will actually make Moonlight work.
TestAllPorts((PSOCKADDR_STORAGE)&locallyReportedWanAddr, portMsgBuf, sizeof(portMsgBuf), false, false);
fprintf(LOG_OUT, "Detected inconsistency between UPnP/NAT-PMP and STUN reported WAN addresses!\n");
}
inet_ntop(AF_INET, &sin.sin_addr, wanAddrStr, sizeof(wanAddrStr));
}
// Detect a double NAT by detecting STUN and and UPnP mismatches
if (sin.sin_addr.S_un.S_addr != locallyReportedWanAddr.sin_addr.S_un.S_addr) {
printf("Testing GameStream ports via UPnP/NAT-PMP reported WAN address\n");
// We don't actually care about the outcome here but it's nice to have in logs
// to determine whether solving the double NAT will actually make Moonlight work.
TestAllPorts((PSOCKADDR_STORAGE)&locallyReportedWanAddr, portMsgBuf, sizeof(portMsgBuf));
printf("Detected inconsistency between UPnP/NAT-PMP and STUN reported WAN addresses!\n");
else {
// Go directly to the relay check if we have only IPv6 connectivity
igdDisconnected = false;
locallyReportedWanAddr = {};
goto RelayCheck;
}
fprintf(stderr, "Testing Internet GameStream connectivity...\n");
char wanAddrStr[64];
inet_ntop(AF_INET, &sin.sin_addr, wanAddrStr, sizeof(wanAddrStr));
// Try to connect via WAN IPv4 address
printf("Testing GameStream ports via STUN-reported WAN address\n");
if (!TestAllPorts(&ss, portMsgBuf, sizeof(portMsgBuf))) {
if (IsDoubleNAT(&locallyReportedWanAddr)) {
snprintf(msgBuf, sizeof(msgBuf), "Your router appears be connected to the Internet through another router. Make sure both routers have UPnP or NAT-PMP enabled, or better yet, switch one of the routers into bridge/AP mode.");
DisplayMessage(msgBuf);
}
else if (IsPossibleCGN(&locallyReportedWanAddr)) {
snprintf(msgBuf, sizeof(msgBuf), "Your ISP is running a Carrier-Grade NAT that is preventing you from hosting services like Moonlight on the Internet. Contact your ISP and ask for a dedicated public IP address.");
DisplayMessage(msgBuf);
}
else if (igdDisconnected) {
snprintf(msgBuf, sizeof(msgBuf), "Internet GameStream connectivity check failed. Make sure you don't have two devices acting as routers connected together.");
DisplayMessage(msgBuf);
}
else if (rulesFound) {
snprintf(msgBuf, sizeof(msgBuf), "Manual Internet streaming test required!\n\n"
"Connect your client device to a different network or cellular data (it MUST NOT on be the same network as this PC for testing!). If Moonlight doesn't automatically connect, you can type the following address into Moonlight's Add PC dialog: %s\n\n"
"If that doesn't work, check your router settings for any existing Moonlight port forwarding entries and delete them or try restarting your router.", wanAddrStr);
DisplayMessage(msgBuf, MpWarn);
fprintf(LOG_OUT, "Testing GameStream ports via STUN-reported WAN address\n");
if (!TestAllPorts(&ss, portMsgBuf, sizeof(portMsgBuf), false, true)) {
RelayCheck:
struct addrinfo hint = {};
struct addrinfo* result;
// We can get here if the router doesn't support NAT reflection.
// We'll need to call out to our loopback server to get a second opinion.
hint.ai_family = AF_UNSPEC;
hint.ai_flags = AI_ADDRCONFIG;
err = getaddrinfo("loopback.moonlight-stream.org", NULL, &hint, &result);
if (err != 0 || result == NULL) {
fprintf(LOG_OUT, "getaddrinfo() failed: %d\n", err);
}
else {
snprintf(msgBuf, sizeof(msgBuf), "Internet GameStream connectivity check failed. Make sure UPnP or NAT-PMP is enabled in your router settings.\n\nThe following ports were not forwarded properly:\n%s", portMsgBuf);
DisplayMessage(msgBuf);
bool allPortsFailedOnV4 = true;
// First try the relay server over IPv4. If this passes, it's considered a full success
fprintf(LOG_OUT, "Testing GameStream ports via IPv4 loopback server\n");
for (struct addrinfo* current = result; current != NULL; current = current->ai_next) {
if (current->ai_family == AF_INET) {
fprintf(CONSOLE_OUT, "Testing GameStream connectivity over the Internet using a relay server...\n");
if (TestAllPorts((PSOCKADDR_STORAGE)current->ai_addr, portMsgBuf, sizeof(portMsgBuf), true, true, &allPortsFailedOnV4)) {
freeaddrinfo(result);
goto AllTestsPassed;
}
}
}
// If that fails, try the relay server over IPv6. If this passes, it will be a partial success
fprintf(LOG_OUT, "Testing GameStream ports via IPv6 loopback server\n");
for (struct addrinfo* current = result; current != NULL; current = current->ai_next) {
if (current->ai_family == AF_INET6) {
fprintf(CONSOLE_OUT, "Testing GameStream connectivity over the Internet using an IPv6 relay server...\n");
// Pass the portMsgBuf only if we've detected an IPv6-only setup. Otherwise, we want to preserve
// the failing ports from the IPv4 to display in the error dialog.
if (TestAllPorts((PSOCKADDR_STORAGE)current->ai_addr,
ss.ss_family == AF_INET6 ? portMsgBuf : NULL,
ss.ss_family == AF_INET6 ? sizeof(portMsgBuf) : 0, true, true)) {
// We will terminate the test at the IPv6 limited connectivity warning in the following cases:
// 1) Double-NAT/CGN - indicates the connection is fundamentally limited to IPv6 for end-to-end connectivity
// 2) IPv6-only - indicates the connection is fundamentally limited to IPv6 for all connectivity
// 3) All ports failed the test with our IPv4 relay - This is one final heuristic to weed out IPv4 misconfigurations. If we have some ports open,
// it clearly indicates IPv4 support is possible, just currently misconfigured.
//
// Our last (implicit) heuristic is that we actually managed to establish an IPv6 connection. This means that there was either
// no IPv6 firewall (hopefully not) or that we were able to talk to a PCP/IGDv6 gateway to allow us through. Hopefully if we have
// a gateway that is unresponsive to UPnP/NAT-PMP, we wouldn't even be able to establish this connection so we would inherently fall
// to the checks below for IPv4 issues.
if (IsDoubleNAT(&locallyReportedWanAddr) || igdDisconnected || IsPossibleCGN(&locallyReportedWanAddr) || ss.ss_family == AF_INET6 || allPortsFailedOnV4) {
snprintf(msgBuf, sizeof(msgBuf), "This PC has limited connectivity for Internet hosting. It will work only for clients on certain networks.\n\n"
"If you want to try streaming with this configuration, you must pair Moonlight to your gaming PC from your home network before trying to stream over the Internet.\n\n"
"To get full connectivity, please contact your ISP and ask for a \"public IP address\" which they may offer for free upon request. For more information and workarounds, click the Help button.");
DisplayMessage(msgBuf, "https://github.com/moonlight-stream/moonlight-docs/wiki/Internet-Streaming-Errors#limited-connectivity-for-hosting-error", MpWarn);
freeaddrinfo(result);
return 0;
}
}
}
}
freeaddrinfo(result);
}
// Many UPnP devices report IGD disconnected when double-NATed. If it was really offline,
// we probably would not have even gotten past STUN.
if (IsDoubleNAT(&locallyReportedWanAddr) || igdDisconnected) {
snprintf(msgBuf, sizeof(msgBuf), "Your router appears be connected to the Internet through another router. Click the Help button for guidance on fixing this issue.");
DisplayMessage(msgBuf, "https://github.com/moonlight-stream/moonlight-docs/wiki/Internet-Streaming-Errors#connected-through-another-router-error");
}
else if (IsPossibleCGN(&locallyReportedWanAddr)) {
snprintf(msgBuf, sizeof(msgBuf), "Your ISP is running a Carrier-Grade NAT that is preventing you from hosting services like Moonlight on the Internet.\n\n"
"Ask your ISP for a \"public IP address\" which they may offer for free upon request. For more information and workarounds, click the Help button.");
DisplayMessage(msgBuf, "https://github.com/moonlight-stream/moonlight-docs/wiki/Internet-Streaming-Errors#carrier-grade-nat-error");
}
else {
snprintf(msgBuf, sizeof(msgBuf), "Internet GameStream connectivity check failed.\n\n"
"Check that UPnP is enabled in your router settings. For more information and workarounds, click the Help button.\n\n"
"The following ports were not forwarded properly:\n%s", portMsgBuf);
DisplayMessage(msgBuf, "https://github.com/moonlight-stream/moonlight-docs/wiki/Internet-Streaming-Errors#internet-gamestream-connectivity-check-error");
}
return -1;
}
snprintf(msgBuf, sizeof(msgBuf), "All tests passed! If Moonlight doesn't automatically connect outside your network, you can type the following address into Moonlight's Add PC dialog: %s", wanAddrStr);
DisplayMessage(msgBuf, MpInfo);
AllTestsPassed:
snprintf(msgBuf, sizeof(msgBuf), "This PC is ready to host over the Internet!\n\n"
"For the easiest setup, you should pair Moonlight to your gaming PC from your home network before trying to stream over the Internet.\n\n"
"If you can't, you can type the following address into Moonlight's Add PC dialog: %s", wanAddrStr);
DisplayMessage(msgBuf, nullptr, MpInfo);
return 0;
}
+17
View File
@@ -0,0 +1,17 @@
#pragma once
#define _CRT_RAND_S
#define _CRT_SECURE_NO_WARNINGS
#include <stdlib.h>
#define WIN32_LEAN_AND_MEAN
#define _WINSOCK_DEPRECATED_NO_WARNINGS
#include <Windows.h>
#include <WinSock2.h>
#include "..\version.h"
#define CONSOLE_OUT stdout
#define LOG_OUT stderr
bool getExternalAddressPortIP4(int proto, unsigned short localPort, PSOCKADDR_IN wanAddr);
+3
View File
@@ -3,6 +3,7 @@
VS_VERSION_INFO VERSIONINFO
FILEVERSION VER_VERSION
PRODUCTVERSION VER_VERSION
BEGIN
BLOCK "StringFileInfo"
BEGIN
@@ -11,6 +12,8 @@ BEGIN
VALUE "CompanyName", VER_COMPANYNAME_STR
VALUE "FileDescription", "Moonlight Internet Streaming Tester"
VALUE "ProductName", VER_PRODUCTNAME_STR
VALUE "FileVersion", VER_VERSION_STR
VALUE "ProductVersion", VER_VERSION_STR
END
END
+6 -5
View File
@@ -23,32 +23,32 @@
<ProjectGuid>{8F78D8D2-A837-489C-BAC5-81494C9CEF7A}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>mist</RootNamespace>
<WindowsTargetPlatformVersion>10.0.17134.0</WindowsTargetPlatformVersion>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>NotSet</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>NotSet</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
@@ -167,6 +167,7 @@
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\version.h" />
<ClInclude Include="mist.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
+3
View File
@@ -26,6 +26,9 @@
<ClInclude Include="..\version.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="mist.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="mist.rc">
+21 -27
View File
@@ -1,11 +1,4 @@
#define _CRT_RAND_S
#define _CRT_SECURE_NO_WARNINGS
#include <stdlib.h>
#define WIN32_LEAN_AND_MEAN
#define _WINSOCK_DEPRECATED_NO_WARNINGS
#include <Windows.h>
#include <WinSock2.h>
#include "mist.h"
#include <stdio.h>
@@ -61,15 +54,15 @@ bool getExternalAddressPortIP4(int proto, unsigned short localPort, PSOCKADDR_IN
char buf[1024];
} resp;
host = gethostbyname("stun.stunprotocol.org");
host = gethostbyname("stun.moonlight-stream.org");
if (host == nullptr) {
printf("gethostbyname() failed: %d\n", WSAGetLastError());
fprintf(LOG_OUT, "gethostbyname() failed: %d\n", WSAGetLastError());
return false;
}
sock = socket(AF_INET, proto == IPPROTO_TCP ? SOCK_STREAM : SOCK_DGRAM, proto);
if (sock == INVALID_SOCKET) {
printf("socket() failed: %d\n", WSAGetLastError());
fprintf(LOG_OUT, "socket() failed: %d\n", WSAGetLastError());
return false;
}
@@ -77,7 +70,7 @@ bool getExternalAddressPortIP4(int proto, unsigned short localPort, PSOCKADDR_IN
bindAddr.sin_family = AF_INET;
bindAddr.sin_port = htons(localPort);
if (bind(sock, (struct sockaddr*)&bindAddr, sizeof(bindAddr)) == SOCKET_ERROR) {
printf("bind() failed: %d\n", WSAGetLastError());
fprintf(LOG_OUT, "bind() failed: %d\n", WSAGetLastError());
closesocket(sock);
return false;
}
@@ -96,7 +89,7 @@ bool getExternalAddressPortIP4(int proto, unsigned short localPort, PSOCKADDR_IN
// We'll connect() even for UDP so we can use send()/recv() and share more code
if (connect(sock, (struct sockaddr*)&stunAddr, sizeof(stunAddr)) == SOCKET_ERROR) {
printf("connect() failed: %d\n", WSAGetLastError());
fprintf(LOG_OUT, "connect() failed: %d\n", WSAGetLastError());
closesocket(sock);
return false;
}
@@ -112,11 +105,11 @@ bool getExternalAddressPortIP4(int proto, unsigned short localPort, PSOCKADDR_IN
timeout = 1;
}
bytesRead = SOCKET_ERROR;
bytesRead = 0;
for (i = 0; i < tries; i++) {
// Retransmit the request every second until the timeout elapses
if (send(sock, (char *)&reqMsg, sizeof(reqMsg), 0) == SOCKET_ERROR) {
printf("send() failed: %d\n", WSAGetLastError());
fprintf(LOG_OUT, "send() failed: %d\n", WSAGetLastError());
closesocket(sock);
return false;
}
@@ -135,7 +128,7 @@ bool getExternalAddressPortIP4(int proto, unsigned short localPort, PSOCKADDR_IN
continue;
}
else if (selectRes == SOCKET_ERROR) {
printf("select() failed: %d\n", WSAGetLastError());
fprintf(LOG_OUT, "select() failed: %d\n", WSAGetLastError());
closesocket(sock);
return false;
}
@@ -148,27 +141,27 @@ bool getExternalAddressPortIP4(int proto, unsigned short localPort, PSOCKADDR_IN
closesocket(sock);
if (bytesRead == 0) {
printf("No response from STUN server\n");
fprintf(LOG_OUT, "No response from STUN server\n");
return false;
}
else if (bytesRead == SOCKET_ERROR) {
printf("Failed to read STUN binding response: %d\n", WSAGetLastError());
fprintf(LOG_OUT, "Failed to read STUN binding response: %d\n", WSAGetLastError());
return false;
}
else if (bytesRead < sizeof(resp.hdr)) {
printf("STUN message truncated: %d\n", bytesRead);
fprintf(LOG_OUT, "STUN message truncated: %d\n", bytesRead);
return false;
}
else if (htonl(resp.hdr.magicCookie) != STUN_MESSAGE_COOKIE) {
printf("Bad STUN cookie value: %x\n", htonl(resp.hdr.magicCookie));
fprintf(LOG_OUT, "Bad STUN cookie value: %x\n", htonl(resp.hdr.magicCookie));
return false;
}
else if (memcmp(reqMsg.transactionId, resp.hdr.transactionId, sizeof(reqMsg.transactionId))) {
printf("STUN transaction ID mismatch\n");
fprintf(LOG_OUT, "STUN transaction ID mismatch\n");
return false;
}
else if (htons(resp.hdr.messageType) != STUN_MESSAGE_BINDING_SUCCESS) {
printf("STUN message type mismatch: %x\n", htons(resp.hdr.messageType));
fprintf(LOG_OUT, "STUN message type mismatch: %x\n", htons(resp.hdr.messageType));
return false;
}
@@ -176,10 +169,11 @@ bool getExternalAddressPortIP4(int proto, unsigned short localPort, PSOCKADDR_IN
bytesRead -= sizeof(resp.hdr);
while (bytesRead > sizeof(*attribute)) {
if (bytesRead < sizeof(*attribute) + htons(attribute->length)) {
printf("STUN attribute out of bounds: %d\n", htons(attribute->length));
fprintf(LOG_OUT, "STUN attribute out of bounds: %d\n", htons(attribute->length));
return false;
}
else if (htons(attribute->type) != STUN_ATTRIBUTE_XOR_MAPPED_ADDRESS) {
// Mask off the comprehension bit
else if ((htons(attribute->type) & 0x7FFF) != STUN_ATTRIBUTE_XOR_MAPPED_ADDRESS) {
// Continue searching if this wasn't our address
bytesRead -= sizeof(*attribute) + htons(attribute->length);
attribute = (PSTUN_ATTRIBUTE_HEADER)(((char*)attribute) + sizeof(*attribute) + htons(attribute->length));
@@ -188,11 +182,11 @@ bool getExternalAddressPortIP4(int proto, unsigned short localPort, PSOCKADDR_IN
ipv4Attrib = (PSTUN_MAPPED_IPV4_ADDRESS_ATTRIBUTE)attribute;
if (htons(ipv4Attrib->hdr.length) != 8) {
printf("STUN address length mismatch: %d\n", htons(ipv4Attrib->hdr.length));
fprintf(LOG_OUT, "STUN address length mismatch: %d\n", htons(ipv4Attrib->hdr.length));
return false;
}
else if (ipv4Attrib->addressFamily != 1) {
printf("STUN address family mismatch: %x\n", ipv4Attrib->addressFamily);
fprintf(LOG_OUT, "STUN address family mismatch: %x\n", ipv4Attrib->addressFamily);
return false;
}
@@ -206,6 +200,6 @@ bool getExternalAddressPortIP4(int proto, unsigned short localPort, PSOCKADDR_IN
return true;
}
printf("No XOR mapped address found in STUN response!\n");
fprintf(LOG_OUT, "No XOR mapped address found in STUN response!\n");
return false;
}
+3 -3
View File
@@ -1,7 +1,7 @@
#pragma once
#define VER_VERSION 2,1,0,0
#define VER_VERSION_STR "2.1.0.0"
#define VER_VERSION 4,1,0,0
#define VER_VERSION_STR "4.1.0.0"
#define VER_COMPANYNAME_STR "Moonlight Game Streaming Project"
#define VER_PRODUCTNAME_STR "Moonlight Internet Streaming Helper"
#define VER_PRODUCTNAME_STR "Moonlight Internet Hosting Tool"