Skip to content

Commit 73ecb15

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

File tree

1 file changed

+51
-144
lines changed

1 file changed

+51
-144
lines changed

src/sys/socket/consts.rs

Lines changed: 51 additions & 144 deletions
Original file line numberDiff line numberDiff line change
@@ -14,41 +14,32 @@ mod os {
1414
#[cfg(any(target_os = "macos", target_os = "ios"))]
1515
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 = libc::AF_SYS_CONTROL;
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")))]
2423
pub const SOCK_RDM: c_int = libc::SOCK_RDM;
25-
#[cfg(any(target_os = "linux", target_os = "android"))]
26-
pub const SOCK_RDM: c_int = 4;
2724

25+
pub const SOL_SOCKET: c_int = libc::SOL_SOCKET;
2826
#[cfg(any(target_os = "linux", target_os = "android"))]
2927
pub const SOL_IP: c_int = libc::SOL_IP;
30-
pub const SOL_SOCKET: c_int = libc::SOL_SOCKET;
3128
#[cfg(any(target_os = "linux", target_os = "android"))]
3229
pub const SOL_TCP: c_int = libc::SOL_TCP;
3330
#[cfg(any(target_os = "linux", target_os = "android"))]
34-
pub const SOL_UDP: c_int = 17;
31+
pub const SOL_UDP: c_int = libc::SOL_UDP;
3532
#[cfg(any(target_os = "linux", target_os = "android"))]
3633
pub const SOL_IPV6: c_int = libc::SOL_IPV6;
3734
#[cfg(any(target_os = "linux", target_os = "android"))]
3835
pub const SOL_NETLINK: c_int = libc::SOL_NETLINK;
36+
3937
pub const IPPROTO_IP: c_int = libc::IPPROTO_IP;
4038
pub const IPPROTO_IPV6: c_int = libc::IPPROTO_IPV6;
4139
pub const IPPROTO_TCP: c_int = libc::IPPROTO_TCP;
42-
#[cfg(any(target_os = "linux", target_os = "android", target_os = "dragonfly"))]
43-
pub const IPPROTO_UDP: c_int = SOL_UDP;
44-
#[cfg(any(target_os = "macos",
45-
target_os = "freebsd",
46-
target_os = "ios",
47-
target_os = "openbsd",
48-
target_os = "netbsd"))]
49-
pub const IPPROTO_UDP: c_int = 17;
40+
pub const IPPROTO_UDP: c_int = libc::IPPROTO_UDP;
5041
#[cfg(any(target_os = "macos", target_os = "ios"))]
51-
pub const SYSPROTO_CONTROL: c_int = 2;
42+
pub const SYSPROTO_CONTROL: c_int = libc::SYSPROTO_CONTROL;
5243

