Skip to content

Commit

Permalink
Reworked set-listener to use netip.AddrPort
Browse files Browse the repository at this point in the history
  • Loading branch information
twystd committed May 27, 2024
1 parent 1e80e5a commit 6434bb4
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 22 deletions.
29 changes: 13 additions & 16 deletions commands/set_listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"errors"
"flag"
"fmt"
"net"
"net/netip"
)

var SetListenerCmd = SetListener{}
Expand All @@ -13,31 +13,28 @@ type SetListener struct {
}

func (c *SetListener) Execute(ctx Context) error {
serialNumber, err := getSerialNumber(ctx)
controller, err := getSerialNumber(ctx)
if err != nil {
return err
}

if len(flag.Args()) < 3 {
return errors.New("missing IP address")
return errors.New("missing IPv4 address:port")
}

address, err := net.ResolveUDPAddr("udp", flag.Arg(2))
if err != nil {
if addr, err := netip.ParseAddrPort(flag.Arg(2)); err != nil {
return err
}

if address == nil || address.IP.To4() == nil {
return fmt.Errorf("invalid UDP address: %v", flag.Arg(2))
}

listener, err := ctx.uhppote.SetListener(serialNumber, *address)
} else if !addr.IsValid() {
return fmt.Errorf("invalid IPv4 address:port (%v)", flag.Arg(2))
} else if ok, err := ctx.uhppote.SetListener(controller, addr); err != nil {
return err
} else if !ok {
return fmt.Errorf("failed to set listener")
} else {
fmt.Printf("%-10v %v\n", controller, addr)

if err == nil {
fmt.Printf("%v\n", listener)
return nil
}

return err
}

func (c *SetListener) CLI() string {
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ module github.com/uhppoted/uhppote-cli
go 1.22

require (
github.com/uhppoted/uhppote-core v0.8.9-0.20240524165731-f11a293bdd8d
github.com/uhppoted/uhppoted-lib v0.8.9-0.20240524171653-86bb80223c95
github.com/uhppoted/uhppote-core v0.8.9-0.20240527172601-d5317b598bb8
github.com/uhppoted/uhppoted-lib v0.8.9-0.20240527174018-4ff1fd4a0224
)

require golang.org/x/sys v0.20.0 // indirect
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
github.com/uhppoted/uhppote-core v0.8.9-0.20240524165731-f11a293bdd8d h1:3i+zWCiQpGN0SXlDHDG2RzBsW1/vzL1sO39gmKbyv88=
github.com/uhppoted/uhppote-core v0.8.9-0.20240524165731-f11a293bdd8d/go.mod h1:Q+DHtT8s74efLs2b0eF20DRBUL9yBkySwaTQ+0lsEVM=
github.com/uhppoted/uhppoted-lib v0.8.9-0.20240524171653-86bb80223c95 h1:XRdwZQUNT0r3zzwjUNOmbsC7Cqc8o0CGXFOztpqMWHQ=
github.com/uhppoted/uhppoted-lib v0.8.9-0.20240524171653-86bb80223c95/go.mod h1:X60HhO4iKqIw+J+r0Rh4OkAzpMbhLzo+7QELXKDQowM=
github.com/uhppoted/uhppote-core v0.8.9-0.20240527172601-d5317b598bb8 h1:54HfgoJgeDfMDJW2cKF/QDy38dh1qKxv9SMTxVlVOVk=
github.com/uhppoted/uhppote-core v0.8.9-0.20240527172601-d5317b598bb8/go.mod h1:Q+DHtT8s74efLs2b0eF20DRBUL9yBkySwaTQ+0lsEVM=
github.com/uhppoted/uhppoted-lib v0.8.9-0.20240527174018-4ff1fd4a0224 h1:DYkZ77CR3eVcfTatc9JLSPyVQEcOviJbA2lysPjbVSI=
github.com/uhppoted/uhppoted-lib v0.8.9-0.20240527174018-4ff1fd4a0224/go.mod h1:3CvWWsUiXmFh4jTzF+NXeWTMeaHiqkIDLOxoKQ0iJd8=
golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y=
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=

0 comments on commit 6434bb4

Please sign in to comment.