Skip to content

Commit 1fd39e7

Browse files
committed
WIP: replace hardcoded socket consts with value from libc
1 parent 73159fd commit 1fd39e7

File tree

1 file changed

+84
-79
lines changed

1 file changed

+84
-79
lines changed

src/sys/socket/consts.rs

Lines changed: 84 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -8,139 +8,148 @@ mod os {
88
pub const AF_INET: c_int = libc::AF_INET;
99
pub const AF_INET6: c_int = libc::AF_INET6;
1010
#[cfg(any(target_os = "linux", target_os = "android"))]
11-
pub const AF_NETLINK: c_int = libc::AF_NETLINK;
11+
pub const AF_NETLINK: c_int = libc::AF_NETLINK; //--
1212
#[cfg(any(target_os = "linux", target_os = "android"))]
13-
pub const AF_PACKET: c_int = libc::AF_PACKET;
13+
pub const AF_PACKET: c_int = libc::AF_PACKET; //--
1414
#[cfg(any(target_os = "macos", target_os = "ios"))]
15-
pub const AF_SYSTEM: c_int = libc::AF_SYSTEM;
15+
pub const AF_SYSTEM: c_int = libc::AF_SYSTEM; //--
1616
#[cfg(any(target_os = "macos", target_os = "ios"))]
17-
pub const AF_SYS_CONTROL: c_int = 2;
17+
pub const AF_SYS_CONTROL: c_int = 2; //--
1818

1919
pub const SOCK_STREAM: c_int = libc::SOCK_STREAM;
2020
pub const SOCK_DGRAM: c_int = libc::SOCK_DGRAM;
2121
pub const SOCK_SEQPACKET: c_int = libc::SOCK_SEQPACKET;
2222
pub const SOCK_RAW: c_int = libc::SOCK_RAW;
23-
#[cfg(not(any(target_os = "linux", target_os = "android")))]
24-
pub const SOCK_RDM: c_int = libc::SOCK_RDM;
23+
#[cfg(any(target_os = "macos",
24+
target_os = "freebsd",
25+
target_os = "ios",
26+
target_os = "openbsd",
27+
target_os = "netbsd",
28+
target_os = "dragonfly"))]
29+
pub const SOCK_RDM: c_int = libc::SOCK_RDM; //--
2530
#[cfg(any(target_os = "linux", target_os = "android"))]
26-
pub const SOCK_RDM: c_int = 4;
31+
pub const SOCK_RDM: c_int = 4; //--
2732

2833
#[cfg(any(target_os = "linux", target_os = "android"))]
29-
pub const SOL_IP: c_int = libc::SOL_IP;
34+
pub const SOL_IP: c_int = libc::SOL_IP; //--
3035
pub const SOL_SOCKET: c_int = libc::SOL_SOCKET;
3136
#[cfg(any(target_os = "linux", target_os = "android"))]
32-
pub const SOL_TCP: c_int = libc::SOL_TCP;
37+
pub const SOL_TCP: c_int = libc::SOL_TCP; //--
3338
#[cfg(any(target_os = "linux", target_os = "android"))]
34-
pub const SOL_UDP: c_int = 17;
39+
pub const SOL_UDP: c_int = 17; //--
3540
#[cfg(any(target_os = "linux", target_os = "android"))]
36-
pub const SOL_IPV6: c_int = libc::SOL_IPV6;
41+
pub const SOL_IPV6: c_int = libc::SOL_IPV6; //--
3742
#[cfg(any(target_os = "linux", target_os = "android"))]
38-
pub const SOL_NETLINK: c_int = libc::SOL_NETLINK;
43+
pub const SOL_NETLINK: c_int = libc::SOL_NETLINK; //--
3944
pub const IPPROTO_IP: c_int = libc::IPPROTO_IP;
4045
pub const IPPROTO_IPV6: c_int = libc::IPPROTO_IPV6;
4146
pub const IPPROTO_TCP: c_int = libc::IPPROTO_TCP;
4247
#[cfg(any(target_os = "linux", target_os = "android", target_os = "dragonfly"))]
43-
pub const IPPROTO_UDP: c_int = SOL_UDP;
48+
pub const IPPROTO_UDP: c_int = SOL_UDP; //--
4449
#[cfg(any(target_os = "macos",
4550
target_os = "freebsd",
4651
target_os = "ios",
4752
target_os = "openbsd",
4853
target_os = "netbsd"))]
49-
pub const IPPROTO_UDP: c_int = 17;
54+
pub const IPPROTO_UDP: c_int = 17; //--
5055
#[cfg(any(target_os = "macos", target_os = "ios"))]
51-
pub const SYSPROTO_CONTROL: c_int = 2;
56+
pub const SYSPROTO_CONTROL: c_int = 2; //--
5257

