Skip to content

Commit 19f2657

Browse files
committed
std: windows sockaddr constants come from ws2_32
1 parent 8aa3d60 commit 19f2657

File tree

2 files changed

+150
-72
lines changed

2 files changed

+150
-72
lines changed

lib/std/os/bits/windows.zig

Lines changed: 56 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// The reference for these types and values is Microsoft Windows's ucrt (Universal C RunTime).
22

33
usingnamespace @import("../windows/bits.zig");
4+
const ws2_32 = @import("../windows/ws2_32.zig");
45

56
pub const fd_t = HANDLE;
67
pub const pid_t = HANDLE;
@@ -163,80 +164,63 @@ pub const F_OK = 0;
163164
pub const AT_REMOVEDIR = 0x200;
164165

165166
pub const in_port_t = u16;
166-
pub const sa_family_t = u16;
167+
pub const sa_family_t = ws2_32.ADDRESS_FAMILY;
167168
pub const socklen_t = u32;
168169

169-
pub const sockaddr = extern struct {
170-
family: sa_family_t,
171-
data: [14]u8,
172-
};
173-
pub const sockaddr_in = extern struct {
174-
family: sa_family_t = AF_INET,
175-
port: in_port_t,
176-
addr: in_addr,
177-
zero: [8]u8 = [8]u8{ 0, 0, 0, 0, 0, 0, 0, 0 },
178-
};
179-
pub const sockaddr_in6 = extern struct {
180-
family: sa_family_t = AF_INET6,
181-
port: in_port_t,
182-
flowinfo: u32,
183-
addr: in6_addr,
184-
scope_id: u32,
185-
};
170+
pub const sockaddr = ws2_32.sockaddr;
171+
pub const sockaddr_in = ws2_32.sockaddr_in;
172+
pub const sockaddr_in6 = ws2_32.sockaddr_in6;
173+
pub const sockaddr_un = ws2_32.sockaddr_un;
174+
186175
pub const in6_addr = [16]u8;
187176
pub const in_addr = u32;
188177

