Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upnp: Don't return loopback IPs in getOurIP. #2566

Merged
merged 1 commit into from Jan 22, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions upnp.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ import (
"fmt"
"net"
"net/http"
"os"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -200,11 +199,14 @@ func getChildService(d *device, serviceType string) *service {

// getOurIP returns a best guess at what the local IP is.
func getOurIP() (ip string, err error) {
hostname, err := os.Hostname()
if err != nil {
return
addrs, err := net.InterfaceAddrs()
for _, addr := range addrs {
ip, _, _ := net.ParseCIDR(addr.String())
if !ip.IsLoopback() {
return ip.String(), nil
}
}
return net.LookupCNAME(hostname)
return
}

// getServiceURL parses the xml description at the given root url to find the
Expand Down