5358
pub const SO_ACCEPTCONN: c_int = libc::SO_ACCEPTCONN;
5459
#[cfg(any(target_os = "linux", target_os = "android"))]
55-
pub const SO_BINDTODEVICE: c_int = libc::SO_BINDTODEVICE;
60+
pub const SO_BINDTODEVICE: c_int = libc::SO_BINDTODEVICE; //--
5661
pub const SO_BROADCAST: c_int = libc::SO_BROADCAST;
5762
#[cfg(any(target_os = "linux", target_os = "android"))]
58-
pub const SO_BSDCOMPAT: c_int = libc::SO_BSDCOMPAT;
63+
pub const SO_BSDCOMPAT: c_int = libc::SO_BSDCOMPAT; //--
5964
#[cfg(any(target_os = "linux", target_os = "android"))]
60-
pub const SO_BUSY_POLL: c_int = libc::SO_BUSY_POLL;
65+
pub const SO_BUSY_POLL: c_int = libc::SO_BUSY_POLL; //--
6166
pub const SO_DEBUG: c_int = libc::SO_DEBUG;
6267
#[cfg(any(target_os = "linux", target_os = "android"))]
63-
pub const SO_DOMAIN: c_int = libc::SO_DOMAIN;
68+
pub const SO_DOMAIN: c_int = libc::SO_DOMAIN; //--
6469
pub const SO_DONTROUTE: c_int = libc::SO_DONTROUTE;
65-
#[cfg(not(target_os = "netbsd"))]
66-
pub const SO_DONTTRUNC: c_int = 0x2000;
70+
#[cfg(not(target_os = "netbsd"))] //--
71+
pub const SO_DONTTRUNC: c_int = 0x2000; //--
6772
pub const SO_ERROR: c_int = libc::SO_ERROR;
6873
pub const SO_KEEPALIVE: c_int = libc::SO_KEEPALIVE;
6974
#[cfg(any(target_os = "macos",
7075
target_os = "freebsd",
7176
target_os = "ios",
7277
target_os = "openbsd",
7378
target_os = "netbsd"))]
74-
pub const SO_LABEL: c_int = 0x1010;
79+
pub const SO_LABEL: c_int = 0x1010; //--
7580
pub const SO_LINGER: c_int = libc::SO_LINGER;
7681
#[cfg(any(target_os = "linux", target_os = "android"))]
77-
pub const SO_MARK: c_int = libc::SO_MARK;
82+
pub const SO_MARK: c_int = libc::SO_MARK; //--
7883
#[cfg(any(target_os = "macos",
7984
target_os = "freebsd",
8085
target_os = "ios",
8186
target_os = "openbsd",
8287
target_os = "netbsd"))]
83-
pub const SO_NREAD: c_int = 0x1020;
88+
pub const SO_NREAD: c_int = 0x1020; //--
8489
#[cfg(any(target_os = "macos",
8590
target_os = "freebsd",
8691
target_os = "ios",
8792
target_os = "openbsd",
8893
target_os = "netbsd"))]
89-
pub const SO_NKE: c_int = 0x1021;
90-
#[cfg(target_os = "dragonfly")]
91-
pub const SO_NOSIGPIPE: c_int = libc::SO_NOSIGPIPE;
92-
#[cfg(any(target_os = "macos",
94+
pub const SO_NKE: c_int = 0x1021; //--
95+
#[cfg(any(target_os = "dragonfly",
9396
target_os = "freebsd",
94-
target_os = "ios",
95-
target_os = "openbsd",
97+
target_os = "macos",
98+
target_os = "ios"))]
99+
pub const SO_NOSIGPIPE: c_int = libc::SO_NOSIGPIPE; //--
100+
#[cfg(any(target_os = "openbsd",
96101
target_os = "netbsd"))]
97-
pub const SO_NOSIGPIPE: c_int = 0x1022;
102+
pub const SO_NOSIGPIPE: c_int = 0x1022; //--
98103
#[cfg(any(target_os = "macos",
99-
target_os = "freebsd",
100-
target_os = "ios",
104+
target_os = "ios"))]
105+
pub const SO_NOADDRERR: c_int = libc::SO_NOADDRERR; //--
106+
#[cfg(any(target_os = "freebsd",
101107
target_os = "openbsd",
102108
target_os = "netbsd"))]
103-
pub const SO_NOADDRERR: c_int = 0x1023;
109+
pub const SO_NOADDRERR: c_int = 0x1023; //--
104110
#[cfg(any(target_os = "macos",
105111
target_os = "freebsd",
106112
target_os = "ios",
107113
target_os = "openbsd",
108114
target_os = "netbsd"))]
109-
pub const SO_NOTIFYCONFLICT: c_int = 0x1026;
115+
pub const SO_NOTIFYCONFLICT: c_int = 0x1026; //--
110116
#[cfg(any(target_os = "macos",
111117
target_os = "freebsd",
112118
target_os = "ios",
113119
target_os = "openbsd",
114120
target_os = "netbsd"))]
115-
pub const SO_NP_EXTENSIONS: c_int = 0x1083;
121+
pub const SO_NP_EXTENSIONS: c_int = 0x1083; //--
116122
#[cfg(any(target_os = "macos",
117-
target_os = "freebsd",
118-
target_os = "ios",
123+
target_os = "ios"))]
124+
pub const SO_NWRITE: c_int = libc::SO_NWRITE; //--
125+
#[cfg(any(target_os = "freebsd",
119126
target_os = "openbsd",
120127
target_os = "netbsd"))]
121-
pub const SO_NWRITE: c_int = 0x1024;
128+
pub const SO_NWRITE: c_int = 0x1024; //--
122129
pub const SO_OOBINLINE: c_int = libc::SO_OOBINLINE;
123130
#[cfg(target_os = "linux")]
124-
pub const SO_ORIGINAL_DST: c_int = 80;
131+
pub const SO_ORIGINAL_DST: c_int = 80; //--
125132
#[cfg(any(target_os = "linux", target_os = "android"))]
126-
pub const SO_PASSCRED: c_int = libc::SO_PASSCRED;
133+
pub const SO_PASSCRED: c_int = libc::SO_PASSCRED; //--
127134
#[cfg(any(target_os = "linux", target_os = "android"))]
128-
pub const SO_PEEK_OFF: c_int = libc::SO_PEEK_OFF;
129-
#[cfg(any(target_os = "linux", target_os = "android"))]
130-
pub const SO_PEERCRED: c_int = libc::SO_PEERCRED;
135+
pub const SO_PEEK_OFF: c_int = libc::SO_PEEK_OFF; //--
136+
#[cfg(any(target_os = "linux",
137+
target_os = "android",
138+
target_os = "openbsd"))]
139+
pub const SO_PEERCRED: c_int = libc::SO_PEERCRED; //--
131140
#[cfg(any(target_os = "macos",
132141
target_os = "freebsd",
133142
target_os = "ios",
134143
target_os = "openbsd",
135144
target_os = "netbsd"))]
136-
pub const SO_PEERLABEL: c_int = 0x1011;
145+
pub const SO_PEERLABEL: c_int = 0x1011; //--
137146
#[cfg(any(target_os = "linux", target_os = "android"))]
138-
pub const SO_PRIORITY: c_int = libc::SO_PRIORITY;
147+
pub const SO_PRIORITY: c_int = libc::SO_PRIORITY; //--
139148
#[cfg(any(target_os = "linux", target_os = "android"))]
140-
pub const SO_PROTOCOL: c_int = libc::SO_PROTOCOL;
149+
pub const SO_PROTOCOL: c_int = libc::SO_PROTOCOL; //--
141150
pub const SO_RCVBUF: c_int = libc::SO_RCVBUF;
142151
#[cfg(any(target_os = "linux", target_os = "android"))]
143-
pub const SO_RCVBUFFORCE: c_int = 33;
152+
pub const SO_RCVBUFFORCE: c_int = 33; //--
144153
pub const SO_RCVLOWAT: c_int = libc::SO_RCVLOWAT;
145154
pub const SO_SNDLOWAT: c_int = libc::SO_SNDLOWAT;
146155
pub const SO_RCVTIMEO: c_int = libc::SO_RCVTIMEO;
@@ -150,94 +159,95 @@ mod os {
150159
target_os = "ios",
151160
target_os = "openbsd",
152161
target_os = "netbsd"))]
153-
pub const SO_RANDOMPORT: c_int = 0x1082;
162+
pub const SO_RANDOMPORT: c_int = 0x1082; //--
154163
#[cfg(any(target_os = "macos",
155164
target_os = "freebsd",
156165
target_os = "ios",
157166
target_os = "openbsd",
158167
target_os = "netbsd"))]
159-
pub const SO_RESTRICTIONS: c_int = 0x1081;
168+
pub const SO_RESTRICTIONS: c_int = 0x1081; //--
160169
#[cfg(any(target_os = "macos",
161170
target_os = "freebsd",
162171
target_os = "ios",
163172
target_os = "openbsd",
164173
target_os = "netbsd"))]
165-
pub const SO_RESTRICT_DENYIN: c_int = 0x00000001;
174+
pub const SO_RESTRICT_DENYIN: c_int = 0x00000001; //--
166175
#[cfg(any(target_os = "macos",
167176
target_os = "freebsd",
168177
target_os = "ios",
169178
target_os = "openbsd",
170179
target_os = "netbsd"))]
171-
pub const SO_RESTRICT_DENYOUT: c_int = 0x00000002;
180+
pub const SO_RESTRICT_DENYOUT: c_int = 0x00000002; //--
172181
#[cfg(any(target_os = "macos",
173182
target_os = "freebsd",
174183
target_os = "ios",
175184
target_os = "openbsd",
176185
target_os = "netbsd"))]
177186
#[allow(overflowing_literals)]
178-
pub const SO_RESTRICT_DENYSET: c_int = 0x80000000;
187+
pub const SO_RESTRICT_DENYSET: c_int = 0x80000000; //--
179188
pub const SO_REUSEADDR: c_int = libc::SO_REUSEADDR;
180189
pub const SO_REUSEPORT: c_int = libc::SO_REUSEPORT;
181190
#[cfg(any(target_os = "macos",
182191
target_os = "freebsd",
183192
target_os = "ios",
184193
target_os = "openbsd",
185194
target_os = "netbsd"))]
186-
pub const SO_REUSESHAREUID: c_int = 0x1025;
195+
pub const SO_REUSESHAREUID: c_int = 0x1025; //--
187196
#[cfg(any(target_os = "linux", target_os = "android"))]
188197
pub const SO_RXQ_OVFL: c_int = libc::SO_RXQ_OVFL;
189198
pub const SO_SNDBUF: c_int = libc::SO_SNDBUF;
190199
#[cfg(any(target_os = "linux", target_os = "android"))]
191200
pub const SO_SNDBUFFORCE: c_int = libc::SO_SNDBUFFORCE;
192201
pub const SO_TIMESTAMP: c_int = libc::SO_TIMESTAMP;
193-
#[cfg(not(target_os = "netbsd"))]
194-
pub const SO_TIMESTAMP_MONOTONIC: c_int = 0x0800;
202+
#[cfg(not(target_os = "netbsd"))] //--
203+
pub const SO_TIMESTAMP_MONOTONIC: c_int = 0x0800; //--
195204
pub const SO_TYPE: c_int = libc::SO_TYPE;
196205
#[cfg(any(target_os = "macos",
197206
target_os = "freebsd",
198207
target_os = "ios",
199208
target_os = "openbsd",
200-
target_os = "netbsd"))]
201-
pub const SO_USELOOPBACK: c_int = libc::SO_USELOOPBACK;
202-
#[cfg(not(target_os = "netbsd"))]
203-
pub const SO_WANTMORE: c_int = 0x4000;
209+
target_os = "netbsd",
210+
target_os = "dragonfly"))]
211+
pub const SO_USELOOPBACK: c_int = libc::SO_USELOOPBACK; //--
212+
#[cfg(not(target_os = "netbsd"))] //--
213+
pub const SO_WANTMORE: c_int = 0x4000; //--
204214
#[cfg(any(target_os = "macos",
205215
target_os = "freebsd",
206216
target_os = "ios",
207217
target_os = "openbsd",
208218
target_os = "netbsd"))]
209-
pub const SO_WANTOOBFLAG: c_int = 0x8000;
219+
pub const SO_WANTOOBFLAG: c_int = 0x8000; //--
210220

