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

Commit

Permalink
Fix defect # 22
Browse files Browse the repository at this point in the history
- Routers failed with 404 when service control url had a question mark.
- DD-WRT Linux base router (and others probably) fails with
402-InvalidArgument when index is out of range
- Some routers retuns invalid mapping entries with empty internal
client.
  • Loading branch information
lontivero committed Apr 17, 2015
1 parent ea28675 commit 790b407
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
22 changes: 18 additions & 4 deletions Open.Nat/Upnp/UpnpNatDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,26 +132,40 @@ public override async Task<IEnumerable<Mapping>> GetAllMappingsAsync()
{
try
{
var message = new GetGenericPortMappingEntry(index);
var message = new GetGenericPortMappingEntry(index++);

var responseData = await _soapClient
.InvokeAsync("GetGenericPortMappingEntry", message.ToXml())
.TimeoutAfter(TimeSpan.FromSeconds(4));

var responseMessage = new GetPortMappingEntryResponseMessage(responseData, DeviceInfo.ServiceType, true);

IPAddress internalClientIp;
if(!IPAddress.TryParse(responseMessage.InternalClient, out internalClientIp))
{
NatDiscoverer.TraceSource.LogWarn("InternalClient is not an IP address. Mapping ignored!");
continue;
}

var mapping = new Mapping(responseMessage.Protocol
, IPAddress.Parse(responseMessage.InternalClient)
, internalClientIp
, responseMessage.InternalPort
, responseMessage.ExternalPort
, responseMessage.LeaseDuration
, responseMessage.PortMappingDescription);
mappings.Add(mapping);
index++;
}
catch (MappingException e)
{
if (e.ErrorCode == UpnpConstants.SpecifiedArrayIndexInvalid) break; // there are no more mappings
if (e.ErrorCode == UpnpConstants.SpecifiedArrayIndexInvalid
|| e.ErrorCode == UpnpConstants.NoSuchEntryInArray) break; // there are no more mappings

// DD-WRT Linux base router (and others probably) fails with 402-InvalidArgument when index is out of range
if (e.ErrorCode == UpnpConstants.InvalidArguments)
{
NatDiscoverer.TraceSource.LogWarn("Router failed with 402-InvalidArgument. No more mappings is assumed.");
break;
}
throw;
}
}
Expand Down
4 changes: 2 additions & 2 deletions Open.Nat/Upnp/UpnpNatDeviceInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ public UpnpNatDeviceInfo(IPAddress localAddress, Uri locationUri, string service
NatDiscoverer.TraceSource.LogInfo("{0}: New control url: {1}", HostEndPoint, serviceControlUrl);
}

var builder = new UriBuilder("http", locationUri.Host, locationUri.Port, serviceControlUrl);
ServiceControlUri = builder.Uri;
var builder = new UriBuilder("http", locationUri.Host, locationUri.Port);
ServiceControlUri = new Uri(builder.Uri, serviceControlUrl); ;
}

public IPEndPoint HostEndPoint { get; private set; }
Expand Down

0 comments on commit 790b407

Please sign in to comment.