add ForwardTCP and ForwardUDP funcs

This commit is contained in:
Nate
2021-10-02 19:35:47 +09:00
parent 67b91c9a5c
commit bc58fa18f4

24
upnp.go
View File

@@ -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)