~kt/udprelay

95d81542d87afea6f41c4bd938088a9e65abf16c — Katie Wolfe 11 months ago ec10aef
Add -version flag
2 files changed, 17 insertions(+), 6 deletions(-)

M main.go
M udprelay.1.scd
M main.go => main.go +14 -6
@@ 13,19 13,19 @@ import (
var flagTimeout = flag.String("timeout", "10m", "duration to keep connections alive after their last packet")
var flagProtocol = flag.Bool("protocol", false, "enables the udprelay command protocol")

var flagVersion = flag.Bool("version", false, "print the version to stdout and exit immediately")

func main() {
	log.SetFlags(0)
	log.Printf("udprelay %s\n", Version)
	flag.Usage = func() {
		fmt.Fprintf(flag.CommandLine.Output(), "usage: %s [OPTION...] port\n\noptions:\n", os.Args[0])
		fmt.Fprintf(flag.CommandLine.Output(), "udprelay %s\nusage: %s [OPTION...] port\n\noptions:\n", Version, os.Args[0])
		flag.PrintDefaults()
	}
	flag.Parse()

	timeoutDuration, err := time.ParseDuration(*flagTimeout)
	if err != nil {
		log.Println("error: parsing -timeout: %s\n", err)
		os.Exit(2)
	if *flagVersion {
		fmt.Printf("udprelay %s\n", Version)
		os.Exit(0)
	}

	if flag.NArg() != 1 {


@@ 38,6 38,14 @@ func main() {
		os.Exit(2)
	}

	log.Printf("udprelay %s\n\n", Version)

	timeoutDuration, err := time.ParseDuration(*flagTimeout)
	if err != nil {
		log.Println("error: parsing -timeout: %s\n", err)
		os.Exit(2)
	}

	conn, err := net.ListenUDP("udp", &net.UDPAddr{Port: listenPort})
	if err != nil {
		panic(err)

M udprelay.1.scd => udprelay.1.scd +3 -0
@@ 22,6 22,9 @@ udprelay also features an optional command protocol that allows for more advance
*-timeout* _duration_
	Set the amount of time to leave connections open without receiving any packets from a peer. _duration_ is a sequence of decimal numbers with unit suffixes, such as *10m*, *120s*, and *5m48s*.

*-version*
	Prints the version of udprelay to stdout and exits with a code of 0.

# SEE ALSO

*udprelay*(7)