allow to specify custom port

This commit is contained in:
seydx
2026-01-14 19:11:53 +01:00
parent 3bf2b316d7
commit a99590823b
2 changed files with 13 additions and 3 deletions
+7 -1
View File
@@ -7,6 +7,7 @@ import (
"fmt" "fmt"
"net" "net"
"net/url" "net/url"
"strconv"
"strings" "strings"
"sync" "sync"
"time" "time"
@@ -278,11 +279,16 @@ func (c *Client) Close() error {
func (c *Client) connect() error { func (c *Client) connect() error {
host := c.host host := c.host
port := 0
if idx := strings.Index(host, ":"); idx > 0 { if idx := strings.Index(host, ":"); idx > 0 {
if p, err := strconv.Atoi(host[idx+1:]); err == nil {
port = p
}
host = host[:idx] host = host[:idx]
} }
conn, err := tutk.Dial(host, c.uid, c.authKey, c.enr, c.mac, c.verbose) conn, err := tutk.Dial(host, port, c.uid, c.authKey, c.enr, c.mac, c.verbose)
if err != nil { if err != nil {
return fmt.Errorf("wyze: connect failed: %w", err) return fmt.Errorf("wyze: connect failed: %w", err)
} }
+6 -2
View File
@@ -78,7 +78,7 @@ type Conn struct {
cmdAck func() cmdAck func()
} }
func Dial(host, uid, authKey, enr, mac string, verbose bool) (*Conn, error) { func Dial(host string, port int, uid, authKey, enr, mac string, verbose bool) (*Conn, error) {
udp, err := net.ListenUDP("udp", nil) udp, err := net.ListenUDP("udp", nil)
if err != nil { if err != nil {
return nil, err return nil, err
@@ -89,9 +89,13 @@ func Dial(host, uid, authKey, enr, mac string, verbose bool) (*Conn, error) {
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
psk := derivePSK(enr) psk := derivePSK(enr)
if port == 0 {
port = DefaultPort
}
c := &Conn{ c := &Conn{
conn: udp, conn: udp,
addr: &net.UDPAddr{IP: net.ParseIP(host), Port: DefaultPort}, addr: &net.UDPAddr{IP: net.ParseIP(host), Port: port},
rid: genRandomID(), rid: genRandomID(),
uid: uid, uid: uid,
authKey: authKey, authKey: authKey,