Source File
net_unix.go
Belonging Package
github.com/prometheus/procfs
package procfs
import (
)
netUnixStaticFieldsCnt = 6
)
const (
netUnixTypeStream = 1
netUnixTypeDgram = 2
netUnixTypeSeqpacket = 5
netUnixFlagListen = 1 << 16
netUnixStateUnconnected = 1
netUnixStateConnecting = 2
netUnixStateConnected = 3
netUnixStateDisconnected = 4
)
var errInvalidKernelPtrFmt = errors.New("Invalid Num(the kernel table slot number) format")
type NetUnixType uint64
type NetUnixFlags uint64
type NetUnixState uint64
type NetUnixLine struct {
KernelPtr string
RefCount uint64
Protocol uint64
Flags NetUnixFlags
Type NetUnixType
State NetUnixState
Inode uint64
Path string
}
type NetUnix struct {
Rows []*NetUnixLine
}
func () (*NetUnix, error) {
, := NewFS(DefaultMountPoint)
if != nil {
return nil,
}
return .NewNetUnix()
}
.Scan()
:= strings.Contains(, "Inode")
:= netUnixStaticFieldsCnt
if {
++
}
for .Scan() {
:= .Text()
, := .parseLine(, , )
if != nil {
return ,
}
.Rows = append(.Rows, )
}
return , .Err()
}
func ( *NetUnix) ( string, bool, int) (*NetUnixLine, error) {
:= strings.Fields()
:= len()
if < {
return nil, fmt.Errorf(
"Parse Unix domain failed: expect at least %d fields but got %d",
, )
}
, := .parseKernelPtr([netUnixKernelPtrIdx])
if != nil {
return nil, fmt.Errorf("Parse Unix domain num(%s) failed: %s", [netUnixKernelPtrIdx], )
}
, := .parseUsers([netUnixRefCountIdx])
if != nil {
return nil, fmt.Errorf("Parse Unix domain ref count(%s) failed: %s", [netUnixRefCountIdx], )
}
, := .parseFlags([netUnixFlagsIdx])
if != nil {
return nil, fmt.Errorf("Parse Unix domain flags(%s) failed: %s", [netUnixFlagsIdx], )
}
, := .parseType([netUnixTypeIdx])
if != nil {
return nil, fmt.Errorf("Parse Unix domain type(%s) failed: %s", [netUnixTypeIdx], )
}
, := .parseState([netUnixStateIdx])
if != nil {
return nil, fmt.Errorf("Parse Unix domain state(%s) failed: %s", [netUnixStateIdx], )
}
var uint64
if {
:= [netUnixInodeIdx]
, = .parseInode()
if != nil {
return nil, fmt.Errorf("Parse Unix domain inode(%s) failed: %s", , )
}
}
:= &NetUnixLine{
KernelPtr: ,
RefCount: ,
Type: ,
Flags: ,
State: ,
Inode: ,
}
if > {
:= netUnixInodeIdx + 1
if ! {
--
}
.Path = []
}
return , nil
}
func ( NetUnix) ( string) (string, error) {
if !strings.HasSuffix(, ":") {
return "", errInvalidKernelPtrFmt
}
return [:len()-1], nil
}
func ( NetUnix) ( string) (uint64, error) {
return strconv.ParseUint(, 16, 32)
}
func ( NetUnix) ( string) (NetUnixType, error) {
, := strconv.ParseUint(, 16, 16)
if != nil {
return 0,
}
return NetUnixType(), nil
}
func ( NetUnix) ( string) (NetUnixFlags, error) {
, := strconv.ParseUint(, 16, 32)
if != nil {
return 0,
}
return NetUnixFlags(), nil
}
func ( NetUnix) ( string) (NetUnixState, error) {
, := strconv.ParseInt(, 16, 8)
if != nil {
return 0,
}
return NetUnixState(), nil
}
func ( NetUnix) ( string) (uint64, error) {
return strconv.ParseUint(, 10, 64)
}
func ( NetUnixType) () string {
switch {
case netUnixTypeStream:
return "stream"
case netUnixTypeDgram:
return "dgram"
case netUnixTypeSeqpacket:
return "seqpacket"
}
return "unknown"
}
func ( NetUnixFlags) () string {
switch {
case netUnixFlagListen:
return "listen"
default:
return "default"
}
}
func ( NetUnixState) () string {
switch {
case netUnixStateUnconnected:
return "unconnected"
case netUnixStateConnecting:
return "connecting"
case netUnixStateConnected:
return "connected"
case netUnixStateDisconnected:
return "disconnected"
}
return "unknown"
![]() |
The pages are generated with Golds v0.3.2-preview. (GOOS=darwin GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |