Skip to content

Commit

Permalink
Listen fix
Browse files Browse the repository at this point in the history
  • Loading branch information
vikulin committed Jun 19, 2024
1 parent 7a56904 commit 46ea27a
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions libmodule/src/go/mobile/hello.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,20 @@ func Greetings(name string) string {
} else {
s += fmt.Sprintf("%s \n", addrs)
}

_, err = net.Listen("tcp", fmt.Sprintf("%s:0", addrs))
if err != nil {
s += fmt.Sprintf("Listen error: %s", err) + "\n"
for _, addr := range addrs {
addrIP, _, _ := net.ParseCIDR(addr.String())
// Ignore IPv4 addresses
if addrIP.To4() != nil {
continue
}
// Ignore non-link-local addresses
if !addrIP.IsLinkLocalUnicast() {
continue
}
_, err = net.Listen("tcp", fmt.Sprintf("[%s]:0", addrIP))
if err != nil {
s += fmt.Sprintf("Listen error: %s", err) + "\n"
}
}
}
return fmt.Sprintf("Hello, %s!", s)
Expand Down

0 comments on commit 46ea27a

Please sign in to comment.