5344
pub const SO_ACCEPTCONN: c_int = libc::SO_ACCEPTCONN;
5445
#[cfg(any(target_os = "linux", target_os = "android"))]
@@ -62,151 +53,84 @@ mod os {
6253
#[cfg(any(target_os = "linux", target_os = "android"))]
6354
pub const SO_DOMAIN: c_int = libc::SO_DOMAIN;
6455
pub const SO_DONTROUTE: c_int = libc::SO_DONTROUTE;
65-
#[cfg(not(target_os = "netbsd"))]
66-
pub const SO_DONTTRUNC: c_int = 0x2000;
56+
#[cfg(any(target_os = "macos", target_os = "ios"))]
57+
pub const SO_DONTTRUNC: c_int = libc::SO_DONTTRUNC;
6758
pub const SO_ERROR: c_int = libc::SO_ERROR;
6859
pub const SO_KEEPALIVE: c_int = libc::SO_KEEPALIVE;
69-
#[cfg(any(target_os = "macos",
70-
target_os = "freebsd",
71-
target_os = "ios",
72-
target_os = "openbsd",
73-
target_os = "netbsd"))]
74-
pub const SO_LABEL: c_int = 0x1010;
60+
#[cfg(any(target_os = "macos", target_os = "ios", target_os = "freebsd"))]
61+
pub const SO_LABEL: c_int = libc::SO_LABEL;
7562
pub const SO_LINGER: c_int = libc::SO_LINGER;
7663
#[cfg(any(target_os = "linux", target_os = "android"))]
7764
pub const SO_MARK: c_int = libc::SO_MARK;
78-
#[cfg(any(target_os = "macos",
79-
target_os = "freebsd",
80-
target_os = "ios",
81-
target_os = "openbsd",
82-
target_os = "netbsd"))]
83-
pub const SO_NREAD: c_int = 0x1020;
84-
#[cfg(any(target_os = "macos",
65+
#[cfg(any(target_os = "macos", target_os = "ios"))]
66+
pub const SO_NREAD: c_int = libc::SO_NREAD;
67+
#[cfg(any(target_os = "macos", target_os = "ios"))]
68+
pub const SO_NKE: c_int = libc::SO_NKE;
69+
#[cfg(any(target_os = "dragonfly",
8570
target_os = "freebsd",
86-
target_os = "ios",
87-
target_os = "openbsd",
88-
target_os = "netbsd"))]
89-
pub const SO_NKE: c_int = 0x1021;
90-
#[cfg(target_os = "dragonfly")]
71+
target_os = "macos",
72+
target_os = "ios"))]
9173
pub const SO_NOSIGPIPE: c_int = libc::SO_NOSIGPIPE;
9274
#[cfg(any(target_os = "macos",
93-
target_os = "freebsd",
94-
target_os = "ios",
95-
target_os = "openbsd",
96-
target_os = "netbsd"))]
97-
pub const SO_NOSIGPIPE: c_int = 0x1022;
98-
#[cfg(any(target_os = "macos",
99-
target_os = "freebsd",
100-
target_os = "ios",
101-
target_os = "openbsd",
102-
target_os = "netbsd"))]
103-
pub const SO_NOADDRERR: c_int = 0x1023;
104-
#[cfg(any(target_os = "macos",
105-
target_os = "freebsd",
106-
target_os = "ios",
107-
target_os = "openbsd",
108-
target_os = "netbsd"))]
109-
pub const SO_NOTIFYCONFLICT: c_int = 0x1026;
110-
#[cfg(any(target_os = "macos",
111-
target_os = "freebsd",
112-
target_os = "ios",
113-
target_os = "openbsd",
114-
target_os = "netbsd"))]
115-
pub const SO_NP_EXTENSIONS: c_int = 0x1083;
75+
target_os = "ios"))]
76+
pub const SO_NOADDRERR: c_int = libc::SO_NOADDRERR;
77+
#[cfg(any(target_os = "macos", target_os = "ios"))]
78+
pub const SO_NOTIFYCONFLICT: c_int = libc::SO_NOTIFYCONFLICT;
79+
#[cfg(any(target_os = "macos", target_os = "ios"))]
80+
pub const SO_NP_EXTENSIONS: c_int = libc::SO_NP_EXTENSIONS;
11681
#[cfg(any(target_os = "macos",
117-
target_os = "freebsd",
118-
target_os = "ios",
119-
target_os = "openbsd",
120-
target_os = "netbsd"))]
121-
pub const SO_NWRITE: c_int = 0x1024;
82+
target_os = "ios"))]
83+
pub const SO_NWRITE: c_int = libc::SO_NWRITE;
12284
pub const SO_OOBINLINE: c_int = libc::SO_OOBINLINE;
123-
#[cfg(target_os = "linux")]
124-
pub const SO_ORIGINAL_DST: c_int = 80;
85+
#[cfg(any(target_os = "linux", target_os = "android"))]
86+
pub const SO_ORIGINAL_DST: c_int = libc::SO_ORIGINAL_DST;
12587
#[cfg(any(target_os = "linux", target_os = "android"))]
12688
pub const SO_PASSCRED: c_int = libc::SO_PASSCRED;
12789
#[cfg(any(target_os = "linux", target_os = "android"))]
12890
pub const SO_PEEK_OFF: c_int = libc::SO_PEEK_OFF;
129-
#[cfg(any(target_os = "linux", target_os = "android"))]
91+
#[cfg(any(target_os = "linux",
92+
target_os = "android",
93+
target_os = "openbsd"))]
13094
pub const SO_PEERCRED: c_int = libc::SO_PEERCRED;
131-
#[cfg(any(target_os = "macos",
132-
target_os = "freebsd",
133-
target_os = "ios",
134-
target_os = "openbsd",
135-
target_os = "netbsd"))]
136-
pub const SO_PEERLABEL: c_int = 0x1011;
95+
#[cfg(any(target_os = "macos", target_os = "ios", target_os = "freebsd"))]
96+
pub const SO_PEERLABEL: c_int = libc::SO_PEERLABEL;
13797
#[cfg(any(target_os = "linux", target_os = "android"))]
13898
pub const SO_PRIORITY: c_int = libc::SO_PRIORITY;
13999
#[cfg(any(target_os = "linux", target_os = "android"))]
140100
pub const SO_PROTOCOL: c_int = libc::SO_PROTOCOL;
141101
pub const SO_RCVBUF: c_int = libc::SO_RCVBUF;
142102
#[cfg(any(target_os = "linux", target_os = "android"))]
143-
pub const SO_RCVBUFFORCE: c_int = 33;
103+
pub const SO_RCVBUFFORCE: c_int = libc::SO_RCVBUFFORCE;
144104
pub const SO_RCVLOWAT: c_int = libc::SO_RCVLOWAT;
145105
pub const SO_SNDLOWAT: c_int = libc::SO_SNDLOWAT;
146106
pub const SO_RCVTIMEO: c_int = libc::SO_RCVTIMEO;
147107
pub const SO_SNDTIMEO: c_int = libc::SO_SNDTIMEO;
148-
#[cfg(any(target_os = "macos",
149-
target_os = "freebsd",
150-
target_os = "ios",
151-
target_os = "openbsd",
152-
target_os = "netbsd"))]
153-
pub const SO_RANDOMPORT: c_int = 0x1082;
154-
#[cfg(any(target_os = "macos",
155-
target_os = "freebsd",
156-
target_os = "ios",
157-
target_os = "openbsd",
158-
target_os = "netbsd"))]
159-
pub const SO_RESTRICTIONS: c_int = 0x1081;
160-
#[cfg(any(target_os = "macos",
161-
target_os = "freebsd",
162-
target_os = "ios",
163-
target_os = "openbsd",
164-
target_os = "netbsd"))]
165-
pub const SO_RESTRICT_DENYIN: c_int = 0x00000001;
166-
#[cfg(any(target_os = "macos",
167-
target_os = "freebsd",
168-
target_os = "ios",
169-
target_os = "openbsd",
170-
target_os = "netbsd"))]
171-
pub const SO_RESTRICT_DENYOUT: c_int = 0x00000002;
172-
#[cfg(any(target_os = "macos",
173-
target_os = "freebsd",
174-
target_os = "ios",
175-
target_os = "openbsd",
176-
target_os = "netbsd"))]
177-
#[allow(overflowing_literals)]
178-
pub const SO_RESTRICT_DENYSET: c_int = 0x80000000;
108+
#[cfg(any(target_os = "macos", target_os = "ios"))]
109+
pub const SO_RANDOMPORT: c_int = libc::SO_RANDOMPORT;
179110
pub const SO_REUSEADDR: c_int = libc::SO_REUSEADDR;
180111
pub const SO_REUSEPORT: c_int = libc::SO_REUSEPORT;
181-
#[cfg(any(target_os = "macos",
182-
target_os = "freebsd",
183-
target_os = "ios",
184-
target_os = "openbsd",
185-
target_os = "netbsd"))]
186-
pub const SO_REUSESHAREUID: c_int = 0x1025;
112+
#[cfg(any(target_os = "macos", target_os = "ios"))]
113+
pub const SO_REUSESHAREUID: c_int = libc::SO_REUSESHAREUID;
187114
#[cfg(any(target_os = "linux", target_os = "android"))]
188115
pub const SO_RXQ_OVFL: c_int = libc::SO_RXQ_OVFL;
189116
pub const SO_SNDBUF: c_int = libc::SO_SNDBUF;
190117
#[cfg(any(target_os = "linux", target_os = "android"))]
191118
pub const SO_SNDBUFFORCE: c_int = libc::SO_SNDBUFFORCE;
192119
pub const SO_TIMESTAMP: c_int = libc::SO_TIMESTAMP;
193-
#[cfg(not(target_os = "netbsd"))]
194-
pub const SO_TIMESTAMP_MONOTONIC: c_int = 0x0800;
120+
#[cfg(any(target_os = "macos", target_os = "ios"))]
121+
pub const SO_TIMESTAMP_MONOTONIC: c_int = libc::SO_TIMESTAMP_MONOTONIC;
195122
pub const SO_TYPE: c_int = libc::SO_TYPE;
196123
#[cfg(any(target_os = "macos",
197124
target_os = "freebsd",
198125
target_os = "ios",
199126
target_os = "openbsd",
200-
target_os = "netbsd"))]
127+
target_os = "netbsd",
128+
target_os = "dragonfly"))]
201129
pub const SO_USELOOPBACK: c_int = libc::SO_USELOOPBACK;
202-
#[cfg(not(target_os = "netbsd"))]
203-
pub const SO_WANTMORE: c_int = 0x4000;
204-
#[cfg(any(target_os = "macos",
205-
target_os = "freebsd",
206-
target_os = "ios",
207-
target_os = "openbsd",
208-
target_os = "netbsd"))]
209-
pub const SO_WANTOOBFLAG: c_int = 0x8000;
130+
#[cfg(any(target_os = "macos", target_os = "ios"))]
131+
pub const SO_WANTMORE: c_int = libc::SO_WANTMORE;
132+
#[cfg(any(target_os = "macos", target_os = "ios"))]
133+
pub const SO_WANTOOBFLAG: c_int = libc::SO_WANTOOBFLAG;
210134

