Support IGD v2 port mappings by GiovanniMenzano · Pull Request #367 · jupnp/jupnp · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Support IGD v2 port mappings
Handle newer gateways and routers that describe ports differently.
Added check for unset ports to avoid NPEs. Covered the IGD v2 hierarchy in tests.

Fixes #366

Signed-off-by: Giovanni Menzano <giovanni.menzano@gmail.com>
  • Loading branch information
GiovanniMenzano committed Jul 27, 2026
commit f3ec271343d4ec5eb0df338bdb530b24fad822bc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/
package org.jupnp.support.igd.callback;

import java.util.Objects;

import org.jupnp.controlpoint.ActionCallback;
import org.jupnp.controlpoint.ControlPoint;
import org.jupnp.model.action.ActionInvocation;
Expand All @@ -38,7 +40,7 @@ protected PortMappingDelete(Service<?, ?> service, ControlPoint controlPoint, Po

this.portMapping = portMapping;

getActionInvocation().setInput("NewExternalPort", portMapping.getExternalPort().toString());
getActionInvocation().setInput("NewExternalPort", Objects.toString(portMapping.getExternalPort(), null));
getActionInvocation().setInput("NewProtocol", portMapping.getProtocol());
if (portMapping.hasRemoteHost()) {
getActionInvocation().setInput("NewRemoteHost", portMapping.getRemoteHost());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,17 @@ class PortMappingListenerTest {

@Test
void discoversVersionTwoInternetGatewayDevice() throws Exception {
final RemoteService connectionService = new RemoteService(new UDAServiceType("WANIPConnection", 1),
final RemoteService connectionService = new RemoteService(new UDAServiceType("WANIPConnection", 2),
new UDAServiceId("WANIPConnection"), URI.create("service.xml"), URI.create("control"),
URI.create("events"));
final RemoteDevice connectionDevice = new RemoteDevice(identity("connection"),
new UDADeviceType("WANConnectionDevice", 1), new DeviceDetails("WAN connection"),
new UDADeviceType("WANConnectionDevice", 2), new DeviceDetails("WAN connection"),
new RemoteService[] { connectionService });
final RemoteDevice wanDevice = new RemoteDevice(identity("wan"), new UDADeviceType("WANDevice", 2),
new DeviceDetails("WAN device"), new RemoteService[0], new RemoteDevice[] { connectionDevice });
final RemoteDevice gateway = new RemoteDevice(identity("gateway"),
new UDADeviceType("InternetGatewayDevice", 2), new DeviceDetails("Internet gateway"),
new RemoteService[0], new RemoteDevice[] { connectionDevice });
new RemoteService[0], new RemoteDevice[] { wanDevice });

final Service<?, ?> discovered = new PortMappingListener(new PortMapping()).discoverConnectionService(gateway);

Expand Down
Loading