Skip to content

Commit e025ce0

Browse files
pvachonwycats
authored andcommitted
Add defines for Mac OS X/Darwin
Apple likes to Think Different(tm), especially where constants are involved. Make sure that we have the appropriate constants available for various performance-focused TCP socket options, and that the IP multicast-related defines are correct.
1 parent eb1ed1a commit e025ce0

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

src/sys/socket.rs

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ mod consts {
130130

131131
#[cfg(any(target_os = "macos", target_os = "ios"))]
132132
mod consts {
133-
use libc::{c_int};
133+
use libc::{c_int, uint8_t};
134134

135135
pub type AddressFamily = c_int;
136136

@@ -150,6 +150,9 @@ mod consts {
150150
pub type SockLevel = c_int;
151151

152152
pub const SOL_SOCKET: SockLevel = 0xffff;
153+
pub const IPPROTO_IP: SockLevel = 0;
154+
pub const IPPROTO_TCP: SockLevel = 6;
155+
pub const IPPROTO_UDP: SockLevel = 17;
153156

154157
pub type SockOpt = c_int;
155158

@@ -190,6 +193,33 @@ mod consts {
190193
pub const SO_WANTOOBFLAG: SockOpt = 0x8000;
191194
#[allow(type_overflow)]
192195
pub const SO_RESTRICT_DENYSET: SockOpt = 0x80000000;
196+
197+
// Socket options for TCP sockets
198+
pub const TCP_NODELAY: SockOpt = 1;
199+
pub const TCP_MAXSEG: SockOpt = 2;
200+
201+
// Socket options for the IP layer of the socket
202+
pub const IP_MULTICAST_IF: SockOpt = 9;
203+
204+
pub type IpMulticastTtl = uint8_t;
205+
206+
pub const IP_MULTICAST_TTL: SockOpt = 10;
207+
pub const IP_MULTICAST_LOOP: SockOpt = 11;
208+
pub const IP_ADD_MEMBERSHIP: SockOpt = 12;
209+
pub const IP_DROP_MEMBERSHIP: SockOpt = 13;
210+
211+
pub type InAddrT = u32;
212+
213+
// Declarations of special addresses
214+
pub const INADDR_ANY: InAddrT = 0;
215+
pub const INADDR_NONE: InAddrT = 0xffffffff;
216+
pub const INADDR_BROADCAST: InAddrT = 0xffffffff;
217+
218+
pub type SockMessageFlags = i32;
219+
// Flags for send/recv and their relatives
220+
pub const MSG_OOB: SockMessageFlags = 0x1;
221+
pub const MSG_PEEK: SockMessageFlags = 0x2;
222+
pub const MSG_DONTWAIT: SockMessageFlags = 0x80;
193223
}
194224

195225
pub fn socket(domain: AddressFamily, mut ty: SockType, flags: SockFlag) -> SysResult<Fd> {

0 commit comments

Comments
 (0)