MCPcopy
hub / github.com/evilsocket/opensnitch / Parse

Function Parse

daemon/netstat/parse.go:84–119  ·  view source on GitHub ↗

Parse scans and retrieves the opened connections, from /proc/net/ files

(proto string)

Source from the content-addressed store, hash-verified

82
83// Parse scans and retrieves the opened connections, from /proc/net/ files
84func Parse(proto string) ([]Entry, error) {
85 filename := core.ConcatStrings("/proc/net/", proto)
86 fd, err := os.Open(filename)
87 if err != nil {
88 return nil, err
89 }
90 defer fd.Close()
91
92 entries := make([]Entry, 0)
93 scanner := bufio.NewScanner(fd)
94 for lineno := 0; scanner.Scan(); lineno++ {
95 // skip column names
96 if lineno == 0 {
97 continue
98 }
99
100 line := core.Trim(scanner.Text())
101 m := parser.FindStringSubmatch(line)
102 if m == nil {
103 log.Warning("Could not parse netstat line from %s: %s", filename, line)
104 continue
105 }
106
107 entries = append(entries, NewEntry(
108 proto,
109 hexToIP(m[1]),
110 hexToInt(m[2]),
111 hexToIP(m[3]),
112 hexToInt(m[4]),
113 decToInt(m[5]),
114 decToInt(m[6]),
115 ))
116 }
117
118 return entries, nil
119}

Callers 2

findEntryForProtocolFunction · 0.70
import_rulesMethod · 0.50

Calls 6

NewEntryFunction · 0.85
hexToIPFunction · 0.85
hexToIntFunction · 0.85
decToIntFunction · 0.85
CloseMethod · 0.65
OpenMethod · 0.45

Tested by

no test coverage detected