-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparser_unix.go
More file actions
73 lines (60 loc) · 1.66 KB
/
parser_unix.go
File metadata and controls
73 lines (60 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package uss
import (
"fmt"
"strconv"
"strings"
)
// parseUnixEntry parses a UNIX socket line (u_str, u_dgr, u_seq)
func parseUnixEntry(line string, lineNum int) (Entry, error) {
fields := strings.Fields(line)
if len(fields) < 4 {
return Entry{}, fmt.Errorf("insufficient fields for UNIX entry (need at least 4, got %d)", len(fields))
}
entry := Entry{
Netid: fields[0],
UnixType: fields[0], // Mirror netid to unixType
State: fields[1],
}
// Parse RecvQ
recvQ, err := strconv.Atoi(fields[2])
if err != nil {
return Entry{}, fmt.Errorf("invalid RecvQ value %q: %w", fields[2], err)
}
entry.RecvQ = recvQ
// Parse SendQ
sendQ, err := strconv.Atoi(fields[3])
if err != nil {
return Entry{}, fmt.Errorf("invalid SendQ value %q: %w", fields[3], err)
}
entry.SendQ = sendQ
// Parse remaining UNIX-specific fields
// Format typically: Path ID Peer PeerID [Process...]
// But can be shorter, e.g., just: Path ID Peer PeerID
fieldIdx := 4
// Field 5: UnixPath (could be filesystem path, abstract socket @..., or *)
if fieldIdx < len(fields) {
entry.UnixPath = fields[fieldIdx]
fieldIdx++
}
// Field 6: UnixID (numeric identifier)
if fieldIdx < len(fields) {
entry.UnixID = fields[fieldIdx]
fieldIdx++
}
// Field 7: UnixPeer (often "*")
if fieldIdx < len(fields) {
entry.UnixPeer = fields[fieldIdx]
fieldIdx++
}
// Field 8: UnixPeerID (often "0")
if fieldIdx < len(fields) {
entry.UnixPeerID = fields[fieldIdx]
fieldIdx++
}
// Remaining fields are Process metadata
if fieldIdx < len(fields) {
entry.ProcessRaw = strings.Join(fields[fieldIdx:], " ")
extractProcessMetadata(&entry, entry.ProcessRaw)
}
return entry, nil
}