189-
pub const sockaddr_un = extern struct {
190-
family: sa_family_t = AF_UNIX,
191-
path: [108]u8,
192-
};
193-
194-
pub const AF_UNSPEC = 0;
195-
pub const AF_UNIX = 1;
196-
pub const AF_INET = 2;
197-
pub const AF_IMPLINK = 3;
198-
pub const AF_PUP = 4;
199-
pub const AF_CHAOS = 5;
200-
pub const AF_NS = 6;
201-
pub const AF_IPX = AF_NS;
202-
pub const AF_ISO = 7;
203-
pub const AF_OSI = AF_ISO;
204-
pub const AF_ECMA = 8;
205-
pub const AF_DATAKIT = 9;
206-
pub const AF_CCITT = 10;
207-
pub const AF_SNA = 11;
208-
pub const AF_DECnet = 12;
209-
pub const AF_DLI = 13;
210-
pub const AF_LAT = 14;
211-
pub const AF_HYLINK = 15;
212-
pub const AF_APPLETALK = 16;
213-
pub const AF_NETBIOS = 17;
214-
pub const AF_VOICEVIEW = 18;
215-
pub const AF_FIREFOX = 19;
216-
pub const AF_UNKNOWN1 = 20;
217-
pub const AF_BAN = 21;
218-
pub const AF_ATM = 22;
219-
pub const AF_INET6 = 23;
220-
pub const AF_CLUSTER = 24;
221-
pub const AF_12844 = 25;
222-
pub const AF_IRDA = 26;
223-
pub const AF_NETDES = 28;
224-
pub const AF_TCNPROCESS = 29;
225-
pub const AF_TCNMESSAGE = 30;
226-
pub const AF_ICLFXBM = 31;
227-
pub const AF_BTH = 32;
228-
pub const AF_MAX = 33;
229-
230-
pub const SOCK_STREAM = 1;
231-
pub const SOCK_DGRAM = 2;
232-
pub const SOCK_RAW = 3;
233-
pub const SOCK_RDM = 4;
234-
pub const SOCK_SEQPACKET = 5;
235-
236-
pub const IPPROTO_ICMP = 1;
237-
pub const IPPROTO_IGMP = 2;
238-
pub const BTHPROTO_RFCOMM = 3;
239-
pub const IPPROTO_TCP = 6;
240-
pub const IPPROTO_UDP = 17;
241-
pub const IPPROTO_ICMPV6 = 58;
242-
pub const IPPROTO_RM = 113;
178+
pub const AF_UNSPEC = ws2_32.AF_UNSPEC;
179+
pub const AF_UNIX = ws2_32.AF_UNIX;
180+
pub const AF_INET = ws2_32.AF_INET;
181+
pub const AF_IMPLINK = ws2_32.AF_IMPLINK;
182+
pub const AF_PUP = ws2_32.AF_PUP;
183+
pub const AF_CHAOS = ws2_32.AF_CHAOS;
184+
pub const AF_NS = ws2_32.AF_NS;
185+
pub const AF_IPX = ws2_32.AF_IPX;
186+
pub const AF_ISO = ws2_32.AF_ISO;
187+
pub const AF_OSI = ws2_32.AF_OSI;
188+
pub const AF_ECMA = ws2_32.AF_ECMA;
189+
pub const AF_DATAKIT = ws2_32.AF_DATAKIT;
190+
pub const AF_CCITT = ws2_32.AF_CCITT;
191+
pub const AF_SNA = ws2_32.AF_SNA;
192+
pub const AF_DECnet = ws2_32.AF_DECnet;
193+
pub const AF_DLI = ws2_32.AF_DLI;
194+
pub const AF_LAT = ws2_32.AF_LAT;
195+
pub const AF_HYLINK = ws2_32.AF_HYLINK;
196+
pub const AF_APPLETALK = ws2_32.AF_APPLETALK;
197+
pub const AF_NETBIOS = ws2_32.AF_NETBIOS;
198+
pub const AF_VOICEVIEW = ws2_32.AF_VOICEVIEW;
199+
pub const AF_FIREFOX = ws2_32.AF_FIREFOX;
200+
pub const AF_UNKNOWN1 = ws2_32.AF_UNKNOWN1;
201+
pub const AF_BAN = ws2_32.AF_BAN;
202+
pub const AF_ATM = ws2_32.AF_ATM;
203+
pub const AF_INET6 = ws2_32.AF_INET6;
204+
pub const AF_CLUSTER = ws2_32.AF_CLUSTER;
205+
pub const AF_12844 = ws2_32.AF_12844;
206+
pub const AF_IRDA = ws2_32.AF_IRDA;
207+
pub const AF_NETDES = ws2_32.AF_NETDES;
208+
pub const AF_TCNPROCESS = ws2_32.AF_TCNPROCESS;
209+
pub const AF_TCNMESSAGE = ws2_32.AF_TCNMESSAGE;
210+
pub const AF_ICLFXBM = ws2_32.AF_ICLFXBM;
211+
pub const AF_BTH = ws2_32.AF_BTH;
212+
pub const AF_MAX = ws2_32.AF_MAX;
213+
214+
pub const SOCK_STREAM = ws2_32.SOCK_STREAM;
215+
pub const SOCK_DGRAM = ws2_32.SOCK_DGRAM;
216+
pub const SOCK_RAW = ws2_32.SOCK_RAW;
217+
pub const SOCK_RDM = ws2_32.SOCK_RDM;
218+
pub const SOCK_SEQPACKET = ws2_32.SOCK_SEQPACKET;
219+
220+
pub const IPPROTO_ICMP = ws2_32.IPPROTO_ICMP;
221+
pub const IPPROTO_IGMP = ws2_32.IPPROTO_IGMP;
222+
pub const BTHPROTO_RFCOMM = ws2_32.BTHPROTO_RFCOMM;
223+
pub const IPPROTO_TCP = ws2_32.IPPROTO_TCP;
224+
pub const IPPROTO_UDP = ws2_32.IPPROTO_UDP;
225+
pub const IPPROTO_ICMPV6 = ws2_32.IPPROTO_ICMPV6;
226+
pub const IPPROTO_RM = ws2_32.IPPROTO_RM;