211221
// Socket options for TCP sockets
212222
pub const TCP_NODELAY: c_int = libc::TCP_NODELAY;
213223
#[cfg(any(target_os = "linux", target_os = "android", target_os = "dragonfly"))]
214-
pub const TCP_MAXSEG: c_int = libc::TCP_MAXSEG;
224+
pub const TCP_MAXSEG: c_int = libc::TCP_MAXSEG; //--
215225
#[cfg(any(target_os = "macos",
216226
target_os = "freebsd",
217227
target_os = "ios",
218228
target_os = "openbsd",
219229
target_os = "netbsd"))]
220-
pub const TCP_MAXSEG: c_int = 2;
230+
pub const TCP_MAXSEG: c_int = 2; //--
221231
#[cfg(any(target_os = "linux", target_os = "android"))]
222-
pub const TCP_CORK: c_int = libc::TCP_CORK;
232+
pub const TCP_CORK: c_int = libc::TCP_CORK; //--
223233
#[cfg(any(target_os = "linux",
224234
target_os = "android",
225235
target_os = "freebsd",
226236
target_os = "dragonfly"))]
227-
pub const TCP_KEEPIDLE: c_int = libc::TCP_KEEPIDLE;
237+
pub const TCP_KEEPIDLE: c_int = libc::TCP_KEEPIDLE; //--
228238
#[cfg(any(target_os = "macos", target_os = "ios"))]
229-
pub const TCP_KEEPALIVE: c_int = libc::TCP_KEEPALIVE;
239+
pub const TCP_KEEPALIVE: c_int = libc::TCP_KEEPALIVE; //--
230240

