From bc58fa18f492af05d34857e7832cb15df4ee767a Mon Sep 17 00:00:00 2001 From: Nate Date: Sat, 2 Oct 2021 19:35:47 +0900 Subject: [PATCH] add ForwardTCP and ForwardUDP funcs --- upnp.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/upnp.go b/upnp.go index 5d238e3..5f10d32 100644 --- a/upnp.go +++ b/upnp.go @@ -101,6 +101,30 @@ func (d *IGD) Forward(port uint16, desc string) error { return d.client.AddPortMapping("", port, "UDP", port, ip, true, desc, 0) } +// ForwardTCP forwards the specified TCP port, and adds its description to the +// router's port mapping table. +func (d *IGD) ForwardTCP(port uint16, desc string) error { + ip, err := d.getInternalIP() + if err != nil { + return err + } + + time.Sleep(time.Millisecond) + return d.client.AddPortMapping("", port, "TCP", port, ip, true, desc, 0) +} + +// ForwardUDP forwards the specified UDP port, and adds its description to the +// router's port mapping table. +func (d *IGD) ForwardUDP(port uint16, desc string) error { + ip, err := d.getInternalIP() + if err != nil { + return err + } + + time.Sleep(time.Millisecond) + return d.client.AddPortMapping("", port, "UDP", port, ip, true, desc, 0) +} + // Clear un-forwards a port, removing it from the router's port mapping table. func (d *IGD) Clear(port uint16) error { time.Sleep(time.Millisecond)