Skip to content

Instantly share code, notes, and snippets.

@Tasssadar
Created Feb 26, 2020
Embed
What would you like to do?
AMD64 linux only
package main
import (
"fmt"
"os"
"os/exec"
"syscall"
"unsafe"
)
const __NEW_UTS_LEN = 64
type new_utsname struct {
sysname [__NEW_UTS_LEN + 1]byte
nodename [__NEW_UTS_LEN + 1]byte
release [__NEW_UTS_LEN + 1]byte
version [__NEW_UTS_LEN + 1]byte
machine [__NEW_UTS_LEN + 1]byte
domainname [__NEW_UTS_LEN + 1]byte
}
func main() {
fmt.Println("real uname")
cmd := exec.Command("uname", "-a")
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.Run()
fmt.Println("\nour uname")
var uts new_utsname
syscall.Syscall(63, uintptr(unsafe.Pointer(&uts)), 0, 0)
fmt.Println("sysname", string(uts.sysname[:]))
fmt.Println("nodename", string(uts.nodename[:]))
fmt.Println("release", string(uts.release[:]))
fmt.Println("version", string(uts.version[:]))
fmt.Println("machine", string(uts.machine[:]))
fmt.Println("domainname", string(uts.domainname[:]))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment