goupnp icon indicating copy to clipboard operation
goupnp copied to clipboard

update the guide

Open mh-cbon opened this issue 2 years ago • 1 comments

at https://github.com/huin/goupnp/blob/main/GUIDE.md

we can change the example to use the LocalAddr() method :D

type RouterClient interface {
	AddPortMapping(
		NewRemoteHost string,
		NewExternalPort uint16,
		NewProtocol string,
		NewInternalPort uint16,
		NewInternalClient string,
		NewEnabled bool,
		NewPortMappingDescription string,
		NewLeaseDuration uint32,
	) (err error)

	LocalAddr() net.IP

	GetExternalIPAddress() (
		NewExternalIPAddress string,
		err error,
	)
}

//....
	return client.AddPortMapping(
		"",
		// External port number to expose to Internet:
		1234,
		// Forward TCP (this could be "UDP" if we wanted that instead).
		"TCP",
		// Internal port number on the LAN to forward to.
		// Some routers might not support this being different to the external
		// port number.
		1234,
		// Internal address on the LAN we want to forward to.
		client.LocalAddr().String(),
		// Enabled:
		true,
		// Informational description for the client requesting the port forwarding.
		"MyProgramName",
		// How long should the port forward last for in seconds.
		// If you want to keep it open for longer and potentially across router
		// resets, you might want to periodically request before this elapses.
		3600,
	)

mh-cbon avatar Feb 19 '23 20:02 mh-cbon

Yes, that seems reasonable. File a PR?

huin avatar Feb 25 '23 09:02 huin