lib/std/os/windows/ws2_32.zig

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,100 @@ pub const WSAOVERLAPPED = extern struct {
108108

109109
pub const WSAOVERLAPPED_COMPLETION_ROUTINE = extern fn (dwError: DWORD, cbTransferred: DWORD, lpOverlapped: *WSAOVERLAPPED, dwFlags: DWORD) void;
110110

111+
pub const ADDRESS_FAMILY = u16;
112+
113+
pub const AF_UNSPEC = 0;
114+
pub const AF_UNIX = 1;
115+
pub const AF_INET = 2;
116+
pub const AF_IMPLINK = 3;
117+
pub const AF_PUP = 4;
118+
pub const AF_CHAOS = 5;
119+
pub const AF_NS = 6;
120+
pub const AF_IPX = AF_NS;
121+
pub const AF_ISO = 7;
122+
pub const AF_OSI = AF_ISO;
123+
pub const AF_ECMA = 8;
124+
pub const AF_DATAKIT = 9;
125+
pub const AF_CCITT = 10;
126+
pub const AF_SNA = 11;
127+
pub const AF_DECnet = 12;
128+
pub const AF_DLI = 13;
129+
pub const AF_LAT = 14;
130+
pub const AF_HYLINK = 15;
131+
pub const AF_APPLETALK = 16;
132+
pub const AF_NETBIOS = 17;
133+
pub const AF_VOICEVIEW = 18;
134+
pub const AF_FIREFOX = 19;
135+
pub const AF_UNKNOWN1 = 20;
136+
pub const AF_BAN = 21;
137+
pub const AF_ATM = 22;
138+
pub const AF_INET6 = 23;
139+
pub const AF_CLUSTER = 24;
140+
pub const AF_12844 = 25;
141+
pub const AF_IRDA = 26;
142+
pub const AF_NETDES = 28;
143+
pub const AF_TCNPROCESS = 29;
144+
pub const AF_TCNMESSAGE = 30;
145+
pub const AF_ICLFXBM = 31;
146+
pub const AF_BTH = 32;
147+
pub const AF_MAX = 33;
148+
149+
pub const SOCK_STREAM = 1;
150+
pub const SOCK_DGRAM = 2;
151+
pub const SOCK_RAW = 3;
152+
pub const SOCK_RDM = 4;
153+
pub const SOCK_SEQPACKET = 5;
154+
155+
pub const IPPROTO_ICMP = 1;
156+
pub const IPPROTO_IGMP = 2;
157+
pub const BTHPROTO_RFCOMM = 3;
158+
pub const IPPROTO_TCP = 6;
159+
pub const IPPROTO_UDP = 17;
160+
pub const IPPROTO_ICMPV6 = 58;
161+
pub const IPPROTO_RM = 113;
162+
163+
pub const sockaddr = extern struct {
164+
family: ADDRESS_FAMILY,
165+
data: [14]u8,
166+
};
167+
168+
/// IPv4 socket address
169+
pub const sockaddr_in = extern struct {
170+
family: ADDRESS_FAMILY = AF_INET,
171+
port: USHORT,
172+
addr: u32,
173+
zero: [8]u8 = [8]u8{ 0, 0, 0, 0, 0, 0, 0, 0 },
174+
};
175+
176+
/// IPv6 socket address
177+
pub const sockaddr_in6 = extern struct {
178+
family: ADDRESS_FAMILY = AF_INET6,
179+
port: USHORT,
180+
flowinfo: u32,
181+
addr: [16]u8,
182+
scope_id: u32,
183+
};
184+
185+
/// UNIX domain socket address
186+
pub const sockaddr_un = extern struct {
187+
family: ADDRESS_FAMILY = AF_UNIX,
188+
path: [108]u8,
189+
};
190+
191+
pub const WSABUF = extern struct {
192+
len: ULONG,
193+
buf: [*]u8,
194+
};
195+
196+
pub const WSAMSG = extern struct {
197+
name: *const sockaddr,
198+
namelen: INT,
199+
lpBuffers: [*]WSABUF,
200+
dwBufferCount: DWORD,
201+
Control: WSABUF,
202+
dwFlags: DWORD,
203+
};
204+
111205
pub const WSA_INVALID_HANDLE = 6;
112206
pub const WSA_NOT_ENOUGH_MEMORY = 8;
113207
pub const WSA_INVALID_PARAMETER = 87;

0 commit comments

Comments
 (0)