Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ParseName ¶
ParseName parses `lsof`'s name field, which by default is in the form: [46][protocol][@hostname|hostaddr][:service|port] but we're disabling hostname conversion with the “-n” option and port conversion with the “-P” option, so the output in printed in the more decodable format: “addr:port->addr:port”.
Types ¶
type OpenFile ¶
type OpenFile struct { Raw string Command string Pid int User string Fd string Type string Device string State string // (ENSTABLISHED), (LISTEN), ... SrcAddr net.Addr // Source address DstAddr net.Addr // Destination address }
func ParseOpenFile ¶
ParseOpenFile expectes "line" to be a single line output from “lsof -i -n -P” call. The line is unmarshaled into an “OpenFile” only if is splittable by " " into a slice of at least 9 items. "line" should not end with a "\n" delimitator, otherwise it will end up in the last unmarshaled item.
"line" examples: "postgres 676 danielmorandini 10u IPv6 0x25c5bf0997ca88e3 0t0 UDP [::1]:60051->[::1]:60051" "Dropbox 614 danielmorandini 247u IPv4 0x25c5bf09a393d583 0t0 TCP 192.168.0.61:58282->162.125.18.133:https (ESTABLISHED)"
func ParseOutput ¶
ParseOutput expects "r" to contain the output of an “lsof -i -n -P” call. The output is splitted into each new line, and each line that “ParseOpenFile” is able to parse is appended to the final output. Returns an error only if reading from "r" produces an error different from “io.EOF”.