MCPcopy
hub / github.com/perkeep/perkeep / uidFromSockstatReader

Function uidFromSockstatReader

internal/netutil/ident.go:220–240  ·  view source on GitHub ↗
(lip net.IP, lport int, rip net.IP, rport int, r io.Reader)

Source from the content-addressed store, hash-verified

218}
219
220func uidFromSockstatReader(lip net.IP, lport int, rip net.IP, rport int, r io.Reader) (uid int, err error) {
221 pat, err := regexp.Compile(fmt.Sprintf(`^([^ ]+).*%s:%d *%s:%d$`,
222 lip.String(), lport, rip.String(), rport))
223 if err != nil {
224 return 0, err
225 }
226 scanner := bufio.NewScanner(r)
227 for scanner.Scan() {
228 l := scanner.Text()
229 m := pat.FindStringSubmatch(l)
230 if len(m) == 2 {
231 return uidFromUsername(m[1])
232 }
233 }
234
235 if err := scanner.Err(); err != nil {
236 return 0, err
237 }
238
239 return 0, ErrNotFound
240}
241
242func uidFromProcReader(lip net.IP, lport int, rip net.IP, rport int, r io.Reader) (uid int, err error) {
243 buf := bufio.NewReader(r)

Callers 2

TestParseFreeBSDSockstatFunction · 0.85
uidFromSockstatFunction · 0.85

Calls 3

TextMethod · 0.65
StringMethod · 0.45
ErrMethod · 0.45

Tested by 1

TestParseFreeBSDSockstatFunction · 0.68