Skip to content

Commit

Permalink
Merge pull request #614 from skrashevich/230905-fix-runtime-crash
Browse files Browse the repository at this point in the history
Refactor LocalIP method to correctly handle non-TCP connections
  • Loading branch information
AlexxIT authored Sep 9, 2023
2 parents 1243981 + 541a7b2 commit 452d757
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions pkg/hap/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 452d757

Please sign in to comment.