231241
// Socket options for the IP layer of the socket
232242
#[cfg(any(target_os = "linux", target_os = "android"))]
233-
pub const IP_MULTICAST_IF: c_int = 32;
243+
pub const IP_MULTICAST_IF: c_int = 32; //--
234244
#[cfg(any(target_os = "macos",
235245
target_os = "freebsd",
236246
target_os = "ios",
237247
target_os = "openbsd",
238248
target_os = "netbsd",
239249
target_os = "dragonfly"))]
240-
pub const IP_MULTICAST_IF: c_int = 9;
250+
pub const IP_MULTICAST_IF: c_int = 9; //--
241251

242252
pub type IpMulticastTtl = uint8_t;
243253

@@ -247,23 +257,23 @@ mod os {
247257
pub const IP_DROP_MEMBERSHIP: c_int = libc::IP_DROP_MEMBERSHIP;
248258

249259
#[cfg(any(target_os = "linux", target_os = "android"))]
250-
pub const IPV6_ADD_MEMBERSHIP: c_int = libc::IPV6_ADD_MEMBERSHIP;
260+
pub const IPV6_ADD_MEMBERSHIP: c_int = libc::IPV6_ADD_MEMBERSHIP; //--
251261
#[cfg(any(target_os = "linux", target_os = "android"))]
252-
pub const IPV6_DROP_MEMBERSHIP: c_int = libc::IPV6_DROP_MEMBERSHIP;
262+
pub const IPV6_DROP_MEMBERSHIP: c_int = libc::IPV6_DROP_MEMBERSHIP; //--
253263
#[cfg(any(target_os = "macos",
254264
target_os = "freebsd",
255265
target_os = "ios",
256266
target_os = "openbsd",
257267
target_os = "netbsd",
258268
target_os = "dragonfly"))]
259-
pub const IPV6_JOIN_GROUP: c_int = libc::IPV6_JOIN_GROUP;
269+
pub const IPV6_JOIN_GROUP: c_int = libc::IPV6_JOIN_GROUP; //--
260270
#[cfg(any(target_os = "macos",
261271
target_os = "freebsd",
262272
target_os = "ios",
263273
target_os = "openbsd",
264274
target_os = "netbsd",
265275
target_os = "dragonfly"))]
266-
pub const IPV6_LEAVE_GROUP: c_int = libc::IPV6_LEAVE_GROUP;
276+
pub const IPV6_LEAVE_GROUP: c_int = libc::IPV6_LEAVE_GROUP; //--
267277

