...
Run Format

Source file src/syscall/ztypes_windows.go

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

View as plain text