Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update the guide #58

Open
mh-cbon opened this issue Feb 19, 2023 · 1 comment
Open

update the guide #58

mh-cbon opened this issue Feb 19, 2023 · 1 comment

Comments

@mh-cbon
Copy link
Contributor

mh-cbon commented Feb 19, 2023

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,
	)
@huin
Copy link
Owner

huin commented Feb 25, 2023

Yes, that seems reasonable. File a PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants