parseWireless parses the contents of /proc/net/wireless. * Inter-| sta-| Quality | Discarded packets | Missed | WE face | tus | link level noise | nwid crypt frag retry misc | beacon | 22 eth1: 0000 5. -256. -10. 0 1 0 3 0 0 eth2
(r io.Reader)
| 82 | eth2: 0000 5. -256. -20. 0 2 0 4 0 0 |
| 83 | */ |
| 84 | func parseWireless(r io.Reader) ([]*Wireless, error) { |
| 85 | var ( |
| 86 | interfaces []*Wireless |
| 87 | scanner = bufio.NewScanner(r) |
| 88 | ) |
| 89 | |
| 90 | for n := 0; scanner.Scan(); n++ { |
| 91 | // Skip the 2 header lines. |
| 92 | if n < 2 { |
| 93 | continue |
| 94 | } |
| 95 | |
| 96 | line := scanner.Text() |
| 97 | |
| 98 | parts := strings.Split(line, ":") |
| 99 | if len(parts) != 2 { |
| 100 | return nil, fmt.Errorf("%w: expected 2 parts after splitting line by ':', got %d for line %q", ErrFileParse, len(parts), line) |
| 101 | } |
| 102 | |
| 103 | name := strings.TrimSpace(parts[0]) |
| 104 | stats := strings.Fields(parts[1]) |
| 105 | |
| 106 | if len(stats) < 10 { |
| 107 | return nil, fmt.Errorf("%w: invalid number of fields in line %d, expected 10+, got %d: %q", ErrFileParse, n, len(stats), line) |
| 108 | } |
| 109 | |
| 110 | status, err := strconv.ParseUint(stats[0], 16, 16) |
| 111 | if err != nil { |
| 112 | return nil, fmt.Errorf("%w: invalid status in line %d: %q", ErrFileParse, n, line) |
| 113 | } |
| 114 | |
| 115 | qlink, err := strconv.Atoi(strings.TrimSuffix(stats[1], ".")) |
| 116 | if err != nil { |
| 117 | return nil, fmt.Errorf("%w: parse Quality:link as integer %q: %w", ErrFileParse, stats[1], err) |
| 118 | } |
| 119 | |
| 120 | qlevel, err := strconv.Atoi(strings.TrimSuffix(stats[2], ".")) |
| 121 | if err != nil { |
| 122 | return nil, fmt.Errorf("%w: Quality:level as integer %q: %w", ErrFileParse, stats[2], err) |
| 123 | } |
| 124 | |
| 125 | qnoise, err := strconv.Atoi(strings.TrimSuffix(stats[3], ".")) |
| 126 | if err != nil { |
| 127 | return nil, fmt.Errorf("%w: Quality:noise as integer %q: %w", ErrFileParse, stats[3], err) |
| 128 | } |
| 129 | |
| 130 | dnwid, err := strconv.Atoi(stats[4]) |
| 131 | if err != nil { |
| 132 | return nil, fmt.Errorf("%w: Discarded:nwid as integer %q: %w", ErrFileParse, stats[4], err) |
| 133 | } |
| 134 | |
| 135 | dcrypt, err := strconv.Atoi(stats[5]) |
| 136 | if err != nil { |
| 137 | return nil, fmt.Errorf("%w: Discarded:crypt as integer %q: %w", ErrFileParse, stats[5], err) |
| 138 | } |
| 139 | |
| 140 | dfrag, err := strconv.Atoi(stats[6]) |
| 141 | if err != nil { |