From 541a7b28a77b62edf365387f0a877eda9eca98ac Mon Sep 17 00:00:00 2001 From: Sergey Krashevich Date: Tue, 5 Sep 2023 10:27:12 +0300 Subject: [PATCH] Refactor LocalIP method to correctly handle non-TCP connections --- pkg/hap/client.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/pkg/hap/client.go b/pkg/hap/client.go index 0c7c3b11..3b882588 100644 --- a/pkg/hap/client.go +++ b/pkg/hap/client.go @@ -317,8 +317,15 @@ func (c *Client) GetImage(width, height int) ([]byte, error) { } func (c *Client) LocalIP() string { - addr := c.Conn.LocalAddr().(*net.TCPAddr) - return addr.IP.To4().String() + conn, ok := c.Conn.(*net.TCPConn) + if !ok { + return "" + } + addr, ok := conn.LocalAddr().(*net.TCPAddr) + if !ok { + return "" + } + return addr.IP.String() } func DecodeKey(s string) []byte {