From d9e994bec8652904d6756a1ccfe737a1a0ecb56d Mon Sep 17 00:00:00 2001 From: WAKAYAMA shirou Date: Sat, 23 Apr 2016 23:10:23 +0900 Subject: [PATCH] [host]freebsd: update freebsd_amd64 --- host/host_freebsd.go | 6 ++---- host/host_freebsd_amd64.go | 9 ++++++--- host/types_freebsd.go | 1 + 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/host/host_freebsd.go b/host/host_freebsd.go index 06142e1..aeb1b45 100644 --- a/host/host_freebsd.go +++ b/host/host_freebsd.go @@ -101,13 +101,11 @@ func Users() ([]UserStat, error) { return ret, err } - u := Utmpx{} - entrySize := int(unsafe.Sizeof(u)) - 3 - entrySize = 197 // TODO: why should 197 + entrySize := sizeOfUtmpx count := len(buf) / entrySize for i := 0; i < count; i++ { - b := buf[i*entrySize : i*entrySize+entrySize] + b := buf[i*sizeOfUtmpx : (i+1)*sizeOfUtmpx] var u Utmpx br := bytes.NewReader(b) err := binary.Read(br, binary.LittleEndian, &u) diff --git a/host/host_freebsd_amd64.go b/host/host_freebsd_amd64.go index 9a4c0a4..3f015f0 100644 --- a/host/host_freebsd_amd64.go +++ b/host/host_freebsd_amd64.go @@ -9,6 +9,7 @@ const ( sizeofInt = 0x4 sizeofLong = 0x8 sizeofLongLong = 0x8 + sizeOfUtmpx = 197 // TODO: why should 197, not 0x118 ) type ( @@ -24,17 +25,19 @@ type Utmp struct { Host [16]int8 Time int32 } + type Utmpx struct { Type int16 Tv Timeval - ID [8]int8 + Id [8]int8 Pid int32 User [32]int8 Line [16]int8 Host [125]int8 - // Host [128]int8 - // X__ut_spare [64]int8 + // Host [128]int8 + // X__ut_spare [64]int8 } + type Timeval struct { Sec [4]byte Usec [3]byte diff --git a/host/types_freebsd.go b/host/types_freebsd.go index 113b22e..e70677f 100644 --- a/host/types_freebsd.go +++ b/host/types_freebsd.go @@ -27,6 +27,7 @@ const ( sizeofInt = C.sizeof_int sizeofLong = C.sizeof_long sizeofLongLong = C.sizeof_longlong + sizeOfUtmpx = C.sizeof_struct_utmpx ) // Basic types