Skip to content

Commit

Permalink
fix panic error check when internal adapter is unreachable.
Browse files Browse the repository at this point in the history
  • Loading branch information
iqhater committed Oct 27, 2024
1 parent d2539a2 commit 0ccaa27
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
8 changes: 7 additions & 1 deletion data/internal.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package data

import (
"errors"
"net"
"strings"
)
Expand All @@ -15,7 +16,12 @@ type InternalData struct {
func (i *InternalData) GetInternalIP() {

conn, err := net.Dial("udp", "8.8.8.8:80")
checkErr(err)

defer func() {
if r := recover(); r != nil {
checkErr(errors.Join(err, r.(error)))
}
}()
defer conn.Close()

localAddr := conn.LocalAddr().(*net.UDPAddr)
Expand Down
2 changes: 1 addition & 1 deletion data/internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func TestGetInternalIP(t *testing.T) {

// assert
if result == "" {
t.Errorf("Wrong internal IP address! Shoud be fromat like this XX.XX.XX.XX %s\n", result)
t.Errorf("Wrong internal IP address! Shoud be format like this XX.XX.XX.XX %s\n", result)
}
}

Expand Down

0 comments on commit 0ccaa27

Please sign in to comment.