diff --git a/Lidgren.Network/NetUPnP.cs b/Lidgren.Network/NetUPnP.cs
index 217602f..ac71115 100644
--- a/Lidgren.Network/NetUPnP.cs
+++ b/Lidgren.Network/NetUPnP.cs
@@ -160,77 +160,84 @@ namespace Lidgren.Network
return false;
}
return false;
- }
+ }
- ///
- /// Add a forwarding rule to the router using UPnP
- ///
- public bool ForwardPort(int port, string description)
- {
- if (!CheckAvailability())
- return false;
+ ///
+ /// Add a forwarding rule to the router using UPnP
+ ///
+ /// The external, WAN facing, port
+ /// A description for the port forwarding rule
+ /// The port on the client machine to send traffic to
+ public bool ForwardPort(int externalPort, string description, int internalPort = 0)
+ {
+ if (!CheckAvailability())
+ return false;
- IPAddress mask;
- var client = NetUtility.GetMyAddress(out mask);
- if (client == null)
- return false;
+ IPAddress mask;
+ var client = NetUtility.GetMyAddress(out mask);
+ if (client == null)
+ return false;
- try
- {
- SOAPRequest(m_serviceUrl,
- "" +
- "" +
- "" + port.ToString() + "" +
- "" + ProtocolType.Udp.ToString().ToUpper(System.Globalization.CultureInfo.InvariantCulture) + "" +
- "" + port.ToString() + "" +
- "" + client.ToString() + "" +
- "1" +
- "" + description + "" +
- "0" +
- "",
- "AddPortMapping");
+ if (internalPort == 0)
+ internalPort = externalPort;
- m_peer.LogDebug("Sent UPnP port forward request");
- NetUtility.Sleep(50);
- }
- catch (Exception ex)
- {
- m_peer.LogWarning("UPnP port forward failed: " + ex.Message);
- return false;
- }
- return true;
- }
+ try
+ {
+ SOAPRequest(m_serviceUrl,
+ "" +
+ "" +
+ "" + externalPort.ToString() + "" +
+ "" + ProtocolType.Udp.ToString().ToUpper(System.Globalization.CultureInfo.InvariantCulture) + "" +
+ "" + internalPort.ToString() + "" +
+ "" + client.ToString() + "" +
+ "1" +
+ "" + description + "" +
+ "0" +
+ "",
+ "AddPortMapping");
- ///
- /// Delete a forwarding rule from the router using UPnP
- ///
- public bool DeleteForwardingRule(int port)
- {
- if (!CheckAvailability())
- return false;
+ m_peer.LogDebug("Sent UPnP port forward request");
+ NetUtility.Sleep(50);
+ }
+ catch (Exception ex)
+ {
+ m_peer.LogWarning("UPnP port forward failed: " + ex.Message);
+ return false;
+ }
+ return true;
+ }
- try
- {
- SOAPRequest(m_serviceUrl,
- "" +
- "" +
- "" +
- "" + port + "" +
- "" + ProtocolType.Udp.ToString().ToUpper(System.Globalization.CultureInfo.InvariantCulture) + "" +
- "", "DeletePortMapping");
- return true;
- }
- catch (Exception ex)
- {
- m_peer.LogWarning("UPnP delete forwarding rule failed: " + ex.Message);
- return false;
- }
- }
+ ///
+ /// Delete a forwarding rule from the router using UPnP
+ ///
+ /// The external, 'internet facing', port
+ public bool DeleteForwardingRule(int externalPort)
+ {
+ if (!CheckAvailability())
+ return false;
- ///
- /// Retrieve the extern ip using UPnP
- ///
- public IPAddress GetExternalIP()
+ try
+ {
+ SOAPRequest(m_serviceUrl,
+ "" +
+ "" +
+ "" +
+ "" + externalPort + "" +
+ "" + ProtocolType.Udp.ToString().ToUpper(System.Globalization.CultureInfo.InvariantCulture) + "" +
+ "", "DeletePortMapping");
+ return true;
+ }
+ catch (Exception ex)
+ {
+ m_peer.LogWarning("UPnP delete forwarding rule failed: " + ex.Message);
+ return false;
+ }
+ }
+
+ ///
+ /// Retrieve the extern ip using UPnP
+ ///
+ public IPAddress GetExternalIP()
{
if (!CheckAvailability())
return null;