diff --git a/host/host_freebsd_amd64.go b/host/host_freebsd_amd64.go index e37eaa4..7706cbd 100644 --- a/host/host_freebsd_amd64.go +++ b/host/host_freebsd_amd64.go @@ -6,23 +6,23 @@ package host const ( - sizeofPtr = 0x8 - sizeofShort = 0x2 - sizeofInt = 0x4 - sizeofLong = 0x8 - sizeofLongLong = 0x8 + sizeofPtr = 0x8 + sizeofShort = 0x2 + sizeofInt = 0x4 + sizeofLong = 0x8 + sizeofLongLong = 0x8 ) type ( - _C_short int16 - _C_int int32 - _C_long int64 - _C_long_long int64 + _C_short int16 + _C_int int32 + _C_long int64 + _C_long_long int64 ) type Utmp struct { - Line [8]int8 - Name [16]int8 - Host [16]int8 - Time int32 + Line [8]int8 + Name [16]int8 + Host [16]int8 + Time int32 } diff --git a/host/host_linux.go b/host/host_linux.go index 4964b92..1a69269 100644 --- a/host/host_linux.go +++ b/host/host_linux.go @@ -91,10 +91,10 @@ func Users() ([]UserStat, error) { continue } user := UserStat{ - User: common.ByteToString(u.UtUser[:]), - Terminal: common.ByteToString(u.UtLine[:]), - Host: common.ByteToString(u.UtHost[:]), - Started: int(u.UtTv.TvSec), + User: common.IntToString(u.User[:]), + Terminal: common.IntToString(u.Line[:]), + Host: common.IntToString(u.Host[:]), + Started: int(u.Tv.TvSec), } ret = append(ret, user) } diff --git a/host/host_linux_amd64.go b/host/host_linux_amd64.go index bdd1600..b04fc17 100644 --- a/host/host_linux_amd64.go +++ b/host/host_linux_amd64.go @@ -1,27 +1,42 @@ -// +build linux -// +build amd64 +// Created by cgo -godefs - DO NOT EDIT +// cgo -godefs types_linux.go package host -type exitStatus struct { - Etermination int16 // Process termination status. - Eexit int16 // Process exit status. -} -type timeval struct { - TvSec uint32 // Seconds. - TvUsec uint32 // Microseconds. -} +const ( + sizeofPtr = 0x8 + sizeofShort = 0x2 + sizeofInt = 0x4 + sizeofLong = 0x8 + sizeofLongLong = 0x8 +) + +type ( + _C_short int16 + _C_int int32 + _C_long int64 + _C_long_long int64 +) type utmp struct { - UtType int16 // Type of login. - UtPid int32 // Process ID of login process. - UtLine [32]byte // Devicename. - UtID [4]byte // Inittab ID. - UtUser [32]byte // Username. - UtHost [256]byte // Hostname for remote login. - UtExit exitStatus // Exit status of a process marked - UtSession int32 // Session ID, used for windowing. - UtTv timeval // Time entry was made. - UtAddrV6 [16]byte // Internet address of remote host. - Unused [20]byte // Reserved for future use. // original is 20 + Type int16 + Pad_cgo_0 [2]byte + Pid int32 + Line [32]int8 + Id [4]int8 + User [32]int8 + Host [256]int8 + Exit exit_status + Session int32 + Tv UtTv + Addr_v6 [4]int32 + X__glibc_reserved [20]int8 +} +type exit_status struct { + Termination int16 + Exit int16 +} +type UtTv struct { + TvSec int32 + TvUsec int32 } diff --git a/host/host_linux_arm.go b/host/host_linux_arm.go index b737d96..d4455ea 100644 --- a/host/host_linux_arm.go +++ b/host/host_linux_arm.go @@ -13,15 +13,15 @@ type timeval struct { } type utmp struct { - UtType int16 // Type of login. - UtPid int32 // Process ID of login process. - UtLine [32]byte // Devicename. - UtID [4]byte // Inittab ID. - UtUser [32]byte // Username. - UtHost [256]byte // Hostname for remote login. - UtExit exitStatus // Exit status of a process marked - UtSession int32 // Session ID, used for windowing. - UtTv timeval // Time entry was made. - UtAddrV6 [16]byte // Internet address of remote host. - Unused [20]byte // Reserved for future use. // original is 20 + Type int16 // Type of login. + Pid int32 // Process ID of login process. + Line [32]byte // Devicename. + ID [4]byte // Inittab ID. + User [32]byte // Username. + Host [256]byte // Hostname for remote login. + Exit exitStatus // Exit status of a process marked + Session int32 // Session ID, used for windowing. + Tv timeval // Time entry was made. + AddrV6 [16]byte // Internet address of remote host. + Unused [20]byte // Reserved for future use. // original is 20 } diff --git a/host/types_linux.go b/host/types_linux.go new file mode 100644 index 0000000..9285455 --- /dev/null +++ b/host/types_linux.go @@ -0,0 +1,45 @@ +// +build ignore + +/* +Input to cgo -godefs. +*/ + +package host + +/* +#define KERNEL +#include +#include + +enum { + sizeofPtr = sizeof(void*), +}; + +*/ +import "C" + +// Machine characteristics; for internal use. + +const ( + sizeofPtr = C.sizeofPtr + sizeofShort = C.sizeof_short + sizeofInt = C.sizeof_int + sizeofLong = C.sizeof_long + sizeofLongLong = C.sizeof_longlong +) + +// Basic types + +type ( + _C_short C.short + _C_int C.int + _C_long C.long + _C_long_long C.longlong +) + +type utmp C.struct_utmp +type exit_status C.struct_exit_status +type UtTv struct { + TvSec int32 + TvUsec int32 +}