-
Notifications
You must be signed in to change notification settings - Fork 42
/
connections.go
76 lines (69 loc) · 1.96 KB
/
connections.go
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
74
75
76
package hidsevent
type ConnectionStat struct {
Fd uint32 `json:"fd"`
Family string `json:"family"`
Type string `json:"type"`
Laddr string `json:"localaddr"`
Raddr string `json:"remoteaddr"`
Status string `json:"status"`
Uids []int32 `json:"uids"`
Pid int32 `json:"pid"`
//ProcessName string
}
type ConnectionInfo struct {
Count int
EstablishedConns []*ConnectionStat `json:"established_conns"`
ListenedConns []*ConnectionStat `json:"listened_conns"`
ExtraConns []*ConnectionStat `json:"extra_conns"`
}
type ConnectionEventType string
const (
ConnectionEventType_New ConnectionEventType = "new"
ConnectionEventType_Disappear ConnectionEventType = "disappear"
)
type ConnectionEvent struct {
EventName ConnectionEventType `json:"event_name"`
Connection *ConnectionStat
}
//func GetNetConnectStatusInfo(c context.Context) (*ConnectionInfo, error) {
// //var cachePname = map[int32]string{}
//
// i := &ConnectionInfo{}
//
// connStat, err := net.ConnectionsWithContext(c, "tcp")
// if err != nil {
// return nil, errors.Errorf("get conns info failed: %v", err)
// }
//
// // only report data filter on server
// for _, statOrigin := range connStat {
// //var procName string
// //var ok bool
// //if procName, ok = cachePname[statOrigin.Pid]; !ok {
// // if proc, err := process.NewProcess(statOrigin.Pid); err != nil {
// // procName = ""
// // } else {
// // procName, _ = proc.Name()
// // cachePname[statOrigin.Pid] = procName
// // }
// //}
//
// stat := &ConnectionStat{
// ConnectionStat: statOrigin,
// //ProcessName: procName,
// }
//
// switch strings.ToUpper(stat.Status) {
// case "ESTABLISHED":
// i.EstablishedConns = append(i.EstablishedConns, stat)
// i.Count = i.Count + 1
// case "LISTEN":
// i.ListenedConns = append(i.ListenedConns, stat)
// i.Count = i.Count + 1
// default:
// i.ExtraConns = append(i.ExtraConns, stat)
// i.Count = i.Count + 1
// }
// }
// return i, nil
//}