211135
// Socket options for TCP sockets
212136
pub const TCP_NODELAY: c_int = libc::TCP_NODELAY;
@@ -216,8 +140,9 @@ mod os {
216140
target_os = "freebsd",
217141
target_os = "ios",
218142
target_os = "openbsd",
219-
target_os = "netbsd"))]
220-
pub const TCP_MAXSEG: c_int = 2;
143+
target_os = "netbsd",
144+
target_os = "dragonfly"))]
145+
pub const TCP_MAXSEG: c_int = libc::TCP_MAXSEG;
221146
#[cfg(any(target_os = "linux", target_os = "android"))]
222147
pub const TCP_CORK: c_int = libc::TCP_CORK;
223148
#[cfg(any(target_os = "linux",
@@ -229,17 +154,9 @@ mod os {
229154
pub const TCP_KEEPALIVE: c_int = libc::TCP_KEEPALIVE;
230155

231156
// Socket options for the IP layer of the socket
232-
#[cfg(any(target_os = "linux", target_os = "android"))]
233-
pub const IP_MULTICAST_IF: c_int = 32;
234-
#[cfg(any(target_os = "macos",
235-
target_os = "freebsd",
236-
target_os = "ios",
237-
target_os = "openbsd",
238-
target_os = "netbsd",
239-
target_os = "dragonfly"))]
240-
pub const IP_MULTICAST_IF: c_int = 9;
157+
pub const IP_MULTICAST_IF: c_int = libc::IP_MULTICAST_IF;
241158

