-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathudp.go
43 lines (37 loc) · 1.25 KB
/
udp.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
package ss
import (
"syscall"
"github.com/Asphaltt/go-iproute2"
)
// ListUdp4Conns retrieves all Udp sockets from kernel.
func (c *Client) ListUdp4Sockets() ([]*Entry, error) {
var req iproute2.InetDiagReq
req.Family = syscall.AF_INET
req.Protocol = syscall.IPPROTO_UDP
req.States = uint32(1 << iproute2.Established)
return c.listSockets(&req)
}
// ListUdp6Conns retrieves all Udp sockets from kernel.
func (c *Client) ListUdp6Sockets() ([]*Entry, error) {
var req iproute2.InetDiagReq
req.Family = syscall.AF_INET6
req.Protocol = syscall.IPPROTO_UDP
req.States = uint32(1 << iproute2.Established)
return c.listSockets(&req)
}
// ListUdp4Listeners retreives all IPv4 Udp listeners from kernel.
func (c *Client) ListUdp4Listeners() ([]*Entry, error) {
var req iproute2.InetDiagReq
req.Family = syscall.AF_INET
req.Protocol = syscall.IPPROTO_UDP
req.States = uint32((1 << iproute2.Listen) | (1 << iproute2.Close))
return c.listSockets(&req)
}
// ListUdp6Listeners retreives all IPv6 Udp listeners from kernel.
func (c *Client) ListUdp6Listeners() ([]*Entry, error) {
var req iproute2.InetDiagReq
req.Family = syscall.AF_INET6
req.Protocol = syscall.IPPROTO_UDP
req.States = uint32((1 << iproute2.Listen) | (1 << iproute2.Close))
return c.listSockets(&req)
}