Skip to content

Commit

Permalink
netstat-nat: do not depend on lookup package
Browse files Browse the repository at this point in the history
  • Loading branch information
dominikh committed Nov 7, 2012
1 parent d51bef1 commit 82f2cf4
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions netstat-nat.go
@@ -1,8 +1,6 @@
package main

import (
"github.com/dominikh/simple-router/lookup"

"github.com/dominikh/conntrack"
"github.com/dominikh/netdb"

Expand Down Expand Up @@ -96,8 +94,8 @@ func main() {
}

for _, flow := range filteredFlows {
sHostname := lookup.Resolve(flow.Original.Source, *noResolve)
dHostname := lookup.Resolve(flow.Original.Destination, *noResolve)
sHostname := resolve(flow.Original.Source, *noResolve)
dHostname := resolve(flow.Original.Destination, *noResolve)
sPortName := portToName(int(flow.Original.SPort), flow.Protocol.Name)
dPortName := portToName(int(flow.Original.DPort), flow.Protocol.Name)
fmt.Fprintf(tabWriter, "%s\t%s:%s\t%s:%s\t%s\n",
Expand All @@ -120,3 +118,16 @@ func portToName(port int, protocol string) string {

return servent.Name
}

func resolve(ip net.IP, noop bool) string {
if noop {
return ip.String()
}

lookup, err := net.LookupAddr(ip.String())
if err == nil && len(lookup) > 0 {
return lookup[0]
}

return ip.String()
}

0 comments on commit 82f2cf4

Please sign in to comment.