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"
"net"
"net/url"
"strconv"
"strings"
"sync"
"time"
@@ -278,11 +279,16 @@ func (c *Client) Close() error {
func (c *Client) connect() error {
host := c.host
port := 0
if idx := strings.Index(host, ":"); idx > 0 {
if p, err := strconv.Atoi(host[idx+1:]); err == nil {
port = p
}
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 {
return fmt.Errorf("wyze: connect failed: %w", err)
}
+6 -2
View File
@@ -78,7 +78,7 @@ type Conn struct {
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)
if err != nil {
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())
psk := derivePSK(enr)
if port == 0 {
port = DefaultPort
}
c := &Conn{
conn: udp,
addr: &net.UDPAddr{IP: net.ParseIP(host), Port: DefaultPort},
addr: &net.UDPAddr{IP: net.ParseIP(host), Port: port},
rid: genRandomID(),
uid: uid,
authKey: authKey,