diff --git a/network/lan_endpoint.go b/network/lan_endpoint.go index ba5de81a..5d3638cc 100644 --- a/network/lan_endpoint.go +++ b/network/lan_endpoint.go @@ -154,3 +154,20 @@ func (t *Endpoint) String() string { } return fmt.Sprintf("%s%s ( %s ) - %s", ipPart, t.HwAddress, t.Vendor, core.Bold(t.Hostname)) } + +func (t *Endpoint) OnMeta(meta map[string]string) { + host := "" + for k, v := range meta { + // simple heuristics to get the longest candidate name + if strings.HasSuffix(k, ":hostname") && len(v) > len(host) { + host = v + } else if k == "mdns:md" && len(v) > len(host) { + host = v + } + t.Meta.Set(k, v) + } + + if t.Hostname == "" { + t.Hostname = host + } +} diff --git a/session/session_setup.go b/session/session_setup.go index 3a13ee32..9cfc2838 100644 --- a/session/session_setup.go +++ b/session/session_setup.go @@ -95,12 +95,7 @@ func (s *Session) startNetMon() { } if existing != nil && event.Meta != nil { - for k, v := range event.Meta { - if strings.HasSuffix(k, ":hostname") && existing.Hostname == "" { - existing.Hostname = v - } - existing.Meta.Set(k, v) - } + existing.OnMeta(event.Meta) } } }