aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/version/os_windows.go
blob: 81147ea500e8e5aacb0d250be7fdc7b3e49cc74c (plain) (blame)
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
44
45
46
47
48
/* SPDX-License-Identifier: MIT
 *
 * Copyright (C) 2019 WireGuard LLC. All Rights Reserved.
 */

package version

import (
	"fmt"
	"unsafe"
)

type OsVersionInfo struct {
	osVersionInfoSize uint32
	MajorVersion      uint32
	MinorVersion      uint32
	BuildNumber       uint32
	PlatformId        uint32
	CsdVersion        [128]uint16
	ServicePackMajor  uint16
	ServicePackMinor  uint16
	SuiteMask         uint16
	ProductType       byte
	reserved          byte
}

//sys rtlGetVersion(versionInfo *OsVersionInfo) (err error) [failretval!=0] = ntdll.RtlGetVersion

func OsVersion() (versionInfo OsVersionInfo, err error) {
	versionInfo.osVersionInfoSize = uint32(unsafe.Sizeof(versionInfo))
	err = rtlGetVersion(&versionInfo)
	return
}

func OsName() string {
	versionInfo, err := OsVersion()
	if err != nil {
		return "Windows Unknown"
	}
	winType := ""
	switch versionInfo.ProductType {
	case 3:
		winType = " Server"
	case 2:
		winType = " Controller"
	}
	return fmt.Sprintf("Windows%s %d.%d.%d", winType, versionInfo.MajorVersion, versionInfo.MinorVersion, versionInfo.BuildNumber)
}