選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 

1243 行
30 KiB

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