mirror of
https://gitlab.com/NebulousLabs/go-upnp.git
synced 2025-10-03 14:16:25 +08:00
add ForwardTCP and ForwardUDP funcs
This commit is contained in:
24
upnp.go
24
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)
|
||||
|
Reference in New Issue
Block a user