Skip to content
This repository was archived by the owner on Jun 8, 2024. It is now read-only.
This repository was 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

@manutoo

Description

@manutoo

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions