ParsePacket scans and retrieves the opened sockets from /proc/net/packet
()
| 27 | |
| 28 | // ParsePacket scans and retrieves the opened sockets from /proc/net/packet |
| 29 | func 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 | } |