github.com/x04/go/src@v0.0.0-20200202162449-3d481ceb3525/syscall/types_windows.go (about)

     1  // Copyright 2011 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 syscall
     6  
     7  const (
     8  	// Windows errors.
     9  	ERROR_FILE_NOT_FOUND		Errno	= 2
    10  	ERROR_PATH_NOT_FOUND		Errno	= 3
    11  	ERROR_ACCESS_DENIED		Errno	= 5
    12  	ERROR_NO_MORE_FILES		Errno	= 18
    13  	ERROR_HANDLE_EOF		Errno	= 38
    14  	ERROR_NETNAME_DELETED		Errno	= 64
    15  	ERROR_FILE_EXISTS		Errno	= 80
    16  	ERROR_BROKEN_PIPE		Errno	= 109
    17  	ERROR_BUFFER_OVERFLOW		Errno	= 111
    18  	ERROR_INSUFFICIENT_BUFFER	Errno	= 122
    19  	ERROR_MOD_NOT_FOUND		Errno	= 126
    20  	ERROR_PROC_NOT_FOUND		Errno	= 127
    21  	ERROR_DIR_NOT_EMPTY		Errno	= 145
    22  	ERROR_ALREADY_EXISTS		Errno	= 183
    23  	ERROR_ENVVAR_NOT_FOUND		Errno	= 203
    24  	ERROR_MORE_DATA			Errno	= 234
    25  	ERROR_OPERATION_ABORTED		Errno	= 995
    26  	ERROR_IO_PENDING		Errno	= 997
    27  	ERROR_NOT_FOUND			Errno	= 1168
    28  	ERROR_PRIVILEGE_NOT_HELD	Errno	= 1314
    29  	WSAEACCES			Errno	= 10013
    30  	WSAECONNABORTED			Errno	= 10053
    31  	WSAECONNRESET			Errno	= 10054
    32  )
    33  
    34  const (
    35  	// Invented values to support what package os expects.
    36  	O_RDONLY	= 0x00000
    37  	O_WRONLY	= 0x00001
    38  	O_RDWR		= 0x00002
    39  	O_CREAT		= 0x00040
    40  	O_EXCL		= 0x00080
    41  	O_NOCTTY	= 0x00100
    42  	O_TRUNC		= 0x00200
    43  	O_NONBLOCK	= 0x00800
    44  	O_APPEND	= 0x00400
    45  	O_SYNC		= 0x01000
    46  	O_ASYNC		= 0x02000
    47  	O_CLOEXEC	= 0x80000
    48  )
    49  
    50  const (
    51  	// More invented values for signals
    52  	SIGHUP	= Signal(0x1)
    53  	SIGINT	= Signal(0x2)
    54  	SIGQUIT	= Signal(0x3)
    55  	SIGILL	= Signal(0x4)
    56  	SIGTRAP	= Signal(0x5)
    57  	SIGABRT	= Signal(0x6)
    58  	SIGBUS	= Signal(0x7)
    59  	SIGFPE	= Signal(0x8)
    60  	SIGKILL	= Signal(0x9)
    61  	SIGSEGV	= Signal(0xb)
    62  	SIGPIPE	= Signal(0xd)
    63  	SIGALRM	= Signal(0xe)
    64  	SIGTERM	= Signal(0xf)
    65  )
    66  
    67  var signals = [...]string{
    68  	1:	"hangup",
    69  	2:	"interrupt",
    70  	3:	"quit",
    71  	4:	"illegal instruction",
    72  	5:	"trace/breakpoint trap",
    73  	6:	"aborted",
    74  	7:	"bus error",
    75  	8:	"floating point exception",
    76  	9:	"killed",
    77  	10:	"user defined signal 1",
    78  	11:	"segmentation fault",
    79  	12:	"user defined signal 2",
    80  	13:	"broken pipe",
    81  	14:	"alarm clock",
    82  	15:	"terminated",
    83  }
    84  
    85  const (
    86  	GENERIC_READ	= 0x80000000
    87  	GENERIC_WRITE	= 0x40000000
    88  	GENERIC_EXECUTE	= 0x20000000
    89  	GENERIC_ALL	= 0x10000000
    90  
    91  	FILE_LIST_DIRECTORY	= 0x00000001
    92  	FILE_APPEND_DATA	= 0x00000004
    93  	FILE_WRITE_ATTRIBUTES	= 0x00000100
    94  
    95  	FILE_SHARE_READ			= 0x00000001
    96  	FILE_SHARE_WRITE		= 0x00000002
    97  	FILE_SHARE_DELETE		= 0x00000004
    98  	FILE_ATTRIBUTE_READONLY		= 0x00000001
    99  	FILE_ATTRIBUTE_HIDDEN		= 0x00000002
   100  	FILE_ATTRIBUTE_SYSTEM		= 0x00000004
   101  	FILE_ATTRIBUTE_DIRECTORY	= 0x00000010
   102  	FILE_ATTRIBUTE_ARCHIVE		= 0x00000020
   103  	FILE_ATTRIBUTE_NORMAL		= 0x00000080
   104  	FILE_ATTRIBUTE_REPARSE_POINT	= 0x00000400
   105  
   106  	INVALID_FILE_ATTRIBUTES	= 0xffffffff
   107  
   108  	CREATE_NEW		= 1
   109  	CREATE_ALWAYS		= 2
   110  	OPEN_EXISTING		= 3
   111  	OPEN_ALWAYS		= 4
   112  	TRUNCATE_EXISTING	= 5
   113  
   114  	FILE_FLAG_OPEN_REPARSE_POINT	= 0x00200000
   115  	FILE_FLAG_BACKUP_SEMANTICS	= 0x02000000
   116  	FILE_FLAG_OVERLAPPED		= 0x40000000
   117  
   118  	HANDLE_FLAG_INHERIT	= 0x00000001
   119  	STARTF_USESTDHANDLES	= 0x00000100
   120  	STARTF_USESHOWWINDOW	= 0x00000001
   121  	DUPLICATE_CLOSE_SOURCE	= 0x00000001
   122  	DUPLICATE_SAME_ACCESS	= 0x00000002
   123  
   124  	STD_INPUT_HANDLE	= -10
   125  	STD_OUTPUT_HANDLE	= -11
   126  	STD_ERROR_HANDLE	= -12
   127  
   128  	FILE_BEGIN	= 0
   129  	FILE_CURRENT	= 1
   130  	FILE_END	= 2
   131  
   132  	LANG_ENGLISH		= 0x09
   133  	SUBLANG_ENGLISH_US	= 0x01
   134  
   135  	FORMAT_MESSAGE_ALLOCATE_BUFFER	= 256
   136  	FORMAT_MESSAGE_IGNORE_INSERTS	= 512
   137  	FORMAT_MESSAGE_FROM_STRING	= 1024
   138  	FORMAT_MESSAGE_FROM_HMODULE	= 2048
   139  	FORMAT_MESSAGE_FROM_SYSTEM	= 4096
   140  	FORMAT_MESSAGE_ARGUMENT_ARRAY	= 8192
   141  	FORMAT_MESSAGE_MAX_WIDTH_MASK	= 255
   142  
   143  	MAX_PATH	= 260
   144  	MAX_LONG_PATH	= 32768
   145  
   146  	MAX_COMPUTERNAME_LENGTH	= 15
   147  
   148  	TIME_ZONE_ID_UNKNOWN	= 0
   149  	TIME_ZONE_ID_STANDARD	= 1
   150  
   151  	TIME_ZONE_ID_DAYLIGHT	= 2
   152  	IGNORE			= 0
   153  	INFINITE		= 0xffffffff
   154  
   155  	WAIT_TIMEOUT	= 258
   156  	WAIT_ABANDONED	= 0x00000080
   157  	WAIT_OBJECT_0	= 0x00000000
   158  	WAIT_FAILED	= 0xFFFFFFFF
   159  
   160  	CREATE_NEW_PROCESS_GROUP	= 0x00000200
   161  	CREATE_UNICODE_ENVIRONMENT	= 0x00000400
   162  
   163  	PROCESS_TERMINATE		= 1
   164  	PROCESS_QUERY_INFORMATION	= 0x00000400
   165  	SYNCHRONIZE			= 0x00100000
   166  
   167  	PAGE_READONLY		= 0x02
   168  	PAGE_READWRITE		= 0x04
   169  	PAGE_WRITECOPY		= 0x08
   170  	PAGE_EXECUTE_READ	= 0x20
   171  	PAGE_EXECUTE_READWRITE	= 0x40
   172  	PAGE_EXECUTE_WRITECOPY	= 0x80
   173  
   174  	FILE_MAP_COPY		= 0x01
   175  	FILE_MAP_WRITE		= 0x02
   176  	FILE_MAP_READ		= 0x04
   177  	FILE_MAP_EXECUTE	= 0x20
   178  
   179  	CTRL_C_EVENT		= 0
   180  	CTRL_BREAK_EVENT	= 1
   181  	CTRL_CLOSE_EVENT	= 2
   182  	CTRL_LOGOFF_EVENT	= 5
   183  	CTRL_SHUTDOWN_EVENT	= 6
   184  )
   185  
   186  const (
   187  	// flags for CreateToolhelp32Snapshot
   188  	TH32CS_SNAPHEAPLIST	= 0x01
   189  	TH32CS_SNAPPROCESS	= 0x02
   190  	TH32CS_SNAPTHREAD	= 0x04
   191  	TH32CS_SNAPMODULE	= 0x08
   192  	TH32CS_SNAPMODULE32	= 0x10
   193  	TH32CS_SNAPALL		= TH32CS_SNAPHEAPLIST | TH32CS_SNAPMODULE | TH32CS_SNAPPROCESS | TH32CS_SNAPTHREAD
   194  	TH32CS_INHERIT		= 0x80000000
   195  )
   196  
   197  const (
   198  	// do not reorder
   199  	FILE_NOTIFY_CHANGE_FILE_NAME	= 1 << iota
   200  	FILE_NOTIFY_CHANGE_DIR_NAME
   201  	FILE_NOTIFY_CHANGE_ATTRIBUTES
   202  	FILE_NOTIFY_CHANGE_SIZE
   203  	FILE_NOTIFY_CHANGE_LAST_WRITE
   204  	FILE_NOTIFY_CHANGE_LAST_ACCESS
   205  	FILE_NOTIFY_CHANGE_CREATION
   206  )
   207  
   208  const (
   209  	// do not reorder
   210  	FILE_ACTION_ADDED	= iota + 1
   211  	FILE_ACTION_REMOVED
   212  	FILE_ACTION_MODIFIED
   213  	FILE_ACTION_RENAMED_OLD_NAME
   214  	FILE_ACTION_RENAMED_NEW_NAME
   215  )
   216  
   217  const (
   218  	// wincrypt.h
   219  	PROV_RSA_FULL				= 1
   220  	PROV_RSA_SIG				= 2
   221  	PROV_DSS				= 3
   222  	PROV_FORTEZZA				= 4
   223  	PROV_MS_EXCHANGE			= 5
   224  	PROV_SSL				= 6
   225  	PROV_RSA_SCHANNEL			= 12
   226  	PROV_DSS_DH				= 13
   227  	PROV_EC_ECDSA_SIG			= 14
   228  	PROV_EC_ECNRA_SIG			= 15
   229  	PROV_EC_ECDSA_FULL			= 16
   230  	PROV_EC_ECNRA_FULL			= 17
   231  	PROV_DH_SCHANNEL			= 18
   232  	PROV_SPYRUS_LYNKS			= 20
   233  	PROV_RNG				= 21
   234  	PROV_INTEL_SEC				= 22
   235  	PROV_REPLACE_OWF			= 23
   236  	PROV_RSA_AES				= 24
   237  	CRYPT_VERIFYCONTEXT			= 0xF0000000
   238  	CRYPT_NEWKEYSET				= 0x00000008
   239  	CRYPT_DELETEKEYSET			= 0x00000010
   240  	CRYPT_MACHINE_KEYSET			= 0x00000020
   241  	CRYPT_SILENT				= 0x00000040
   242  	CRYPT_DEFAULT_CONTAINER_OPTIONAL	= 0x00000080
   243  
   244  	USAGE_MATCH_TYPE_AND	= 0
   245  	USAGE_MATCH_TYPE_OR	= 1
   246  
   247  	X509_ASN_ENCODING	= 0x00000001
   248  	PKCS_7_ASN_ENCODING	= 0x00010000
   249  
   250  	CERT_STORE_PROV_MEMORY	= 2
   251  
   252  	CERT_STORE_ADD_ALWAYS	= 4
   253  
   254  	CERT_STORE_DEFER_CLOSE_UNTIL_LAST_FREE_FLAG	= 0x00000004
   255  
   256  	CERT_TRUST_NO_ERROR				= 0x00000000
   257  	CERT_TRUST_IS_NOT_TIME_VALID			= 0x00000001
   258  	CERT_TRUST_IS_REVOKED				= 0x00000004
   259  	CERT_TRUST_IS_NOT_SIGNATURE_VALID		= 0x00000008
   260  	CERT_TRUST_IS_NOT_VALID_FOR_USAGE		= 0x00000010
   261  	CERT_TRUST_IS_UNTRUSTED_ROOT			= 0x00000020
   262  	CERT_TRUST_REVOCATION_STATUS_UNKNOWN		= 0x00000040
   263  	CERT_TRUST_IS_CYCLIC				= 0x00000080
   264  	CERT_TRUST_INVALID_EXTENSION			= 0x00000100
   265  	CERT_TRUST_INVALID_POLICY_CONSTRAINTS		= 0x00000200
   266  	CERT_TRUST_INVALID_BASIC_CONSTRAINTS		= 0x00000400
   267  	CERT_TRUST_INVALID_NAME_CONSTRAINTS		= 0x00000800
   268  	CERT_TRUST_HAS_NOT_SUPPORTED_NAME_CONSTRAINT	= 0x00001000
   269  	CERT_TRUST_HAS_NOT_DEFINED_NAME_CONSTRAINT	= 0x00002000
   270  	CERT_TRUST_HAS_NOT_PERMITTED_NAME_CONSTRAINT	= 0x00004000
   271  	CERT_TRUST_HAS_EXCLUDED_NAME_CONSTRAINT		= 0x00008000
   272  	CERT_TRUST_IS_OFFLINE_REVOCATION		= 0x01000000
   273  	CERT_TRUST_NO_ISSUANCE_CHAIN_POLICY		= 0x02000000
   274  	CERT_TRUST_IS_EXPLICIT_DISTRUST			= 0x04000000
   275  	CERT_TRUST_HAS_NOT_SUPPORTED_CRITICAL_EXT	= 0x08000000
   276  
   277  	CERT_CHAIN_POLICY_BASE			= 1
   278  	CERT_CHAIN_POLICY_AUTHENTICODE		= 2
   279  	CERT_CHAIN_POLICY_AUTHENTICODE_TS	= 3
   280  	CERT_CHAIN_POLICY_SSL			= 4
   281  	CERT_CHAIN_POLICY_BASIC_CONSTRAINTS	= 5
   282  	CERT_CHAIN_POLICY_NT_AUTH		= 6
   283  	CERT_CHAIN_POLICY_MICROSOFT_ROOT	= 7
   284  	CERT_CHAIN_POLICY_EV			= 8
   285  
   286  	CERT_E_EXPIRED		= 0x800B0101
   287  	CERT_E_ROLE		= 0x800B0103
   288  	CERT_E_PURPOSE		= 0x800B0106
   289  	CERT_E_UNTRUSTEDROOT	= 0x800B0109
   290  	CERT_E_CN_NO_MATCH	= 0x800B010F
   291  
   292  	AUTHTYPE_CLIENT	= 1
   293  	AUTHTYPE_SERVER	= 2
   294  )
   295  
   296  var (
   297  	OID_PKIX_KP_SERVER_AUTH	= []byte("1.3.6.1.5.5.7.3.1\x00")
   298  	OID_SERVER_GATED_CRYPTO	= []byte("1.3.6.1.4.1.311.10.3.3\x00")
   299  	OID_SGC_NETSCAPE	= []byte("2.16.840.1.113730.4.1\x00")
   300  )
   301  
   302  // Pointer represents a pointer to an arbitrary Windows type.
   303  //
   304  // Pointer-typed fields may point to one of many different types. It's
   305  // up to the caller to provide a pointer to the appropriate type, cast
   306  // to Pointer. The caller must obey the unsafe.Pointer rules while
   307  // doing so.
   308  type Pointer *struct{}
   309  
   310  // Invented values to support what package os expects.
   311  type Timeval struct {
   312  	Sec	int32
   313  	Usec	int32
   314  }
   315  
   316  func (tv *Timeval) Nanoseconds() int64 {
   317  	return (int64(tv.Sec)*1e6 + int64(tv.Usec)) * 1e3
   318  }
   319  
   320  func NsecToTimeval(nsec int64) (tv Timeval) {
   321  	tv.Sec = int32(nsec / 1e9)
   322  	tv.Usec = int32(nsec % 1e9 / 1e3)
   323  	return
   324  }
   325  
   326  type SecurityAttributes struct {
   327  	Length			uint32
   328  	SecurityDescriptor	uintptr
   329  	InheritHandle		uint32
   330  }
   331  
   332  type Overlapped struct {
   333  	Internal	uintptr
   334  	InternalHigh	uintptr
   335  	Offset		uint32
   336  	OffsetHigh	uint32
   337  	HEvent		Handle
   338  }
   339  
   340  type FileNotifyInformation struct {
   341  	NextEntryOffset	uint32
   342  	Action		uint32
   343  	FileNameLength	uint32
   344  	FileName	uint16
   345  }
   346  
   347  type Filetime struct {
   348  	LowDateTime	uint32
   349  	HighDateTime	uint32
   350  }
   351  
   352  // Nanoseconds returns Filetime ft in nanoseconds
   353  // since Epoch (00:00:00 UTC, January 1, 1970).
   354  func (ft *Filetime) Nanoseconds() int64 {
   355  	// 100-nanosecond intervals since January 1, 1601
   356  	nsec := int64(ft.HighDateTime)<<32 + int64(ft.LowDateTime)
   357  	// change starting time to the Epoch (00:00:00 UTC, January 1, 1970)
   358  	nsec -= 116444736000000000
   359  	// convert into nanoseconds
   360  	nsec *= 100
   361  	return nsec
   362  }
   363  
   364  func NsecToFiletime(nsec int64) (ft Filetime) {
   365  	// convert into 100-nanosecond
   366  	nsec /= 100
   367  	// change starting time to January 1, 1601
   368  	nsec += 116444736000000000
   369  	// split into high / low
   370  	ft.LowDateTime = uint32(nsec & 0xffffffff)
   371  	ft.HighDateTime = uint32(nsec >> 32 & 0xffffffff)
   372  	return ft
   373  }
   374  
   375  type Win32finddata struct {
   376  	FileAttributes		uint32
   377  	CreationTime		Filetime
   378  	LastAccessTime		Filetime
   379  	LastWriteTime		Filetime
   380  	FileSizeHigh		uint32
   381  	FileSizeLow		uint32
   382  	Reserved0		uint32
   383  	Reserved1		uint32
   384  	FileName		[MAX_PATH - 1]uint16
   385  	AlternateFileName	[13]uint16
   386  }
   387  
   388  // This is the actual system call structure.
   389  // Win32finddata is what we committed to in Go 1.
   390  type win32finddata1 struct {
   391  	FileAttributes		uint32
   392  	CreationTime		Filetime
   393  	LastAccessTime		Filetime
   394  	LastWriteTime		Filetime
   395  	FileSizeHigh		uint32
   396  	FileSizeLow		uint32
   397  	Reserved0		uint32
   398  	Reserved1		uint32
   399  	FileName		[MAX_PATH]uint16
   400  	AlternateFileName	[14]uint16
   401  }
   402  
   403  func copyFindData(dst *Win32finddata, src *win32finddata1) {
   404  	dst.FileAttributes = src.FileAttributes
   405  	dst.CreationTime = src.CreationTime
   406  	dst.LastAccessTime = src.LastAccessTime
   407  	dst.LastWriteTime = src.LastWriteTime
   408  	dst.FileSizeHigh = src.FileSizeHigh
   409  	dst.FileSizeLow = src.FileSizeLow
   410  	dst.Reserved0 = src.Reserved0
   411  	dst.Reserved1 = src.Reserved1
   412  
   413  	// The src is 1 element bigger than dst, but it must be NUL.
   414  	copy(dst.FileName[:], src.FileName[:])
   415  	copy(dst.AlternateFileName[:], src.AlternateFileName[:])
   416  }
   417  
   418  type ByHandleFileInformation struct {
   419  	FileAttributes		uint32
   420  	CreationTime		Filetime
   421  	LastAccessTime		Filetime
   422  	LastWriteTime		Filetime
   423  	VolumeSerialNumber	uint32
   424  	FileSizeHigh		uint32
   425  	FileSizeLow		uint32
   426  	NumberOfLinks		uint32
   427  	FileIndexHigh		uint32
   428  	FileIndexLow		uint32
   429  }
   430  
   431  const (
   432  	GetFileExInfoStandard	= 0
   433  	GetFileExMaxInfoLevel	= 1
   434  )
   435  
   436  type Win32FileAttributeData struct {
   437  	FileAttributes	uint32
   438  	CreationTime	Filetime
   439  	LastAccessTime	Filetime
   440  	LastWriteTime	Filetime
   441  	FileSizeHigh	uint32
   442  	FileSizeLow	uint32
   443  }
   444  
   445  // ShowWindow constants
   446  const (
   447  	// winuser.h
   448  	SW_HIDE			= 0
   449  	SW_NORMAL		= 1
   450  	SW_SHOWNORMAL		= 1
   451  	SW_SHOWMINIMIZED	= 2
   452  	SW_SHOWMAXIMIZED	= 3
   453  	SW_MAXIMIZE		= 3
   454  	SW_SHOWNOACTIVATE	= 4
   455  	SW_SHOW			= 5
   456  	SW_MINIMIZE		= 6
   457  	SW_SHOWMINNOACTIVE	= 7
   458  	SW_SHOWNA		= 8
   459  	SW_RESTORE		= 9
   460  	SW_SHOWDEFAULT		= 10
   461  	SW_FORCEMINIMIZE	= 11
   462  )
   463  
   464  type StartupInfo struct {
   465  	Cb		uint32
   466  	_		*uint16
   467  	Desktop		*uint16
   468  	Title		*uint16
   469  	X		uint32
   470  	Y		uint32
   471  	XSize		uint32
   472  	YSize		uint32
   473  	XCountChars	uint32
   474  	YCountChars	uint32
   475  	FillAttribute	uint32
   476  	Flags		uint32
   477  	ShowWindow	uint16
   478  	_		uint16
   479  	_		*byte
   480  	StdInput	Handle
   481  	StdOutput	Handle
   482  	StdErr		Handle
   483  }
   484  
   485  type ProcessInformation struct {
   486  	Process		Handle
   487  	Thread		Handle
   488  	ProcessId	uint32
   489  	ThreadId	uint32
   490  }
   491  
   492  type ProcessEntry32 struct {
   493  	Size		uint32
   494  	Usage		uint32
   495  	ProcessID	uint32
   496  	DefaultHeapID	uintptr
   497  	ModuleID	uint32
   498  	Threads		uint32
   499  	ParentProcessID	uint32
   500  	PriClassBase	int32
   501  	Flags		uint32
   502  	ExeFile		[MAX_PATH]uint16
   503  }
   504  
   505  type Systemtime struct {
   506  	Year		uint16
   507  	Month		uint16
   508  	DayOfWeek	uint16
   509  	Day		uint16
   510  	Hour		uint16
   511  	Minute		uint16
   512  	Second		uint16
   513  	Milliseconds	uint16
   514  }
   515  
   516  type Timezoneinformation struct {
   517  	Bias		int32
   518  	StandardName	[32]uint16
   519  	StandardDate	Systemtime
   520  	StandardBias	int32
   521  	DaylightName	[32]uint16
   522  	DaylightDate	Systemtime
   523  	DaylightBias	int32
   524  }
   525  
   526  // Socket related.
   527  
   528  const (
   529  	AF_UNSPEC	= 0
   530  	AF_UNIX		= 1
   531  	AF_INET		= 2
   532  	AF_INET6	= 23
   533  	AF_NETBIOS	= 17
   534  
   535  	SOCK_STREAM	= 1
   536  	SOCK_DGRAM	= 2
   537  	SOCK_RAW	= 3
   538  	SOCK_SEQPACKET	= 5
   539  
   540  	IPPROTO_IP	= 0
   541  	IPPROTO_IPV6	= 0x29
   542  	IPPROTO_TCP	= 6
   543  	IPPROTO_UDP	= 17
   544  
   545  	SOL_SOCKET			= 0xffff
   546  	SO_REUSEADDR			= 4
   547  	SO_KEEPALIVE			= 8
   548  	SO_DONTROUTE			= 16
   549  	SO_BROADCAST			= 32
   550  	SO_LINGER			= 128
   551  	SO_RCVBUF			= 0x1002
   552  	SO_SNDBUF			= 0x1001
   553  	SO_UPDATE_ACCEPT_CONTEXT	= 0x700b
   554  	SO_UPDATE_CONNECT_CONTEXT	= 0x7010
   555  
   556  	IOC_OUT					= 0x40000000
   557  	IOC_IN					= 0x80000000
   558  	IOC_VENDOR				= 0x18000000
   559  	IOC_INOUT				= IOC_IN | IOC_OUT
   560  	IOC_WS2					= 0x08000000
   561  	SIO_GET_EXTENSION_FUNCTION_POINTER	= IOC_INOUT | IOC_WS2 | 6
   562  	SIO_KEEPALIVE_VALS			= IOC_IN | IOC_VENDOR | 4
   563  	SIO_UDP_CONNRESET			= IOC_IN | IOC_VENDOR | 12
   564  
   565  	// cf. https://support.microsoft.com/default.aspx?scid=kb;en-us;257460
   566  
   567  	IP_TOS			= 0x3
   568  	IP_TTL			= 0x4
   569  	IP_MULTICAST_IF		= 0x9
   570  	IP_MULTICAST_TTL	= 0xa
   571  	IP_MULTICAST_LOOP	= 0xb
   572  	IP_ADD_MEMBERSHIP	= 0xc
   573  	IP_DROP_MEMBERSHIP	= 0xd
   574  
   575  	IPV6_V6ONLY		= 0x1b
   576  	IPV6_UNICAST_HOPS	= 0x4
   577  	IPV6_MULTICAST_IF	= 0x9
   578  	IPV6_MULTICAST_HOPS	= 0xa
   579  	IPV6_MULTICAST_LOOP	= 0xb
   580  	IPV6_JOIN_GROUP		= 0xc
   581  	IPV6_LEAVE_GROUP	= 0xd
   582  
   583  	SOMAXCONN	= 0x7fffffff
   584  
   585  	TCP_NODELAY	= 1
   586  
   587  	SHUT_RD		= 0
   588  	SHUT_WR		= 1
   589  	SHUT_RDWR	= 2
   590  
   591  	WSADESCRIPTION_LEN	= 256
   592  	WSASYS_STATUS_LEN	= 128
   593  )
   594  
   595  type WSABuf struct {
   596  	Len	uint32
   597  	Buf	*byte
   598  }
   599  
   600  // Invented values to support what package os expects.
   601  const (
   602  	S_IFMT		= 0x1f000
   603  	S_IFIFO		= 0x1000
   604  	S_IFCHR		= 0x2000
   605  	S_IFDIR		= 0x4000
   606  	S_IFBLK		= 0x6000
   607  	S_IFREG		= 0x8000
   608  	S_IFLNK		= 0xa000
   609  	S_IFSOCK	= 0xc000
   610  	S_ISUID		= 0x800
   611  	S_ISGID		= 0x400
   612  	S_ISVTX		= 0x200
   613  	S_IRUSR		= 0x100
   614  	S_IWRITE	= 0x80
   615  	S_IWUSR		= 0x80
   616  	S_IXUSR		= 0x40
   617  )
   618  
   619  const (
   620  	FILE_TYPE_CHAR		= 0x0002
   621  	FILE_TYPE_DISK		= 0x0001
   622  	FILE_TYPE_PIPE		= 0x0003
   623  	FILE_TYPE_REMOTE	= 0x8000
   624  	FILE_TYPE_UNKNOWN	= 0x0000
   625  )
   626  
   627  type Hostent struct {
   628  	Name		*byte
   629  	Aliases		**byte
   630  	AddrType	uint16
   631  	Length		uint16
   632  	AddrList	**byte
   633  }
   634  
   635  type Protoent struct {
   636  	Name	*byte
   637  	Aliases	**byte
   638  	Proto	uint16
   639  }
   640  
   641  const (
   642  	DNS_TYPE_A		= 0x0001
   643  	DNS_TYPE_NS		= 0x0002
   644  	DNS_TYPE_MD		= 0x0003
   645  	DNS_TYPE_MF		= 0x0004
   646  	DNS_TYPE_CNAME		= 0x0005
   647  	DNS_TYPE_SOA		= 0x0006
   648  	DNS_TYPE_MB		= 0x0007
   649  	DNS_TYPE_MG		= 0x0008
   650  	DNS_TYPE_MR		= 0x0009
   651  	DNS_TYPE_NULL		= 0x000a
   652  	DNS_TYPE_WKS		= 0x000b
   653  	DNS_TYPE_PTR		= 0x000c
   654  	DNS_TYPE_HINFO		= 0x000d
   655  	DNS_TYPE_MINFO		= 0x000e
   656  	DNS_TYPE_MX		= 0x000f
   657  	DNS_TYPE_TEXT		= 0x0010
   658  	DNS_TYPE_RP		= 0x0011
   659  	DNS_TYPE_AFSDB		= 0x0012
   660  	DNS_TYPE_X25		= 0x0013
   661  	DNS_TYPE_ISDN		= 0x0014
   662  	DNS_TYPE_RT		= 0x0015
   663  	DNS_TYPE_NSAP		= 0x0016
   664  	DNS_TYPE_NSAPPTR	= 0x0017
   665  	DNS_TYPE_SIG		= 0x0018
   666  	DNS_TYPE_KEY		= 0x0019
   667  	DNS_TYPE_PX		= 0x001a
   668  	DNS_TYPE_GPOS		= 0x001b
   669  	DNS_TYPE_AAAA		= 0x001c
   670  	DNS_TYPE_LOC		= 0x001d
   671  	DNS_TYPE_NXT		= 0x001e
   672  	DNS_TYPE_EID		= 0x001f
   673  	DNS_TYPE_NIMLOC		= 0x0020
   674  	DNS_TYPE_SRV		= 0x0021
   675  	DNS_TYPE_ATMA		= 0x0022
   676  	DNS_TYPE_NAPTR		= 0x0023
   677  	DNS_TYPE_KX		= 0x0024
   678  	DNS_TYPE_CERT		= 0x0025
   679  	DNS_TYPE_A6		= 0x0026
   680  	DNS_TYPE_DNAME		= 0x0027
   681  	DNS_TYPE_SINK		= 0x0028
   682  	DNS_TYPE_OPT		= 0x0029
   683  	DNS_TYPE_DS		= 0x002B
   684  	DNS_TYPE_RRSIG		= 0x002E
   685  	DNS_TYPE_NSEC		= 0x002F
   686  	DNS_TYPE_DNSKEY		= 0x0030
   687  	DNS_TYPE_DHCID		= 0x0031
   688  	DNS_TYPE_UINFO		= 0x0064
   689  	DNS_TYPE_UID		= 0x0065
   690  	DNS_TYPE_GID		= 0x0066
   691  	DNS_TYPE_UNSPEC		= 0x0067
   692  	DNS_TYPE_ADDRS		= 0x00f8
   693  	DNS_TYPE_TKEY		= 0x00f9
   694  	DNS_TYPE_TSIG		= 0x00fa
   695  	DNS_TYPE_IXFR		= 0x00fb
   696  	DNS_TYPE_AXFR		= 0x00fc
   697  	DNS_TYPE_MAILB		= 0x00fd
   698  	DNS_TYPE_MAILA		= 0x00fe
   699  	DNS_TYPE_ALL		= 0x00ff
   700  	DNS_TYPE_ANY		= 0x00ff
   701  	DNS_TYPE_WINS		= 0xff01
   702  	DNS_TYPE_WINSR		= 0xff02
   703  	DNS_TYPE_NBSTAT		= 0xff01
   704  )
   705  
   706  const (
   707  	DNS_INFO_NO_RECORDS = 0x251D
   708  )
   709  
   710  const (
   711  	// flags inside DNSRecord.Dw
   712  	DnsSectionQuestion	= 0x0000
   713  	DnsSectionAnswer	= 0x0001
   714  	DnsSectionAuthority	= 0x0002
   715  	DnsSectionAdditional	= 0x0003
   716  )
   717  
   718  type DNSSRVData struct {
   719  	Target		*uint16
   720  	Priority	uint16
   721  	Weight		uint16
   722  	Port		uint16
   723  	Pad		uint16
   724  }
   725  
   726  type DNSPTRData struct {
   727  	Host *uint16
   728  }
   729  
   730  type DNSMXData struct {
   731  	NameExchange	*uint16
   732  	Preference	uint16
   733  	Pad		uint16
   734  }
   735  
   736  type DNSTXTData struct {
   737  	StringCount	uint16
   738  	StringArray	[1]*uint16
   739  }
   740  
   741  type DNSRecord struct {
   742  	Next		*DNSRecord
   743  	Name		*uint16
   744  	Type		uint16
   745  	Length		uint16
   746  	Dw		uint32
   747  	Ttl		uint32
   748  	Reserved	uint32
   749  	Data		[40]byte
   750  }
   751  
   752  const (
   753  	TF_DISCONNECT		= 1
   754  	TF_REUSE_SOCKET		= 2
   755  	TF_WRITE_BEHIND		= 4
   756  	TF_USE_DEFAULT_WORKER	= 0
   757  	TF_USE_SYSTEM_THREAD	= 16
   758  	TF_USE_KERNEL_APC	= 32
   759  )
   760  
   761  type TransmitFileBuffers struct {
   762  	Head		uintptr
   763  	HeadLength	uint32
   764  	Tail		uintptr
   765  	TailLength	uint32
   766  }
   767  
   768  const (
   769  	IFF_UP			= 1
   770  	IFF_BROADCAST		= 2
   771  	IFF_LOOPBACK		= 4
   772  	IFF_POINTTOPOINT	= 8
   773  	IFF_MULTICAST		= 16
   774  )
   775  
   776  const SIO_GET_INTERFACE_LIST = 0x4004747F
   777  
   778  // TODO(mattn): SockaddrGen is union of sockaddr/sockaddr_in/sockaddr_in6_old.
   779  // will be fixed to change variable type as suitable.
   780  
   781  type SockaddrGen [24]byte
   782  
   783  type InterfaceInfo struct {
   784  	Flags			uint32
   785  	Address			SockaddrGen
   786  	BroadcastAddress	SockaddrGen
   787  	Netmask			SockaddrGen
   788  }
   789  
   790  type IpAddressString struct {
   791  	String [16]byte
   792  }
   793  
   794  type IpMaskString IpAddressString
   795  
   796  type IpAddrString struct {
   797  	Next		*IpAddrString
   798  	IpAddress	IpAddressString
   799  	IpMask		IpMaskString
   800  	Context		uint32
   801  }
   802  
   803  const MAX_ADAPTER_NAME_LENGTH = 256
   804  const MAX_ADAPTER_DESCRIPTION_LENGTH = 128
   805  const MAX_ADAPTER_ADDRESS_LENGTH = 8
   806  
   807  type IpAdapterInfo struct {
   808  	Next			*IpAdapterInfo
   809  	ComboIndex		uint32
   810  	AdapterName		[MAX_ADAPTER_NAME_LENGTH + 4]byte
   811  	Description		[MAX_ADAPTER_DESCRIPTION_LENGTH + 4]byte
   812  	AddressLength		uint32
   813  	Address			[MAX_ADAPTER_ADDRESS_LENGTH]byte
   814  	Index			uint32
   815  	Type			uint32
   816  	DhcpEnabled		uint32
   817  	CurrentIpAddress	*IpAddrString
   818  	IpAddressList		IpAddrString
   819  	GatewayList		IpAddrString
   820  	DhcpServer		IpAddrString
   821  	HaveWins		bool
   822  	PrimaryWinsServer	IpAddrString
   823  	SecondaryWinsServer	IpAddrString
   824  	LeaseObtained		int64
   825  	LeaseExpires		int64
   826  }
   827  
   828  const MAXLEN_PHYSADDR = 8
   829  const MAX_INTERFACE_NAME_LEN = 256
   830  const MAXLEN_IFDESCR = 256
   831  
   832  type MibIfRow struct {
   833  	Name		[MAX_INTERFACE_NAME_LEN]uint16
   834  	Index		uint32
   835  	Type		uint32
   836  	Mtu		uint32
   837  	Speed		uint32
   838  	PhysAddrLen	uint32
   839  	PhysAddr	[MAXLEN_PHYSADDR]byte
   840  	AdminStatus	uint32
   841  	OperStatus	uint32
   842  	LastChange	uint32
   843  	InOctets	uint32
   844  	InUcastPkts	uint32
   845  	InNUcastPkts	uint32
   846  	InDiscards	uint32
   847  	InErrors	uint32
   848  	InUnknownProtos	uint32
   849  	OutOctets	uint32
   850  	OutUcastPkts	uint32
   851  	OutNUcastPkts	uint32
   852  	OutDiscards	uint32
   853  	OutErrors	uint32
   854  	OutQLen		uint32
   855  	DescrLen	uint32
   856  	Descr		[MAXLEN_IFDESCR]byte
   857  }
   858  
   859  type CertInfo struct {
   860  	// Not implemented
   861  }
   862  
   863  type CertContext struct {
   864  	EncodingType	uint32
   865  	EncodedCert	*byte
   866  	Length		uint32
   867  	CertInfo	*CertInfo
   868  	Store		Handle
   869  }
   870  
   871  type CertChainContext struct {
   872  	Size				uint32
   873  	TrustStatus			CertTrustStatus
   874  	ChainCount			uint32
   875  	Chains				**CertSimpleChain
   876  	LowerQualityChainCount		uint32
   877  	LowerQualityChains		**CertChainContext
   878  	HasRevocationFreshnessTime	uint32
   879  	RevocationFreshnessTime		uint32
   880  }
   881  
   882  type CertTrustListInfo struct {
   883  	// Not implemented
   884  }
   885  
   886  type CertSimpleChain struct {
   887  	Size				uint32
   888  	TrustStatus			CertTrustStatus
   889  	NumElements			uint32
   890  	Elements			**CertChainElement
   891  	TrustListInfo			*CertTrustListInfo
   892  	HasRevocationFreshnessTime	uint32
   893  	RevocationFreshnessTime		uint32
   894  }
   895  
   896  type CertChainElement struct {
   897  	Size			uint32
   898  	CertContext		*CertContext
   899  	TrustStatus		CertTrustStatus
   900  	RevocationInfo		*CertRevocationInfo
   901  	IssuanceUsage		*CertEnhKeyUsage
   902  	ApplicationUsage	*CertEnhKeyUsage
   903  	ExtendedErrorInfo	*uint16
   904  }
   905  
   906  type CertRevocationCrlInfo struct {
   907  	// Not implemented
   908  }
   909  
   910  type CertRevocationInfo struct {
   911  	Size			uint32
   912  	RevocationResult	uint32
   913  	RevocationOid		*byte
   914  	OidSpecificInfo		Pointer
   915  	HasFreshnessTime	uint32
   916  	FreshnessTime		uint32
   917  	CrlInfo			*CertRevocationCrlInfo
   918  }
   919  
   920  type CertTrustStatus struct {
   921  	ErrorStatus	uint32
   922  	InfoStatus	uint32
   923  }
   924  
   925  type CertUsageMatch struct {
   926  	Type	uint32
   927  	Usage	CertEnhKeyUsage
   928  }
   929  
   930  type CertEnhKeyUsage struct {
   931  	Length			uint32
   932  	UsageIdentifiers	**byte
   933  }
   934  
   935  type CertChainPara struct {
   936  	Size				uint32
   937  	RequestedUsage			CertUsageMatch
   938  	RequstedIssuancePolicy		CertUsageMatch
   939  	URLRetrievalTimeout		uint32
   940  	CheckRevocationFreshnessTime	uint32
   941  	RevocationFreshnessTime		uint32
   942  	CacheResync			*Filetime
   943  }
   944  
   945  type CertChainPolicyPara struct {
   946  	Size		uint32
   947  	Flags		uint32
   948  	ExtraPolicyPara	Pointer
   949  }
   950  
   951  type SSLExtraCertChainPolicyPara struct {
   952  	Size		uint32
   953  	AuthType	uint32
   954  	Checks		uint32
   955  	ServerName	*uint16
   956  }
   957  
   958  type CertChainPolicyStatus struct {
   959  	Size			uint32
   960  	Error			uint32
   961  	ChainIndex		uint32
   962  	ElementIndex		uint32
   963  	ExtraPolicyStatus	Pointer
   964  }
   965  
   966  const (
   967  	// do not reorder
   968  	HKEY_CLASSES_ROOT	= 0x80000000 + iota
   969  	HKEY_CURRENT_USER
   970  	HKEY_LOCAL_MACHINE
   971  	HKEY_USERS
   972  	HKEY_PERFORMANCE_DATA
   973  	HKEY_CURRENT_CONFIG
   974  	HKEY_DYN_DATA
   975  
   976  	KEY_QUERY_VALUE		= 1
   977  	KEY_SET_VALUE		= 2
   978  	KEY_CREATE_SUB_KEY	= 4
   979  	KEY_ENUMERATE_SUB_KEYS	= 8
   980  	KEY_NOTIFY		= 16
   981  	KEY_CREATE_LINK		= 32
   982  	KEY_WRITE		= 0x20006
   983  	KEY_EXECUTE		= 0x20019
   984  	KEY_READ		= 0x20019
   985  	KEY_WOW64_64KEY		= 0x0100
   986  	KEY_WOW64_32KEY		= 0x0200
   987  	KEY_ALL_ACCESS		= 0xf003f
   988  )
   989  
   990  const (
   991  	// do not reorder
   992  	REG_NONE	= iota
   993  	REG_SZ
   994  	REG_EXPAND_SZ
   995  	REG_BINARY
   996  	REG_DWORD_LITTLE_ENDIAN
   997  	REG_DWORD_BIG_ENDIAN
   998  	REG_LINK
   999  	REG_MULTI_SZ
  1000  	REG_RESOURCE_LIST
  1001  	REG_FULL_RESOURCE_DESCRIPTOR
  1002  	REG_RESOURCE_REQUIREMENTS_LIST
  1003  	REG_QWORD_LITTLE_ENDIAN
  1004  	REG_DWORD	= REG_DWORD_LITTLE_ENDIAN
  1005  	REG_QWORD	= REG_QWORD_LITTLE_ENDIAN
  1006  )
  1007  
  1008  type AddrinfoW struct {
  1009  	Flags		int32
  1010  	Family		int32
  1011  	Socktype	int32
  1012  	Protocol	int32
  1013  	Addrlen		uintptr
  1014  	Canonname	*uint16
  1015  	Addr		Pointer
  1016  	Next		*AddrinfoW
  1017  }
  1018  
  1019  const (
  1020  	AI_PASSIVE	= 1
  1021  	AI_CANONNAME	= 2
  1022  	AI_NUMERICHOST	= 4
  1023  )
  1024  
  1025  type GUID struct {
  1026  	Data1	uint32
  1027  	Data2	uint16
  1028  	Data3	uint16
  1029  	Data4	[8]byte
  1030  }
  1031  
  1032  var WSAID_CONNECTEX = GUID{
  1033  	0x25a207b9,
  1034  	0xddf3,
  1035  	0x4660,
  1036  	[8]byte{0x8e, 0xe9, 0x76, 0xe5, 0x8c, 0x74, 0x06, 0x3e},
  1037  }
  1038  
  1039  const (
  1040  	FILE_SKIP_COMPLETION_PORT_ON_SUCCESS	= 1
  1041  	FILE_SKIP_SET_EVENT_ON_HANDLE		= 2
  1042  )
  1043  
  1044  const (
  1045  	WSAPROTOCOL_LEN		= 255
  1046  	MAX_PROTOCOL_CHAIN	= 7
  1047  	BASE_PROTOCOL		= 1
  1048  	LAYERED_PROTOCOL	= 0
  1049  
  1050  	XP1_CONNECTIONLESS		= 0x00000001
  1051  	XP1_GUARANTEED_DELIVERY		= 0x00000002
  1052  	XP1_GUARANTEED_ORDER		= 0x00000004
  1053  	XP1_MESSAGE_ORIENTED		= 0x00000008
  1054  	XP1_PSEUDO_STREAM		= 0x00000010
  1055  	XP1_GRACEFUL_CLOSE		= 0x00000020
  1056  	XP1_EXPEDITED_DATA		= 0x00000040
  1057  	XP1_CONNECT_DATA		= 0x00000080
  1058  	XP1_DISCONNECT_DATA		= 0x00000100
  1059  	XP1_SUPPORT_BROADCAST		= 0x00000200
  1060  	XP1_SUPPORT_MULTIPOINT		= 0x00000400
  1061  	XP1_MULTIPOINT_CONTROL_PLANE	= 0x00000800
  1062  	XP1_MULTIPOINT_DATA_PLANE	= 0x00001000
  1063  	XP1_QOS_SUPPORTED		= 0x00002000
  1064  	XP1_UNI_SEND			= 0x00008000
  1065  	XP1_UNI_RECV			= 0x00010000
  1066  	XP1_IFS_HANDLES			= 0x00020000
  1067  	XP1_PARTIAL_MESSAGE		= 0x00040000
  1068  	XP1_SAN_SUPPORT_SDP		= 0x00080000
  1069  
  1070  	PFL_MULTIPLE_PROTO_ENTRIES	= 0x00000001
  1071  	PFL_RECOMMENDED_PROTO_ENTRY	= 0x00000002
  1072  	PFL_HIDDEN			= 0x00000004
  1073  	PFL_MATCHES_PROTOCOL_ZERO	= 0x00000008
  1074  	PFL_NETWORKDIRECT_PROVIDER	= 0x00000010
  1075  )
  1076  
  1077  type WSAProtocolInfo struct {
  1078  	ServiceFlags1		uint32
  1079  	ServiceFlags2		uint32
  1080  	ServiceFlags3		uint32
  1081  	ServiceFlags4		uint32
  1082  	ProviderFlags		uint32
  1083  	ProviderId		GUID
  1084  	CatalogEntryId		uint32
  1085  	ProtocolChain		WSAProtocolChain
  1086  	Version			int32
  1087  	AddressFamily		int32
  1088  	MaxSockAddr		int32
  1089  	MinSockAddr		int32
  1090  	SocketType		int32
  1091  	Protocol		int32
  1092  	ProtocolMaxOffset	int32
  1093  	NetworkByteOrder	int32
  1094  	SecurityScheme		int32
  1095  	MessageSize		uint32
  1096  	ProviderReserved	uint32
  1097  	ProtocolName		[WSAPROTOCOL_LEN + 1]uint16
  1098  }
  1099  
  1100  type WSAProtocolChain struct {
  1101  	ChainLen	int32
  1102  	ChainEntries	[MAX_PROTOCOL_CHAIN]uint32
  1103  }
  1104  
  1105  type TCPKeepalive struct {
  1106  	OnOff		uint32
  1107  	Time		uint32
  1108  	Interval	uint32
  1109  }
  1110  
  1111  type symbolicLinkReparseBuffer struct {
  1112  	SubstituteNameOffset	uint16
  1113  	SubstituteNameLength	uint16
  1114  	PrintNameOffset		uint16
  1115  	PrintNameLength		uint16
  1116  	Flags			uint32
  1117  	PathBuffer		[1]uint16
  1118  }
  1119  
  1120  type mountPointReparseBuffer struct {
  1121  	SubstituteNameOffset	uint16
  1122  	SubstituteNameLength	uint16
  1123  	PrintNameOffset		uint16
  1124  	PrintNameLength		uint16
  1125  	PathBuffer		[1]uint16
  1126  }
  1127  
  1128  type reparseDataBuffer struct {
  1129  	ReparseTag		uint32
  1130  	ReparseDataLength	uint16
  1131  	Reserved		uint16
  1132  
  1133  	// GenericReparseBuffer
  1134  	reparseBuffer	byte
  1135  }
  1136  
  1137  const (
  1138  	FSCTL_GET_REPARSE_POINT			= 0x900A8
  1139  	MAXIMUM_REPARSE_DATA_BUFFER_SIZE	= 16 * 1024
  1140  	_IO_REPARSE_TAG_MOUNT_POINT		= 0xA0000003
  1141  	IO_REPARSE_TAG_SYMLINK			= 0xA000000C
  1142  	SYMBOLIC_LINK_FLAG_DIRECTORY		= 0x1
  1143  	_SYMLINK_FLAG_RELATIVE			= 1
  1144  )
  1145  
  1146  const UNIX_PATH_MAX = 108	// defined in afunix.h