Merge pull request #614 from skrashevich/230905-fix-runtime-crash

Refactor LocalIP method to correctly handle non-TCP connections
This commit is contained in:
Alex X
2023-09-09 17:37:52 +03:00
committed by GitHub
+9 -2
View File
@@ -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 {