mirror of
https://gitlab.com/NebulousLabs/go-upnp.git
synced 2025-10-05 23:16:49 +08:00
6
upnp.go
6
upnp.go
@@ -63,17 +63,23 @@ func (d *IGD) Forward(port uint16, desc string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
time.Sleep(time.Millisecond)
|
||||||
err = d.client.AddPortMapping("", port, "TCP", port, ip, true, desc, 0)
|
err = d.client.AddPortMapping("", port, "TCP", port, ip, true, desc, 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
time.Sleep(time.Millisecond)
|
||||||
return d.client.AddPortMapping("", port, "UDP", port, ip, true, desc, 0)
|
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.
|
// Clear un-forwards a port, removing it from the router's port mapping table.
|
||||||
func (d *IGD) Clear(port uint16) error {
|
func (d *IGD) Clear(port uint16) error {
|
||||||
|
time.Sleep(time.Millisecond)
|
||||||
tcpErr := d.client.DeletePortMapping("", port, "TCP")
|
tcpErr := d.client.DeletePortMapping("", port, "TCP")
|
||||||
|
time.Sleep(time.Millisecond)
|
||||||
udpErr := d.client.DeletePortMapping("", port, "UDP")
|
udpErr := d.client.DeletePortMapping("", port, "UDP")
|
||||||
|
|
||||||
// only return an error if both deletions failed
|
// only return an error if both deletions failed
|
||||||
if tcpErr != nil && udpErr != nil {
|
if tcpErr != nil && udpErr != nil {
|
||||||
return tcpErr
|
return tcpErr
|
||||||
|
@@ -71,6 +71,7 @@ func TestIGD(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
t.Log("Loc:", loc)
|
||||||
|
|
||||||
// connect to router directly
|
// connect to router directly
|
||||||
d, err = Load(loc)
|
d, err = Load(loc)
|
||||||
|
Reference in New Issue
Block a user