268278
pub type InAddrT = u32;
269279

@@ -278,15 +288,10 @@ mod os {
278288
MSG_OOB,
279289
MSG_PEEK,
280290
MSG_DONTWAIT,
281-
#[cfg(not(target_os = "dragonfly"))]
282291
MSG_CTRUNC,
283-
#[cfg(not(target_os = "dragonfly"))]
284292
MSG_TRUNC,
285-
#[cfg(not(target_os = "dragonfly"))]
286293
MSG_EOR,
287-
#[cfg(any(target_os = "linux", target_os = "android"))]
288294
MSG_ERRQUEUE,
289-
#[cfg(any(target_os = "linux", target_os = "android"))]
290295
MSG_CMSG_CLOEXEC,
291296
}
292297
}
@@ -298,13 +303,13 @@ mod os {
298303

299304
// Ancillary message types
300305
#[cfg(any(target_os = "linux", target_os = "android"))]
301-
pub const SCM_RIGHTS: c_int = libc::SCM_RIGHTS;
306+
pub const SCM_RIGHTS: c_int = libc::SCM_RIGHTS; //--
302307
#[cfg(any(target_os = "macos",
303308
target_os = "freebsd",
304309
target_os = "ios",
305310
target_os = "openbsd",
306311
target_os = "netbsd"))]
307-
pub const SCM_RIGHTS: c_int = 1;
312+
pub const SCM_RIGHTS: c_int = 1; //--
308313

309314
}
310315

0 commit comments

Comments
 (0)