Skip to content

Commit

Permalink
p2p/nat: use IP.IsPrivate (ethereum#26252)
Browse files Browse the repository at this point in the history
  • Loading branch information
dbadoy authored Nov 25, 2022
1 parent 8c6e74e commit 53d1ae0
Showing 1 changed file with 1 addition and 8 deletions.
9 changes: 1 addition & 8 deletions p2p/nat/natpmp.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,6 @@ func discoverPMP() Interface {
return nil
}

var (
// LAN IP ranges
_, lan10, _ = net.ParseCIDR("10.0.0.0/8")
_, lan176, _ = net.ParseCIDR("172.16.0.0/12")
_, lan192, _ = net.ParseCIDR("192.168.0.0/16")
)

// TODO: improve this. We currently assume that (on most networks)
// the router is X.X.X.1 in a local LAN range.
func potentialGateways() (gws []net.IP) {
Expand All @@ -116,7 +109,7 @@ func potentialGateways() (gws []net.IP) {
}
for _, addr := range ifaddrs {
if x, ok := addr.(*net.IPNet); ok {
if lan10.Contains(x.IP) || lan176.Contains(x.IP) || lan192.Contains(x.IP) {
if x.IP.IsPrivate() {
ip := x.IP.Mask(x.Mask).To4()
if ip != nil {
ip[3] = ip[3] | 0x01
Expand Down

0 comments on commit 53d1ae0

Please sign in to comment.