mirror of
https://github.com/ziglang/zig.git
synced 2026-02-15 13:58:27 +00:00
Merge pull request #3695 from daurnimator/towards-afd
Windows definitions
This commit is contained in:
commit
4dd3f42972
@ -226,3 +226,17 @@ pub const AF_TCNMESSAGE = 30;
|
||||
pub const AF_ICLFXBM = 31;
|
||||
pub const AF_BTH = 32;
|
||||
pub const AF_MAX = 33;
|
||||
|
||||
pub const SOCK_STREAM = 1;
|
||||
pub const SOCK_DGRAM = 2;
|
||||
pub const SOCK_RAW = 3;
|
||||
pub const SOCK_RDM = 4;
|
||||
pub const SOCK_SEQPACKET = 5;
|
||||
|
||||
pub const IPPROTO_ICMP = 1;
|
||||
pub const IPPROTO_IGMP = 2;
|
||||
pub const BTHPROTO_RFCOMM = 3;
|
||||
pub const IPPROTO_TCP = 6;
|
||||
pub const IPPROTO_UDP = 17;
|
||||
pub const IPPROTO_ICMPV6 = 58;
|
||||
pub const IPPROTO_RM = 113;
|
||||
|
||||
@ -16,6 +16,7 @@ pub const kernel32 = @import("windows/kernel32.zig");
|
||||
pub const ntdll = @import("windows/ntdll.zig");
|
||||
pub const ole32 = @import("windows/ole32.zig");
|
||||
pub const shell32 = @import("windows/shell32.zig");
|
||||
pub const ws2_32 = @import("windows/ws2_32.zig");
|
||||
|
||||
pub usingnamespace @import("windows/bits.zig");
|
||||
|
||||
@ -96,6 +97,42 @@ pub fn CreatePipe(rd: *HANDLE, wr: *HANDLE, sattr: *const SECURITY_ATTRIBUTES) C
|
||||
}
|
||||
}
|
||||
|
||||
pub fn DeviceIoControl(
|
||||
h: HANDLE,
|
||||
ioControlCode: DWORD,
|
||||
in: ?[]const u8,
|
||||
out: ?[]u8,
|
||||
overlapped: ?*OVERLAPPED,
|
||||
) !DWORD {
|
||||
var bytes: DWORD = undefined;
|
||||
if (kernel32.DeviceIoControl(
|
||||
h,
|
||||
ioControlCode,
|
||||
if (in) |i| i.ptr else null,
|
||||
if (in) |i| @intCast(u32, i.len) else 0,
|
||||
if (out) |o| o.ptr else null,
|
||||
if (out) |o| @intCast(u32, o.len) else 0,
|
||||
&bytes,
|
||||
overlapped,
|
||||
) == 0) {
|
||||
switch (kernel32.GetLastError()) {
|
||||
else => |err| return unexpectedError(err),
|
||||
}
|
||||
}
|
||||
return bytes;
|
||||
}
|
||||
|
||||
pub fn GetOverlappedResult(h: HANDLE, overlapped: *OVERLAPPED, wait: bool) !DWORD {
|
||||
var bytes: DWORD = undefined;
|
||||
if (kernel32.GetOverlappedResult(h, overlapped, &bytes, wait) == 0) {
|
||||
switch (kernel32.GetLastError()) {
|
||||
ERROR_IO_INCOMPLETE => if (!wait) return error.WouldBlock else unreachable,
|
||||
else => |err| return unexpectedError(err),
|
||||
}
|
||||
}
|
||||
return bytes;
|
||||
}
|
||||
|
||||
pub const SetHandleInformationError = error{Unexpected};
|
||||
|
||||
pub fn SetHandleInformation(h: HANDLE, mask: DWORD, flags: DWORD) SetHandleInformationError!void {
|
||||
@ -571,6 +608,74 @@ pub fn GetFileAttributesW(lpFileName: [*]const u16) GetFileAttributesError!DWORD
|
||||
return rc;
|
||||
}
|
||||
|
||||
pub fn WSAStartup(majorVersion: u8, minorVersion: u8) !ws2_32.WSADATA {
|
||||
var wsadata: ws2_32.WSADATA = undefined;
|
||||
return switch (ws2_32.WSAStartup((@as(WORD, minorVersion) << 8) | majorVersion, &wsadata)) {
|
||||
0 => wsadata,
|
||||
else => |err| unexpectedWSAError(err),
|
||||
};
|
||||
}
|
||||
|
||||
pub fn WSACleanup() !void {
|
||||
return switch (ws2_32.WSACleanup()) {
|
||||
0 => {},
|
||||
ws2_32.SOCKET_ERROR => switch (ws2_32.WSAGetLastError()) {
|
||||
else => |err| return unexpectedWSAError(err),
|
||||
},
|
||||
else => unreachable,
|
||||
};
|
||||
}
|
||||
|
||||
pub fn WSASocketW(
|
||||
af: i32,
|
||||
socket_type: i32,
|
||||
protocol: i32,
|
||||
protocolInfo: ?*ws2_32.WSAPROTOCOL_INFOW,
|
||||
g: ws2_32.GROUP,
|
||||
dwFlags: DWORD,
|
||||
) !ws2_32.SOCKET {
|
||||
const rc = ws2_32.WSASocketW(af, socket_type, protocol, protocolInfo, g, dwFlags);
|
||||
if (rc == ws2_32.INVALID_SOCKET) {
|
||||
switch (ws2_32.WSAGetLastError()) {
|
||||
ws2_32.WSAEAFNOSUPPORT => return error.AddressFamilyNotSupported,
|
||||
ws2_32.WSAEMFILE => return error.ProcessFdQuotaExceeded,
|
||||
ws2_32.WSAENOBUFS => return error.SystemResources,
|
||||
ws2_32.WSAEPROTONOSUPPORT => return error.ProtocolNotSupported,
|
||||
else => |err| return unexpectedWSAError(err),
|
||||
}
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
pub fn WSAIoctl(
|
||||
s: ws2_32.SOCKET,
|
||||
dwIoControlCode: DWORD,
|
||||
inBuffer: ?[]const u8,
|
||||
outBuffer: []u8,
|
||||
overlapped: ?*ws2_32.WSAOVERLAPPED,
|
||||
completionRoutine: ?*ws2_32.WSAOVERLAPPED_COMPLETION_ROUTINE,
|
||||
) !DWORD {
|
||||
var bytes: DWORD = undefined;
|
||||
switch (ws2_32.WSAIoctl(
|
||||
s,
|
||||
dwIoControlCode,
|
||||
if (inBuffer) |i| i.ptr else null,
|
||||
if (inBuffer) |i| @intCast(DWORD, i.len) else 0,
|
||||
outBuffer.ptr,
|
||||
@intCast(DWORD, outBuffer.len),
|
||||
&bytes,
|
||||
overlapped,
|
||||
completionRoutine,
|
||||
)) {
|
||||
0 => {},
|
||||
ws2_32.SOCKET_ERROR => switch (ws2_32.WSAGetLastError()) {
|
||||
else => |err| return unexpectedWSAError(err),
|
||||
},
|
||||
else => unreachable,
|
||||
}
|
||||
return bytes;
|
||||
}
|
||||
|
||||
const GetModuleFileNameError = error{Unexpected};
|
||||
|
||||
pub fn GetModuleFileNameW(hModule: ?HMODULE, buf_ptr: [*]u16, buf_len: DWORD) GetModuleFileNameError![]u16 {
|
||||
@ -868,6 +973,10 @@ pub fn unexpectedError(err: DWORD) std.os.UnexpectedError {
|
||||
return error.Unexpected;
|
||||
}
|
||||
|
||||
pub fn unexpectedWSAError(err: c_int) std.os.UnexpectedError {
|
||||
return unexpectedError(@intCast(DWORD, err));
|
||||
}
|
||||
|
||||
/// Call this when you made a windows NtDll call
|
||||
/// and you get an unexpected status.
|
||||
pub fn unexpectedStatus(status: NTSTATUS) std.os.UnexpectedError {
|
||||
|
||||
@ -67,6 +67,113 @@ pub const va_list = *@OpaqueType();
|
||||
pub const TRUE = 1;
|
||||
pub const FALSE = 0;
|
||||
|
||||
pub const DEVICE_TYPE = ULONG;
|
||||
pub const FILE_DEVICE_BEEP: DEVICE_TYPE = 0x0001;
|
||||
pub const FILE_DEVICE_CD_ROM: DEVICE_TYPE = 0x0002;
|
||||
pub const FILE_DEVICE_CD_ROM_FILE_SYSTEM: DEVICE_TYPE = 0x0003;
|
||||
pub const FILE_DEVICE_CONTROLLER: DEVICE_TYPE = 0x0004;
|
||||
pub const FILE_DEVICE_DATALINK: DEVICE_TYPE = 0x0005;
|
||||
pub const FILE_DEVICE_DFS: DEVICE_TYPE = 0x0006;
|
||||
pub const FILE_DEVICE_DISK: DEVICE_TYPE = 0x0007;
|
||||
pub const FILE_DEVICE_DISK_FILE_SYSTEM: DEVICE_TYPE = 0x0008;
|
||||
pub const FILE_DEVICE_FILE_SYSTEM: DEVICE_TYPE = 0x0009;
|
||||
pub const FILE_DEVICE_INPORT_PORT: DEVICE_TYPE = 0x000a;
|
||||
pub const FILE_DEVICE_KEYBOARD: DEVICE_TYPE = 0x000b;
|
||||
pub const FILE_DEVICE_MAILSLOT: DEVICE_TYPE = 0x000c;
|
||||
pub const FILE_DEVICE_MIDI_IN: DEVICE_TYPE = 0x000d;
|
||||
pub const FILE_DEVICE_MIDI_OUT: DEVICE_TYPE = 0x000e;
|
||||
pub const FILE_DEVICE_MOUSE: DEVICE_TYPE = 0x000f;
|
||||
pub const FILE_DEVICE_MULTI_UNC_PROVIDER: DEVICE_TYPE = 0x0010;
|
||||
pub const FILE_DEVICE_NAMED_PIPE: DEVICE_TYPE = 0x0011;
|
||||
pub const FILE_DEVICE_NETWORK: DEVICE_TYPE = 0x0012;
|
||||
pub const FILE_DEVICE_NETWORK_BROWSER: DEVICE_TYPE = 0x0013;
|
||||
pub const FILE_DEVICE_NETWORK_FILE_SYSTEM: DEVICE_TYPE = 0x0014;
|
||||
pub const FILE_DEVICE_NULL: DEVICE_TYPE = 0x0015;
|
||||
pub const FILE_DEVICE_PARALLEL_PORT: DEVICE_TYPE = 0x0016;
|
||||
pub const FILE_DEVICE_PHYSICAL_NETCARD: DEVICE_TYPE = 0x0017;
|
||||
pub const FILE_DEVICE_PRINTER: DEVICE_TYPE = 0x0018;
|
||||
pub const FILE_DEVICE_SCANNER: DEVICE_TYPE = 0x0019;
|
||||
pub const FILE_DEVICE_SERIAL_MOUSE_PORT: DEVICE_TYPE = 0x001a;
|
||||
pub const FILE_DEVICE_SERIAL_PORT: DEVICE_TYPE = 0x001b;
|
||||
pub const FILE_DEVICE_SCREEN: DEVICE_TYPE = 0x001c;
|
||||
pub const FILE_DEVICE_SOUND: DEVICE_TYPE = 0x001d;
|
||||
pub const FILE_DEVICE_STREAMS: DEVICE_TYPE = 0x001e;
|
||||
pub const FILE_DEVICE_TAPE: DEVICE_TYPE = 0x001f;
|
||||
pub const FILE_DEVICE_TAPE_FILE_SYSTEM: DEVICE_TYPE = 0x0020;
|
||||
pub const FILE_DEVICE_TRANSPORT: DEVICE_TYPE = 0x0021;
|
||||
pub const FILE_DEVICE_UNKNOWN: DEVICE_TYPE = 0x0022;
|
||||
pub const FILE_DEVICE_VIDEO: DEVICE_TYPE = 0x0023;
|
||||
pub const FILE_DEVICE_VIRTUAL_DISK: DEVICE_TYPE = 0x0024;
|
||||
pub const FILE_DEVICE_WAVE_IN: DEVICE_TYPE = 0x0025;
|
||||
pub const FILE_DEVICE_WAVE_OUT: DEVICE_TYPE = 0x0026;
|
||||
pub const FILE_DEVICE_8042_PORT: DEVICE_TYPE = 0x0027;
|
||||
pub const FILE_DEVICE_NETWORK_REDIRECTOR: DEVICE_TYPE = 0x0028;
|
||||
pub const FILE_DEVICE_BATTERY: DEVICE_TYPE = 0x0029;
|
||||
pub const FILE_DEVICE_BUS_EXTENDER: DEVICE_TYPE = 0x002a;
|
||||
pub const FILE_DEVICE_MODEM: DEVICE_TYPE = 0x002b;
|
||||
pub const FILE_DEVICE_VDM: DEVICE_TYPE = 0x002c;
|
||||
pub const FILE_DEVICE_MASS_STORAGE: DEVICE_TYPE = 0x002d;
|
||||
pub const FILE_DEVICE_SMB: DEVICE_TYPE = 0x002e;
|
||||
pub const FILE_DEVICE_KS: DEVICE_TYPE = 0x002f;
|
||||
pub const FILE_DEVICE_CHANGER: DEVICE_TYPE = 0x0030;
|
||||
pub const FILE_DEVICE_SMARTCARD: DEVICE_TYPE = 0x0031;
|
||||
pub const FILE_DEVICE_ACPI: DEVICE_TYPE = 0x0032;
|
||||
pub const FILE_DEVICE_DVD: DEVICE_TYPE = 0x0033;
|
||||
pub const FILE_DEVICE_FULLSCREEN_VIDEO: DEVICE_TYPE = 0x0034;
|
||||
pub const FILE_DEVICE_DFS_FILE_SYSTEM: DEVICE_TYPE = 0x0035;
|
||||
pub const FILE_DEVICE_DFS_VOLUME: DEVICE_TYPE = 0x0036;
|
||||
pub const FILE_DEVICE_SERENUM: DEVICE_TYPE = 0x0037;
|
||||
pub const FILE_DEVICE_TERMSRV: DEVICE_TYPE = 0x0038;
|
||||
pub const FILE_DEVICE_KSEC: DEVICE_TYPE = 0x0039;
|
||||
pub const FILE_DEVICE_FIPS: DEVICE_TYPE = 0x003a;
|
||||
pub const FILE_DEVICE_INFINIBAND: DEVICE_TYPE = 0x003b;
|
||||
// TODO: missing values?
|
||||
pub const FILE_DEVICE_VMBUS: DEVICE_TYPE = 0x003e;
|
||||
pub const FILE_DEVICE_CRYPT_PROVIDER: DEVICE_TYPE = 0x003f;
|
||||
pub const FILE_DEVICE_WPD: DEVICE_TYPE = 0x0040;
|
||||
pub const FILE_DEVICE_BLUETOOTH: DEVICE_TYPE = 0x0041;
|
||||
pub const FILE_DEVICE_MT_COMPOSITE: DEVICE_TYPE = 0x0042;
|
||||
pub const FILE_DEVICE_MT_TRANSPORT: DEVICE_TYPE = 0x0043;
|
||||
pub const FILE_DEVICE_BIOMETRIC: DEVICE_TYPE = 0x0044;
|
||||
pub const FILE_DEVICE_PMI: DEVICE_TYPE = 0x0045;
|
||||
pub const FILE_DEVICE_EHSTOR: DEVICE_TYPE = 0x0046;
|
||||
pub const FILE_DEVICE_DEVAPI: DEVICE_TYPE = 0x0047;
|
||||
pub const FILE_DEVICE_GPIO: DEVICE_TYPE = 0x0048;
|
||||
pub const FILE_DEVICE_USBEX: DEVICE_TYPE = 0x0049;
|
||||
pub const FILE_DEVICE_CONSOLE: DEVICE_TYPE = 0x0050;
|
||||
pub const FILE_DEVICE_NFP: DEVICE_TYPE = 0x0051;
|
||||
pub const FILE_DEVICE_SYSENV: DEVICE_TYPE = 0x0052;
|
||||
pub const FILE_DEVICE_VIRTUAL_BLOCK: DEVICE_TYPE = 0x0053;
|
||||
pub const FILE_DEVICE_POINT_OF_SERVICE: DEVICE_TYPE = 0x0054;
|
||||
pub const FILE_DEVICE_STORAGE_REPLICATION: DEVICE_TYPE = 0x0055;
|
||||
pub const FILE_DEVICE_TRUST_ENV: DEVICE_TYPE = 0x0056;
|
||||
pub const FILE_DEVICE_UCM: DEVICE_TYPE = 0x0057;
|
||||
pub const FILE_DEVICE_UCMTCPCI: DEVICE_TYPE = 0x0058;
|
||||
pub const FILE_DEVICE_PERSISTENT_MEMORY: DEVICE_TYPE = 0x0059;
|
||||
pub const FILE_DEVICE_NVDIMM: DEVICE_TYPE = 0x005a;
|
||||
pub const FILE_DEVICE_HOLOGRAPHIC: DEVICE_TYPE = 0x005b;
|
||||
pub const FILE_DEVICE_SDFXHCI: DEVICE_TYPE = 0x005c;
|
||||
|
||||
/// https://docs.microsoft.com/en-us/windows-hardware/drivers/kernel/buffer-descriptions-for-i-o-control-codes
|
||||
pub const TransferType = enum(u2) {
|
||||
METHOD_BUFFERED = 0,
|
||||
METHOD_IN_DIRECT = 1,
|
||||
METHOD_OUT_DIRECT = 2,
|
||||
METHOD_NEITHER = 3,
|
||||
};
|
||||
|
||||
pub const FILE_ANY_ACCESS = 0;
|
||||
pub const FILE_READ_ACCESS = 1;
|
||||
pub const FILE_WRITE_ACCESS = 2;
|
||||
|
||||
/// https://docs.microsoft.com/en-us/windows-hardware/drivers/kernel/defining-i-o-control-codes
|
||||
pub fn CTL_CODE(deviceType: u16, function: u12, method: TransferType, access: u2) DWORD {
|
||||
return (@as(DWORD, deviceType) << 16) |
|
||||
(@as(DWORD, access) << 14) |
|
||||
(@as(DWORD, function) << 2) |
|
||||
@enumToInt(method);
|
||||
}
|
||||
|
||||
pub const INVALID_HANDLE_VALUE = @intToPtr(HANDLE, maxInt(usize));
|
||||
|
||||
pub const INVALID_FILE_ATTRIBUTES = @as(DWORD, maxInt(DWORD));
|
||||
|
||||
@ -45,6 +45,17 @@ pub extern "kernel32" stdcallcc fn CreateIoCompletionPort(FileHandle: HANDLE, Ex
|
||||
|
||||
pub extern "kernel32" stdcallcc fn CreateThread(lpThreadAttributes: ?LPSECURITY_ATTRIBUTES, dwStackSize: SIZE_T, lpStartAddress: LPTHREAD_START_ROUTINE, lpParameter: ?LPVOID, dwCreationFlags: DWORD, lpThreadId: ?LPDWORD) ?HANDLE;
|
||||
|
||||
pub extern "kernel32" stdcallcc fn DeviceIoControl(
|
||||
h: HANDLE,
|
||||
dwIoControlCode: DWORD,
|
||||
lpInBuffer: ?*const c_void,
|
||||
nInBufferSize: DWORD,
|
||||
lpOutBuffer: ?LPVOID,
|
||||
nOutBufferSize: DWORD,
|
||||
lpBytesReturned: LPDWORD,
|
||||
lpOverlapped: ?*OVERLAPPED,
|
||||
) BOOL;
|
||||
|
||||
pub extern "kernel32" stdcallcc fn DeleteFileW(lpFileName: [*]const u16) BOOL;
|
||||
|
||||
pub extern "kernel32" stdcallcc fn DuplicateHandle(hSourceProcessHandle: HANDLE, hSourceHandle: HANDLE, hTargetProcessHandle: HANDLE, lpTargetHandle: *HANDLE, dwDesiredAccess: DWORD, bInheritHandle: BOOL, dwOptions: DWORD) BOOL;
|
||||
|
||||
@ -21,6 +21,18 @@ pub extern "NtDll" stdcallcc fn NtCreateFile(
|
||||
EaBuffer: ?*c_void,
|
||||
EaLength: ULONG,
|
||||
) NTSTATUS;
|
||||
pub extern "NtDll" stdcallcc fn NtDeviceIoControlFile(
|
||||
FileHandle: HANDLE,
|
||||
Event: ?HANDLE,
|
||||
ApcRoutine: ?*IO_APC_ROUTINE,
|
||||
ApcContext: usize,
|
||||
IoStatusBlock: *IO_STATUS_BLOCK,
|
||||
IoControlCode: ULONG,
|
||||
InputBuffer: ?*const c_void,
|
||||
InputBufferLength: ULONG,
|
||||
OutputBuffer: ?PVOID,
|
||||
OutputBufferLength: ULONG,
|
||||
) NTSTATUS;
|
||||
pub extern "NtDll" stdcallcc fn NtClose(Handle: HANDLE) NTSTATUS;
|
||||
pub extern "NtDll" stdcallcc fn RtlDosPathNameToNtPathName_U(
|
||||
DosPathName: [*]const u16,
|
||||
|
||||
257
lib/std/os/windows/ws2_32.zig
Normal file
257
lib/std/os/windows/ws2_32.zig
Normal file
@ -0,0 +1,257 @@
|
||||
usingnamespace @import("bits.zig");
|
||||
|
||||
pub const SOCKET = *@OpaqueType();
|
||||
pub const INVALID_SOCKET = @intToPtr(SOCKET, ~@as(usize, 0));
|
||||
pub const SOCKET_ERROR = -1;
|
||||
|
||||
pub const WSADESCRIPTION_LEN = 256;
|
||||
pub const WSASYS_STATUS_LEN = 128;
|
||||
|
||||
pub const WSADATA = if (usize.bit_count == u64.bit_count)
|
||||
extern struct {
|
||||
wVersion: WORD,
|
||||
wHighVersion: WORD,
|
||||
iMaxSockets: u16,
|
||||
iMaxUdpDg: u16,
|
||||
lpVendorInfo: *u8,
|
||||
szDescription: [WSADESCRIPTION_LEN + 1]u8,
|
||||
szSystemStatus: [WSASYS_STATUS_LEN + 1]u8,
|
||||
}
|
||||
else
|
||||
extern struct {
|
||||
wVersion: WORD,
|
||||
wHighVersion: WORD,
|
||||
szDescription: [WSADESCRIPTION_LEN + 1]u8,
|
||||
szSystemStatus: [WSASYS_STATUS_LEN + 1]u8,
|
||||
iMaxSockets: u16,
|
||||
iMaxUdpDg: u16,
|
||||
lpVendorInfo: *u8,
|
||||
};
|
||||
|
||||
pub const MAX_PROTOCOL_CHAIN = 7;
|
||||
|
||||
pub const WSAPROTOCOLCHAIN = extern struct {
|
||||
ChainLen: c_int,
|
||||
ChainEntries: [MAX_PROTOCOL_CHAIN]DWORD,
|
||||
};
|
||||
|
||||
pub const WSAPROTOCOL_LEN = 255;
|
||||
|
||||
pub const WSAPROTOCOL_INFOA = extern struct {
|
||||
dwServiceFlags1: DWORD,
|
||||
dwServiceFlags2: DWORD,
|
||||
dwServiceFlags3: DWORD,
|
||||
dwServiceFlags4: DWORD,
|
||||
dwProviderFlags: DWORD,
|
||||
ProviderId: GUID,
|
||||
dwCatalogEntryId: DWORD,
|
||||
ProtocolChain: WSAPROTOCOLCHAIN,
|
||||
iVersion: c_int,
|
||||
iAddressFamily: c_int,
|
||||
iMaxSockAddr: c_int,
|
||||
iMinSockAddr: c_int,
|
||||
iSocketType: c_int,
|
||||
iProtocol: c_int,
|
||||
iProtocolMaxOffset: c_int,
|
||||
iNetworkByteOrder: c_int,
|
||||
iSecurityScheme: c_int,
|
||||
dwMessageSize: DWORD,
|
||||
dwProviderReserved: DWORD,
|
||||
szProtocol: [WSAPROTOCOL_LEN + 1]CHAR,
|
||||
};
|
||||
|
||||
pub const WSAPROTOCOL_INFOW = extern struct {
|
||||
dwServiceFlags1: DWORD,
|
||||
dwServiceFlags2: DWORD,
|
||||
dwServiceFlags3: DWORD,
|
||||
dwServiceFlags4: DWORD,
|
||||
dwProviderFlags: DWORD,
|
||||
ProviderId: GUID,
|
||||
dwCatalogEntryId: DWORD,
|
||||
ProtocolChain: WSAPROTOCOLCHAIN,
|
||||
iVersion: c_int,
|
||||
iAddressFamily: c_int,
|
||||
iMaxSockAddr: c_int,
|
||||
iMinSockAddr: c_int,
|
||||
iSocketType: c_int,
|
||||
iProtocol: c_int,
|
||||
iProtocolMaxOffset: c_int,
|
||||
iNetworkByteOrder: c_int,
|
||||
iSecurityScheme: c_int,
|
||||
dwMessageSize: DWORD,
|
||||
dwProviderReserved: DWORD,
|
||||
szProtocol: [WSAPROTOCOL_LEN + 1]WCHAR,
|
||||
};
|
||||
|
||||
pub const GROUP = u32;
|
||||
|
||||
pub const SG_UNCONSTRAINED_GROUP = 0x1;
|
||||
pub const SG_CONSTRAINED_GROUP = 0x2;
|
||||
|
||||
pub const WSA_FLAG_OVERLAPPED = 0x01;
|
||||
pub const WSA_FLAG_MULTIPOINT_C_ROOT = 0x02;
|
||||
pub const WSA_FLAG_MULTIPOINT_C_LEAF = 0x04;
|
||||
pub const WSA_FLAG_MULTIPOINT_D_ROOT = 0x08;
|
||||
pub const WSA_FLAG_MULTIPOINT_D_LEAF = 0x10;
|
||||
pub const WSA_FLAG_ACCESS_SYSTEM_SECURITY = 0x40;
|
||||
pub const WSA_FLAG_NO_HANDLE_INHERIT = 0x80;
|
||||
|
||||
pub const WSAEVENT = HANDLE;
|
||||
|
||||
pub const WSAOVERLAPPED = extern struct {
|
||||
Internal: DWORD,
|
||||
InternalHigh: DWORD,
|
||||
Offset: DWORD,
|
||||
OffsetHigh: DWORD,
|
||||
hEvent: ?WSAEVENT,
|
||||
};
|
||||
|
||||
pub const WSAOVERLAPPED_COMPLETION_ROUTINE = extern fn (
|
||||
dwError: DWORD,
|
||||
cbTransferred: DWORD,
|
||||
lpOverlapped: *WSAOVERLAPPED,
|
||||
dwFlags: DWORD
|
||||
) void;
|
||||
|
||||
pub const WSA_INVALID_HANDLE = 6;
|
||||
pub const WSA_NOT_ENOUGH_MEMORY = 8;
|
||||
pub const WSA_INVALID_PARAMETER = 87;
|
||||
pub const WSA_OPERATION_ABORTED = 995;
|
||||
pub const WSA_IO_INCOMPLETE = 996;
|
||||
pub const WSA_IO_PENDING = 997;
|
||||
pub const WSAEINTR = 10004;
|
||||
pub const WSAEBADF = 10009;
|
||||
pub const WSAEACCES = 10013;
|
||||
pub const WSAEFAULT = 10014;
|
||||
pub const WSAEINVAL = 10022;
|
||||
pub const WSAEMFILE = 10024;
|
||||
pub const WSAEWOULDBLOCK = 10035;
|
||||
pub const WSAEINPROGRESS = 10036;
|
||||
pub const WSAEALREADY = 10037;
|
||||
pub const WSAENOTSOCK = 10038;
|
||||
pub const WSAEDESTADDRREQ = 10039;
|
||||
pub const WSAEMSGSIZE = 10040;
|
||||
pub const WSAEPROTOTYPE = 10041;
|
||||
pub const WSAENOPROTOOPT = 10042;
|
||||
pub const WSAEPROTONOSUPPORT = 10043;
|
||||
pub const WSAESOCKTNOSUPPORT = 10044;
|
||||
pub const WSAEOPNOTSUPP = 10045;
|
||||
pub const WSAEPFNOSUPPORT = 10046;
|
||||
pub const WSAEAFNOSUPPORT = 10047;
|
||||
pub const WSAEADDRINUSE = 10048;
|
||||
pub const WSAEADDRNOTAVAIL = 10049;
|
||||
pub const WSAENETDOWN = 10050;
|
||||
pub const WSAENETUNREACH = 10051;
|
||||
pub const WSAENETRESET = 10052;
|
||||
pub const WSAECONNABORTED = 10053;
|
||||
pub const WSAECONNRESET = 10054;
|
||||
pub const WSAENOBUFS = 10055;
|
||||
pub const WSAEISCONN = 10056;
|
||||
pub const WSAENOTCONN = 10057;
|
||||
pub const WSAESHUTDOWN = 10058;
|
||||
pub const WSAETOOMANYREFS = 10059;
|
||||
pub const WSAETIMEDOUT = 10060;
|
||||
pub const WSAECONNREFUSED = 10061;
|
||||
pub const WSAELOOP = 10062;
|
||||
pub const WSAENAMETOOLONG = 10063;
|
||||
pub const WSAEHOSTDOWN = 10064;
|
||||
pub const WSAEHOSTUNREACH = 10065;
|
||||
pub const WSAENOTEMPTY = 10066;
|
||||
pub const WSAEPROCLIM = 10067;
|
||||
pub const WSAEUSERS = 10068;
|
||||
pub const WSAEDQUOT = 10069;
|
||||
pub const WSAESTALE = 10070;
|
||||
pub const WSAEREMOTE = 10071;
|
||||
pub const WSASYSNOTREADY = 10091;
|
||||
pub const WSAVERNOTSUPPORTED = 10092;
|
||||
pub const WSANOTINITIALISED = 10093;
|
||||
pub const WSAEDISCON = 10101;
|
||||
pub const WSAENOMORE = 10102;
|
||||
pub const WSAECANCELLED = 10103;
|
||||
pub const WSAEINVALIDPROCTABLE = 10104;
|
||||
pub const WSAEINVALIDPROVIDER = 10105;
|
||||
pub const WSAEPROVIDERFAILEDINIT = 10106;
|
||||
pub const WSASYSCALLFAILURE = 10107;
|
||||
pub const WSASERVICE_NOT_FOUND = 10108;
|
||||
pub const WSATYPE_NOT_FOUND = 10109;
|
||||
pub const WSA_E_NO_MORE = 10110;
|
||||
pub const WSA_E_CANCELLED = 10111;
|
||||
pub const WSAEREFUSED = 10112;
|
||||
pub const WSAHOST_NOT_FOUND = 11001;
|
||||
pub const WSATRY_AGAIN = 11002;
|
||||
pub const WSANO_RECOVERY = 11003;
|
||||
pub const WSANO_DATA = 11004;
|
||||
pub const WSA_QOS_RECEIVERS = 11005;
|
||||
pub const WSA_QOS_SENDERS = 11006;
|
||||
pub const WSA_QOS_NO_SENDERS = 11007;
|
||||
pub const WSA_QOS_NO_RECEIVERS = 11008;
|
||||
pub const WSA_QOS_REQUEST_CONFIRMED = 11009;
|
||||
pub const WSA_QOS_ADMISSION_FAILURE = 11010;
|
||||
pub const WSA_QOS_POLICY_FAILURE = 11011;
|
||||
pub const WSA_QOS_BAD_STYLE = 11012;
|
||||
pub const WSA_QOS_BAD_OBJECT = 11013;
|
||||
pub const WSA_QOS_TRAFFIC_CTRL_ERROR = 11014;
|
||||
pub const WSA_QOS_GENERIC_ERROR = 11015;
|
||||
pub const WSA_QOS_ESERVICETYPE = 11016;
|
||||
pub const WSA_QOS_EFLOWSPEC = 11017;
|
||||
pub const WSA_QOS_EPROVSPECBUF = 11018;
|
||||
pub const WSA_QOS_EFILTERSTYLE = 11019;
|
||||
pub const WSA_QOS_EFILTERTYPE = 11020;
|
||||
pub const WSA_QOS_EFILTERCOUNT = 11021;
|
||||
pub const WSA_QOS_EOBJLENGTH = 11022;
|
||||
pub const WSA_QOS_EFLOWCOUNT = 11023;
|
||||
pub const WSA_QOS_EUNKOWNPSOBJ = 11024;
|
||||
pub const WSA_QOS_EPOLICYOBJ = 11025;
|
||||
pub const WSA_QOS_EFLOWDESC = 11026;
|
||||
pub const WSA_QOS_EPSFLOWSPEC = 11027;
|
||||
pub const WSA_QOS_EPSFILTERSPEC = 11028;
|
||||
pub const WSA_QOS_ESDMODEOBJ = 11029;
|
||||
pub const WSA_QOS_ESHAPERATEOBJ = 11030;
|
||||
pub const WSA_QOS_RESERVED_PETYPE = 11031;
|
||||
|
||||
|
||||
/// no parameters
|
||||
const IOC_VOID = 0x80000000;
|
||||
/// copy out parameters
|
||||
const IOC_OUT = 0x40000000;
|
||||
/// copy in parameters
|
||||
const IOC_IN = 0x80000000;
|
||||
|
||||
/// The IOCTL is a generic Windows Sockets 2 IOCTL code. New IOCTL codes defined for Windows Sockets 2 will have T == 1.
|
||||
const IOC_WS2 = 0x08000000;
|
||||
|
||||
pub const SIO_BASE_HANDLE = IOC_OUT | IOC_WS2 | 34;
|
||||
|
||||
pub extern "ws2_32" stdcallcc fn WSAStartup(
|
||||
wVersionRequired: WORD,
|
||||
lpWSAData: *WSADATA,
|
||||
) c_int;
|
||||
pub extern "ws2_32" stdcallcc fn WSACleanup() c_int;
|
||||
pub extern "ws2_32" stdcallcc fn WSAGetLastError() c_int;
|
||||
pub extern "ws2_32" stdcallcc fn WSASocketA(
|
||||
af: c_int,
|
||||
type: c_int,
|
||||
protocol: c_int,
|
||||
lpProtocolInfo: ?*WSAPROTOCOL_INFOA,
|
||||
g: GROUP,
|
||||
dwFlags: DWORD,
|
||||
) SOCKET;
|
||||
pub extern "ws2_32" stdcallcc fn WSASocketW(
|
||||
af: c_int,
|
||||
type: c_int,
|
||||
protocol: c_int,
|
||||
lpProtocolInfo: ?*WSAPROTOCOL_INFOW,
|
||||
g: GROUP,
|
||||
dwFlags: DWORD,
|
||||
) SOCKET;
|
||||
pub extern "ws2_32" stdcallcc fn WSAIoctl(
|
||||
s: SOCKET,
|
||||
dwIoControlCode: DWORD,
|
||||
lpvInBuffer: ?*const c_void,
|
||||
cbInBuffer: DWORD,
|
||||
lpvOutBuffer: ?LPVOID,
|
||||
cbOutBuffer: DWORD,
|
||||
lpcbBytesReturned: LPDWORD,
|
||||
lpOverlapped: ?*WSAOVERLAPPED,
|
||||
lpCompletionRoutine: ?*WSAOVERLAPPED_COMPLETION_ROUTINE,
|
||||
) c_int;
|
||||
Loading…
x
Reference in New Issue
Block a user