aboutsummaryrefslogblamecommitdiffstatshomepage
path: root/version/os_windows.go
blob: 81147ea500e8e5aacb0d250be7fdc7b3e49cc74c (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12











                                                         
                           
                                








                                     


                              






                                                                                                 

                      









                                        
         
                                                                                                                                      
 
/* 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)
}