242-
pub type IpMulticastTtl = uint8_t;
159+
pub type IpMulticastTtl = uint8_t; //--
243160

244161
pub const IP_MULTICAST_TTL: c_int = libc::IP_MULTICAST_TTL;
245162
pub const IP_MULTICAST_LOOP: c_int = libc::IP_MULTICAST_LOOP;
@@ -265,7 +182,7 @@ mod os {
265182
target_os = "dragonfly"))]
266183
pub const IPV6_LEAVE_GROUP: c_int = libc::IPV6_LEAVE_GROUP;
267184

268-
pub type InAddrT = u32;
185+
pub type InAddrT = u32; //--
269186

270187
// Declarations of special addresses
271188
pub const INADDR_ANY: InAddrT = 0;
@@ -278,11 +195,8 @@ mod os {
278195
MSG_OOB,
279196
MSG_PEEK,
280197
MSG_DONTWAIT,
281-
#[cfg(not(target_os = "dragonfly"))]
282198
MSG_CTRUNC,
283-
#[cfg(not(target_os = "dragonfly"))]
284199
MSG_TRUNC,
285-
#[cfg(not(target_os = "dragonfly"))]
286200
MSG_EOR,
287201
#[cfg(any(target_os = "linux", target_os = "android"))]
288202
MSG_ERRQUEUE,
@@ -297,14 +211,7 @@ mod os {
297211
pub const SHUT_RDWR: c_int = libc::SHUT_RDWR;
298212

299213
// Ancillary message types
300-
#[cfg(any(target_os = "linux", target_os = "android"))]
301214
pub const SCM_RIGHTS: c_int = libc::SCM_RIGHTS;
302-
#[cfg(any(target_os = "macos",
303-
target_os = "freebsd",
304-
target_os = "ios",
305-
target_os = "openbsd",
306-
target_os = "netbsd"))]
307-
pub const SCM_RIGHTS: c_int = 1;
308215

309216
}
310217

0 commit comments

Comments
 (0)