Home | History | Annotate | Download | only in windows
      1 // Copyright 2014 The Go Authors.  All rights reserved.
      2 // Use of this source code is governed by a BSD-style
      3 // license that can be found in the LICENSE file.
      4 
      5 package windows
      6 
      7 import "syscall"
      8 
      9 //go:generate go run ../../../syscall/mksyscall_windows.go -output zsyscall_windows.go syscall_windows.go
     10 
     11 const GAA_FLAG_INCLUDE_PREFIX = 0x00000010
     12 
     13 const IF_TYPE_SOFTWARE_LOOPBACK = 24
     14 
     15 type SocketAddress struct {
     16 	Sockaddr       *syscall.RawSockaddrAny
     17 	SockaddrLength int32
     18 }
     19 
     20 type IpAdapterUnicastAddress struct {
     21 	Length             uint32
     22 	Flags              uint32
     23 	Next               *IpAdapterUnicastAddress
     24 	Address            SocketAddress
     25 	PrefixOrigin       int32
     26 	SuffixOrigin       int32
     27 	DadState           int32
     28 	ValidLifetime      uint32
     29 	PreferredLifetime  uint32
     30 	LeaseLifetime      uint32
     31 	OnLinkPrefixLength uint8
     32 }
     33 
     34 type IpAdapterAnycastAddress struct {
     35 	Length  uint32
     36 	Flags   uint32
     37 	Next    *IpAdapterAnycastAddress
     38 	Address SocketAddress
     39 }
     40 
     41 type IpAdapterMulticastAddress struct {
     42 	Length  uint32
     43 	Flags   uint32
     44 	Next    *IpAdapterMulticastAddress
     45 	Address SocketAddress
     46 }
     47 
     48 type IpAdapterDnsServerAdapter struct {
     49 	Length   uint32
     50 	Reserved uint32
     51 	Next     *IpAdapterDnsServerAdapter
     52 	Address  SocketAddress
     53 }
     54 
     55 type IpAdapterPrefix struct {
     56 	Length       uint32
     57 	Flags        uint32
     58 	Next         *IpAdapterPrefix
     59 	Address      SocketAddress
     60 	PrefixLength uint32
     61 }
     62 
     63 type IpAdapterAddresses struct {
     64 	Length                uint32
     65 	IfIndex               uint32
     66 	Next                  *IpAdapterAddresses
     67 	AdapterName           *byte
     68 	FirstUnicastAddress   *IpAdapterUnicastAddress
     69 	FirstAnycastAddress   *IpAdapterAnycastAddress
     70 	FirstMulticastAddress *IpAdapterMulticastAddress
     71 	FirstDnsServerAddress *IpAdapterDnsServerAdapter
     72 	DnsSuffix             *uint16
     73 	Description           *uint16
     74 	FriendlyName          *uint16
     75 	PhysicalAddress       [syscall.MAX_ADAPTER_ADDRESS_LENGTH]byte
     76 	PhysicalAddressLength uint32
     77 	Flags                 uint32
     78 	Mtu                   uint32
     79 	IfType                uint32
     80 	OperStatus            uint32
     81 	Ipv6IfIndex           uint32
     82 	ZoneIndices           [16]uint32
     83 	FirstPrefix           *IpAdapterPrefix
     84 	/* more fields might be present here. */
     85 }
     86 
     87 const (
     88 	IfOperStatusUp             = 1
     89 	IfOperStatusDown           = 2
     90 	IfOperStatusTesting        = 3
     91 	IfOperStatusUnknown        = 4
     92 	IfOperStatusDormant        = 5
     93 	IfOperStatusNotPresent     = 6
     94 	IfOperStatusLowerLayerDown = 7
     95 )
     96 
     97 //sys GetAdaptersAddresses(family uint32, flags uint32, reserved uintptr, adapterAddresses *IpAdapterAddresses, sizeOfPointer *uint32) (errcode error) = iphlpapi.GetAdaptersAddresses
     98 //sys	GetComputerNameEx(nameformat uint32, buf *uint16, n *uint32) (err error) = GetComputerNameExW
     99 //sys	MoveFileEx(from *uint16, to *uint16, flags uint32) (err error) = MoveFileExW
    100 
    101 const (
    102 	ComputerNameNetBIOS                   = 0
    103 	ComputerNameDnsHostname               = 1
    104 	ComputerNameDnsDomain                 = 2
    105 	ComputerNameDnsFullyQualified         = 3
    106 	ComputerNamePhysicalNetBIOS           = 4
    107 	ComputerNamePhysicalDnsHostname       = 5
    108 	ComputerNamePhysicalDnsDomain         = 6
    109 	ComputerNamePhysicalDnsFullyQualified = 7
    110 	ComputerNameMax                       = 8
    111 
    112 	MOVEFILE_REPLACE_EXISTING      = 0x1
    113 	MOVEFILE_COPY_ALLOWED          = 0x2
    114 	MOVEFILE_DELAY_UNTIL_REBOOT    = 0x4
    115 	MOVEFILE_WRITE_THROUGH         = 0x8
    116 	MOVEFILE_CREATE_HARDLINK       = 0x10
    117 	MOVEFILE_FAIL_IF_NOT_TRACKABLE = 0x20
    118 )
    119 
    120 func Rename(oldpath, newpath string) error {
    121 	from, err := syscall.UTF16PtrFromString(oldpath)
    122 	if err != nil {
    123 		return err
    124 	}
    125 	to, err := syscall.UTF16PtrFromString(newpath)
    126 	if err != nil {
    127 		return err
    128 	}
    129 	return MoveFileEx(from, to, MOVEFILE_REPLACE_EXISTING)
    130 }
    131