Skip to content
This repository has been archived by the owner on Jun 8, 2024. It is now read-only.

CreatePortMapAsync() fails with IPv4+IPv6 router, with Error 600: Argument Value Invalid #100

Open
manutoo opened this issue Jan 17, 2021 · 0 comments
Labels

Comments

@manutoo
Copy link

manutoo commented Jan 17, 2021

My ISP is Orange, with a LiveBox v4 router by Sagem.

When using DiscoverDeviceAsync, it returns the router with its IPv6 address.

Trying to open port with the IPv6 fails likely because the router doesn't accept local IPv6, but only IPv4 ones.

Moreover, it's not possible to manually specify the local IPv4 in the request because the requesting IP should match the one in the entry added, so if it's done over the IPv6 network, then they won't be the same.

To fix that, I had to do in DiscoverDeviceAsync():

  1. changed:

    var devices = await DiscoverAsync(portMapper, true, cancellationTokenSource);

to:

var devices = await DiscoverAsync(portMapper, false, cancellationTokenSource);		//TOO: Need them all, so can keep the IPv4 one if it's there
  1. changed:
    var device = devices.FirstOrDefault();
    to:

     	NatDevice device = null;
    
     	foreach (var MyDevice in devices)
     	{
     		System.Net.IPAddress Ip = MyDevice.GetIPAddress();
    
     		if (Ip.AddressFamily != System.Net.Sockets.AddressFamily.InterNetworkV6)
     		{
     			device = MyDevice;
     			break;
     		}
     	}
    
     	if (device == null)
     	{
     		device = devices.FirstOrDefault();
     	}
    
  2. Added support for GetIPAddress() to the device classes.

Side note: with Unity, the mappings aren't automatically removed, at least in the Editor.

@manutoo manutoo changed the title CreatePortMapAsync() fails with IPv6 router, with Error 600: Argument Value Invalid CreatePortMapAsync() fails with IPv4+IPv6 router, with Error 600: Argument Value Invalid Jan 17, 2021
@lontivero lontivero added the bug label Jan 9, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants