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

Function ParsePacket

daemon/netstat/parse_packet.go:29–61  ·  view source on GitHub ↗

ParsePacket scans and retrieves the opened sockets from /proc/net/packet

()

Source from the content-addressed store, hash-verified

27
28// ParsePacket scans and retrieves the opened sockets from /proc/net/packet
29func ParsePacket() ([]Entry, error) {
30 filename := core.ConcatStrings("/proc/net/packet")
31 fd, err := os.Open(filename)
32 if err != nil {
33 return nil, err
34 }
35 defer fd.Close()
36
37 entries := make([]Entry, 0)
38 scanner := bufio.NewScanner(fd)
39 for lineno := 0; scanner.Scan(); lineno++ {
40 // skip column names
41 if lineno == 0 {
42 continue
43 }
44
45 line := core.Trim(scanner.Text())
46 m := packetParser.FindStringSubmatch(line)
47 if m == nil {
48 log.Warning("Could not parse netstat line from %s: %s", filename, line)
49 continue
50 }
51 // TODO: get proto, type, etc.
52 en := Entry{}
53 en.Iface = decToInt(m[3])
54 en.UserId = decToInt(m[4])
55 en.INode = decToInt(m[5])
56
57 entries = append(entries, en)
58 }
59
60 return entries, nil
61}

Callers

nothing calls this directly

Calls 3

decToIntFunction · 0.85
CloseMethod · 0.65
OpenMethod · 0.45

Tested by

no test coverage detected