summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNicolas Dusart <dusartnicolas@gmail.com>2017-07-10 11:00:29 +0200
committerNicolas Dusart <dusartnicolas@gmail.com>2017-08-01 09:46:01 +0200
commit33de2ae77f7c767b142500e08da3bb7096de9ecb (patch)
treebb6632c5b23317f13caa57061c655e4310c0521a /src
parentf8768e93d8a8961b700b375d47fa3fe1ff2a346a (diff)
downloadnix-33de2ae77f7c767b142500e08da3bb7096de9ecb.zip
remove sys::sockets::consts module as it's libc goal to define them
Diffstat (limited to 'src')
-rw-r--r--src/sys/socket/addr.rs20
-rw-r--r--src/sys/socket/consts.rs437
-rw-r--r--src/sys/socket/mod.rs61
-rw-r--r--src/sys/socket/sockopt.rs68
4 files changed, 81 insertions, 505 deletions
diff --git a/src/sys/socket/addr.rs b/src/sys/socket/addr.rs
index 5f8b130a..e8273273 100644
--- a/src/sys/socket/addr.rs
+++ b/src/sys/socket/addr.rs
@@ -1,4 +1,4 @@
-use super::{consts, sa_family_t};
+use super::sa_family_t;
use {Errno, Error, Result, NixPath};
use libc;
use std::{fmt, hash, mem, net, ptr};
@@ -23,15 +23,15 @@ use ::sys::socket::addr::sys_control::SysControlAddr;
#[repr(i32)]
#[derive(Copy, Clone, PartialEq, Eq, Debug, Hash)]
pub enum AddressFamily {
- Unix = consts::AF_UNIX,
- Inet = consts::AF_INET,
- Inet6 = consts::AF_INET6,
+ Unix = libc::AF_UNIX,
+ Inet = libc::AF_INET,
+ Inet6 = libc::AF_INET6,
#[cfg(any(target_os = "linux", target_os = "android"))]
- Netlink = consts::AF_NETLINK,
+ Netlink = libc::AF_NETLINK,
#[cfg(any(target_os = "linux", target_os = "android"))]
- Packet = consts::AF_PACKET,
+ Packet = libc::AF_PACKET,
#[cfg(any(target_os = "macos", target_os = "ios"))]
- System = consts::AF_SYSTEM,
+ System = libc::AF_SYSTEM,
}
#[derive(Copy)]
@@ -252,7 +252,7 @@ impl Ipv4Addr {
}
pub fn any() -> Ipv4Addr {
- Ipv4Addr(libc::in_addr { s_addr: consts::INADDR_ANY })
+ Ipv4Addr(libc::in_addr { s_addr: 0/*consts::INADDR_ANY*/ }) // TODO: define INADDR_ANY in libc
}
pub fn octets(&self) -> [u8; 4] {
@@ -644,8 +644,8 @@ pub mod netlink {
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub mod sys_control {
- use ::sys::socket::consts;
use ::sys::socket::addr::{AddressFamily};
+ use libc;
use libc::{c_uchar, uint16_t, uint32_t};
use std::{fmt, mem};
use std::hash::{Hash, Hasher};
@@ -702,7 +702,7 @@ pub mod sys_control {
let addr = sockaddr_ctl {
sc_len: mem::size_of::<sockaddr_ctl>() as c_uchar,
sc_family: AddressFamily::System as c_uchar,
- ss_sysaddr: consts::AF_SYS_CONTROL as uint16_t,
+ ss_sysaddr: libc::AF_SYS_CONTROL as uint16_t,
sc_id: id,
sc_unit: unit,
sc_reserved: [0; 5]
diff --git a/src/sys/socket/consts.rs b/src/sys/socket/consts.rs
deleted file mode 100644
index ad9c522f..00000000
--- a/src/sys/socket/consts.rs
+++ /dev/null
@@ -1,437 +0,0 @@
-pub use self::os::*;
-
-#[cfg(any(target_os = "linux", target_os = "android"))]
-mod os {
- use libc::{self, c_int, uint8_t};
-
- pub const AF_UNIX: c_int = libc::AF_UNIX;
- pub const AF_LOCAL: c_int = libc::AF_LOCAL;
- pub const AF_INET: c_int = libc::AF_INET;
- pub const AF_INET6: c_int = libc::AF_INET6;
- pub const AF_NETLINK: c_int = libc::AF_NETLINK;
- pub const AF_PACKET: c_int = libc::AF_PACKET;
-
- pub const SOCK_STREAM: c_int = libc::SOCK_STREAM;
- pub const SOCK_DGRAM: c_int = libc::SOCK_DGRAM;
- pub const SOCK_SEQPACKET: c_int = libc::SOCK_SEQPACKET;
- pub const SOCK_RAW: c_int = libc::SOCK_RAW;
- pub const SOCK_RDM: c_int = 4;
-
- pub const SOL_IP: c_int = libc::SOL_IP;
- pub const SOL_SOCKET: c_int = libc::SOL_SOCKET;
- pub const SOL_TCP: c_int = libc::SOL_TCP;
- pub const SOL_UDP: c_int = 17;
- pub const SOL_IPV6: c_int = libc::SOL_IPV6;
- pub const SOL_NETLINK: c_int = libc::SOL_NETLINK;
- pub const IPPROTO_IP: c_int = libc::IPPROTO_IP;
- pub const IPPROTO_IPV6: c_int = libc::IPPROTO_IPV6;
- pub const IPPROTO_TCP: c_int = libc::IPPROTO_TCP;
- pub const IPPROTO_UDP: c_int = SOL_UDP;
-
- pub const SO_ACCEPTCONN: c_int = libc::SO_ACCEPTCONN;
- pub const SO_BINDTODEVICE: c_int = libc::SO_BINDTODEVICE;
- pub const SO_BROADCAST: c_int = libc::SO_BROADCAST;
- pub const SO_BSDCOMPAT: c_int = libc::SO_BSDCOMPAT;
- pub const SO_DEBUG: c_int = libc::SO_DEBUG;
- pub const SO_DOMAIN: c_int = libc::SO_DOMAIN;
- pub const SO_ERROR: c_int = libc::SO_ERROR;
- pub const SO_DONTROUTE: c_int = libc::SO_DONTROUTE;
- pub const SO_KEEPALIVE: c_int = libc::SO_KEEPALIVE;
- pub const SO_LINGER: c_int = libc::SO_LINGER;
- pub const SO_MARK: c_int = libc::SO_MARK;
- pub const SO_OOBINLINE: c_int = libc::SO_OOBINLINE;
- pub const SO_PASSCRED: c_int = libc::SO_PASSCRED;
- pub const SO_PEEK_OFF: c_int = libc::SO_PEEK_OFF;
- pub const SO_PEERCRED: c_int = libc::SO_PEERCRED;
- pub const SO_PRIORITY: c_int = libc::SO_PRIORITY;
- pub const SO_PROTOCOL: c_int = libc::SO_PROTOCOL;
- pub const SO_RCVBUF: c_int = libc::SO_RCVBUF;
- pub const SO_RCVBUFFORCE: c_int = 33;
- pub const SO_RCVLOWAT: c_int = libc::SO_RCVLOWAT;
- pub const SO_SNDLOWAT: c_int = libc::SO_SNDLOWAT;
- pub const SO_RCVTIMEO: c_int = libc::SO_RCVTIMEO;
- pub const SO_SNDTIMEO: c_int = libc::SO_SNDTIMEO;
- pub const SO_REUSEADDR: c_int = libc::SO_REUSEADDR;
- pub const SO_REUSEPORT: c_int = libc::SO_REUSEPORT;
- pub const SO_RXQ_OVFL: c_int = libc::SO_RXQ_OVFL;
- pub const SO_SNDBUF: c_int = libc::SO_SNDBUF;
- pub const SO_SNDBUFFORCE: c_int = libc::SO_SNDBUFFORCE;
- pub const SO_TIMESTAMP: c_int = libc::SO_TIMESTAMP;
- pub const SO_TYPE: c_int = libc::SO_TYPE;
- pub const SO_BUSY_POLL: c_int = libc::SO_BUSY_POLL;
- #[cfg(target_os = "linux")]
- pub const SO_ORIGINAL_DST: c_int = 80;
-
- // Socket options for TCP sockets
- pub const TCP_NODELAY: c_int = libc::TCP_NODELAY;
- pub const TCP_MAXSEG: c_int = libc::TCP_MAXSEG;
- pub const TCP_CORK: c_int = libc::TCP_CORK;
- pub const TCP_KEEPIDLE: c_int = libc::TCP_KEEPIDLE;
-
- // Socket options for the IP layer of the socket
- pub const IP_MULTICAST_IF: c_int = 32;
-
- pub type IpMulticastTtl = uint8_t;
-
- pub const IP_MULTICAST_TTL: c_int = libc::IP_MULTICAST_TTL;
- pub const IP_MULTICAST_LOOP: c_int = libc::IP_MULTICAST_LOOP;
- pub const IP_ADD_MEMBERSHIP: c_int = libc::IP_ADD_MEMBERSHIP;
- pub const IP_DROP_MEMBERSHIP: c_int = libc::IP_DROP_MEMBERSHIP;
-
- pub const IPV6_ADD_MEMBERSHIP: c_int = libc::IPV6_ADD_MEMBERSHIP;
- pub const IPV6_DROP_MEMBERSHIP: c_int = libc::IPV6_DROP_MEMBERSHIP;
-
- pub type InAddrT = u32;
-
- // Declarations of special addresses
- pub const INADDR_ANY: InAddrT = 0;
- pub const INADDR_NONE: InAddrT = 0xffffffff;
- pub const INADDR_BROADCAST: InAddrT = 0xffffffff;
-
- // Flags for send/recv and their relatives
- libc_bitflags!{
- pub flags MsgFlags: libc::c_int {
- MSG_OOB,
- MSG_PEEK,
- MSG_CTRUNC,
- MSG_TRUNC,
- MSG_DONTWAIT,
- MSG_EOR,
- MSG_ERRQUEUE,
- MSG_CMSG_CLOEXEC,
- }
- }
-
- // shutdown flags
- pub const SHUT_RD: c_int = libc::SHUT_RD;
- pub const SHUT_WR: c_int = libc::SHUT_WR;
- pub const SHUT_RDWR: c_int = libc::SHUT_RDWR;
-
- // Ancillary message types
- pub const SCM_RIGHTS: c_int = libc::SCM_RIGHTS;
-}
-
-// Not all of these constants exist on freebsd
-#[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "ios", target_os = "openbsd", target_os = "netbsd"))]
-mod os {
- #[cfg(any(target_os = "macos",
- target_os = "ios",
- target_os = "freebsd"))]
- use libc::{self, c_int, uint8_t};
- #[cfg(any(target_os = "openbsd", target_os = "netbsd"))]
- use libc::{self, c_int, uint8_t};
-
- pub const AF_UNIX: c_int = libc::AF_UNIX;
- pub const AF_LOCAL: c_int = libc::AF_LOCAL;
- pub const AF_INET: c_int = libc::AF_INET;
- pub const AF_INET6: c_int = libc::AF_INET6;
- #[cfg(any(target_os = "macos", target_os = "ios"))]
- pub const AF_SYSTEM: c_int = libc::AF_SYSTEM;
-
- #[cfg(any(target_os = "macos", target_os = "ios"))]
- pub const AF_SYS_CONTROL: c_int = 2;
-
- pub const SOCK_STREAM: c_int = libc::SOCK_STREAM;
- pub const SOCK_DGRAM: c_int = libc::SOCK_DGRAM;
- pub const SOCK_SEQPACKET: c_int = libc::SOCK_SEQPACKET;
- pub const SOCK_RAW: c_int = libc::SOCK_RAW;
- pub const SOCK_RDM: c_int = libc::SOCK_RDM;
-
- pub const SOL_SOCKET: c_int = libc::SOL_SOCKET;
- pub const IPPROTO_IP: c_int = libc::IPPROTO_IP;
- pub const IPPROTO_IPV6: c_int = libc::IPPROTO_IPV6;
- pub const IPPROTO_TCP: c_int = libc::IPPROTO_TCP;
- pub const IPPROTO_UDP: c_int = 17;
- #[cfg(any(target_os = "macos", target_os = "ios"))]
- pub const SYSPROTO_CONTROL: c_int = 2;
-
- pub const SO_ACCEPTCONN: c_int = libc::SO_ACCEPTCONN;
- pub const SO_BROADCAST: c_int = libc::SO_BROADCAST;
- pub const SO_DEBUG: c_int = libc::SO_DEBUG;
- #[cfg(not(target_os = "netbsd"))]
- pub const SO_DONTTRUNC: c_int = 0x2000;
- pub const SO_USELOOPBACK: c_int = libc::SO_USELOOPBACK;
- pub const SO_ERROR: c_int = libc::SO_ERROR;
- pub const SO_DONTROUTE: c_int = libc::SO_DONTROUTE;
- pub const SO_KEEPALIVE: c_int = libc::SO_KEEPALIVE;
- pub const SO_LABEL: c_int = 0x1010;
- pub const SO_LINGER: c_int = libc::SO_LINGER;
- pub const SO_NREAD: c_int = 0x1020;
- pub const SO_NKE: c_int = 0x1021;
- pub const SO_NOSIGPIPE: c_int = 0x1022;
- pub const SO_NOADDRERR: c_int = 0x1023;
- pub const SO_NOTIFYCONFLICT: c_int = 0x1026;
- pub const SO_NP_EXTENSIONS: c_int = 0x1083;
- pub const SO_NWRITE: c_int = 0x1024;
- pub const SO_OOBINLINE: c_int = libc::SO_OOBINLINE;
- pub const SO_PEERLABEL: c_int = 0x1011;
- pub const SO_RCVBUF: c_int = libc::SO_RCVBUF;
- pub const SO_RCVLOWAT: c_int = libc::SO_RCVLOWAT;
- pub const SO_SNDLOWAT: c_int = libc::SO_SNDLOWAT;
- pub const SO_RCVTIMEO: c_int = libc::SO_RCVTIMEO;
- pub const SO_SNDTIMEO: c_int = libc::SO_SNDTIMEO;
- pub const SO_RANDOMPORT: c_int = 0x1082;
- pub const SO_RESTRICTIONS: c_int = 0x1081;
- pub const SO_RESTRICT_DENYIN: c_int = 0x00000001;
- pub const SO_RESTRICT_DENYOUT: c_int = 0x00000002;
- pub const SO_REUSEADDR: c_int = libc::SO_REUSEADDR;
- pub const SO_REUSEPORT: c_int = libc::SO_REUSEPORT;
- pub const SO_REUSESHAREUID: c_int = 0x1025;
- pub const SO_SNDBUF: c_int = libc::SO_SNDBUF;
- pub const SO_TIMESTAMP: c_int = libc::SO_TIMESTAMP;
- #[cfg(not(target_os = "netbsd"))]
- pub const SO_TIMESTAMP_MONOTONIC: c_int = 0x0800;
- pub const SO_TYPE: c_int = libc::SO_TYPE;
- #[cfg(not(target_os = "netbsd"))]
- pub const SO_WANTMORE: c_int = 0x4000;
- pub const SO_WANTOOBFLAG: c_int = 0x8000;
- #[allow(overflowing_literals)]
- pub const SO_RESTRICT_DENYSET: c_int = 0x80000000;
-
- // Socket options for TCP sockets
- pub const TCP_NODELAY: c_int = libc::TCP_NODELAY;
- pub const TCP_MAXSEG: c_int = 2;
- #[cfg(any(target_os = "macos", target_os = "ios"))]
- pub const TCP_KEEPALIVE: c_int = libc::TCP_KEEPALIVE;
- #[cfg(target_os = "freebsd")]
- pub const TCP_KEEPIDLE: c_int = libc::TCP_KEEPIDLE;
-
- // Socket options for the IP layer of the socket
- pub const IP_MULTICAST_IF: c_int = 9;
-
- pub type IpMulticastTtl = uint8_t;
-
- pub const IP_MULTICAST_TTL: c_int = libc::IP_MULTICAST_TTL;
- pub const IP_MULTICAST_LOOP: c_int = libc::IP_MULTICAST_LOOP;
- pub const IP_ADD_MEMBERSHIP: c_int = libc::IP_ADD_MEMBERSHIP;
- pub const IP_DROP_MEMBERSHIP: c_int = libc::IP_DROP_MEMBERSHIP;
-
- pub const IPV6_JOIN_GROUP: c_int = libc::IPV6_JOIN_GROUP;
- pub const IPV6_LEAVE_GROUP: c_int = libc::IPV6_LEAVE_GROUP;
-
- pub type InAddrT = u32;
-
- // Declarations of special addresses
- pub const INADDR_ANY: InAddrT = 0;
- pub const INADDR_NONE: InAddrT = 0xffffffff;
- pub const INADDR_BROADCAST: InAddrT = 0xffffffff;
-
- // Flags for send/recv and their relatives
- libc_bitflags!{
- pub flags MsgFlags: libc::c_int {
- MSG_OOB,
- MSG_PEEK,
- MSG_EOR,
- MSG_TRUNC,
- MSG_CTRUNC,
- MSG_DONTWAIT,
- }
- }
-
- // shutdown flags
- pub const SHUT_RD: c_int = libc::SHUT_RD;
- pub const SHUT_WR: c_int = libc::SHUT_WR;
- pub const SHUT_RDWR: c_int = libc::SHUT_RDWR;
-
- // Ancillary message types
- pub const SCM_RIGHTS: c_int = 1;
-}
-
-#[cfg(target_os = "dragonfly")]
-mod os {
- use libc::{c_int, uint8_t};
-
- pub const AF_UNIX: c_int = libc::AF_UNIX;
- pub const AF_LOCAL: c_int = libc::AF_LOCAL;
- pub const AF_INET: c_int = libc::AF_INET;
- pub const AF_INET6: c_int = libc::AF_INET6;
-
- pub const SOCK_STREAM: c_int = libc::SOCK_STREAM;
- pub const SOCK_DGRAM: c_int = libc::SOCK_DGRAM;
- pub const SOCK_SEQPACKET: c_int = libc::SOCK_SEQPACKET;
- pub const SOCK_RAW: c_int = libc::SOCK_RAW;
- pub const SOCK_RDM: c_int = libc::SOCK_RDM;
-
- pub const SOL_SOCKET: c_int = libc::SOL_SOCKET;
- pub const IPPROTO_IP: c_int = libc::IPPROTO_IP;
- pub const IPPROTO_IPV6: c_int = libc::IPPROTO_IPV6;
- pub const IPPROTO_TCP: c_int = libc::IPPROTO_TCP;
- pub const IPPROTO_UDP: c_int = libc::IPPROTO_UDP;
-
- pub const SO_ACCEPTCONN: c_int = libc::SO_ACCEPTCONN;
- pub const SO_BROADCAST: c_int = libc::SO_BROADCAST;
- pub const SO_DEBUG: c_int = libc::SO_DEBUG;
- pub const SO_ERROR: c_int = libc::SO_ERROR;
- pub const SO_DONTROUTE: c_int = libc::SO_DONTROUTE;
- pub const SO_KEEPALIVE: c_int = libc::SO_KEEPALIVE;
- pub const SO_LINGER: c_int = libc::SO_LINGER;
- pub const SO_NOSIGPIPE: c_int = libc::SO_NOSIGPIPE;
- pub const SO_OOBINLINE: c_int = libc::SO_OOBINLINE;
- pub const SO_RCVBUF: c_int = libc::SO_RCVBUF;
- pub const SO_RCVLOWAT: c_int = libc::RCVLOWAT;
- pub const SO_SNDLOWAT: c_int = libc::SO_SNDLOWAT;
- pub const SO_RCVTIMEO: c_int = libc::SO_RCVTIMEO;
- pub const SO_SNDTIMEO: c_int = libc::SO_SNDTIMEO;
- pub const SO_REUSEADDR: c_int = libc::SO_REUSEADDR;
- pub const SO_REUSEPORT: c_int = libc::SO_REUSEPORT;
- pub const SO_SNDBUF: c_int = libc::SO_SNDBUF;
- pub const SO_TIMESTAMP: c_int = libc::SO_TIMESTAMP;
- pub const SO_TYPE: c_int = libc::SO_TYPE;
-
- // Socket options for TCP sockets
- pub const TCP_NODELAY: c_int = libc::TCP_NODELAY;
- pub const TCP_MAXSEG: c_int = libc::TCP_MAXSEG;
- pub const TCP_KEEPIDLE: c_int = libc::TCP_KEEPIDLE;
-
- // Socket options for the IP layer of the socket
- pub const IP_MULTICAST_IF: c_int = 9;
-
- pub type IpMulticastTtl = uint8_t;
-
- pub const IP_MULTICAST_TTL: c_int = libc::IP_MULTICAST_TTL;
- pub const IP_MULTICAST_LOOP: c_int = libc::IP_MULTICAST_LOOP;
- pub const IP_ADD_MEMBERSHIP: c_int = libc::IP_ADD_MEMBERSHIP;
- pub const IP_DROP_MEMBERSHIP: c_int = libc::IP_DROP_MEMBERSHIP;
- pub const IPV6_JOIN_GROUP: c_int = libc::IPV6_JOIN_GROUP;
- pub const IPV6_LEAVE_GROUP: c_int = libc::IPV6_LEAVE_GROUP;
-
- pub type InAddrT = u32;
-
- // Declarations of special addresses
- pub const INADDR_ANY: InAddrT = 0;
- pub const INADDR_NONE: InAddrT = 0xffffffff;
- pub const INADDR_BROADCAST: InAddrT = 0xffffffff;
-
- // Flags for send/recv and their relatives
- libc_bitflags!{
- pub flags MsgFlags: libc::c_int {
- MSG_OOB,
- MSG_PEEK,
- MSG_DONTWAIT,
- }
- }
-
- // shutdown flags
- pub const SHUT_RD: c_int = libc::SHUT_RD;
- pub const SHUT_WR: c_int = libc::SHUT_WR;
- pub const SHUT_RDWR: c_int = libc::SHUT_RDWR;
-}
-
-#[cfg(test)]
-mod test {
- use super::*;
- use nixtest::{assert_const_eq,get_int_const,GetConst};
- use libc::{c_char};
- use std::fmt;
-
- impl fmt::Display for MsgFlags {
- fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- write!(f, "{}", self.bits())
- }
- }
-
- impl GetConst for MsgFlags {
- unsafe fn get_const(name: *const c_char) -> MsgFlags {
- MsgFlags::from_bits_truncate(get_int_const(name))
- }
- }
-
- macro_rules! check_const {
- ($($konst:ident),+) => {{
- $(assert_const_eq(stringify!($konst), $konst);)+
- }};
- }
-
- #[test]
- pub fn test_const_values() {
- check_const!(
- AF_UNIX,
- AF_LOCAL,
- AF_INET,
- AF_INET6,
- SOCK_STREAM,
- SOCK_DGRAM,
- SOCK_SEQPACKET,
- SOCK_RAW,
- SOCK_RDM,
- SOL_SOCKET,
- IPPROTO_IP,
- IPPROTO_IPV6,
- IPPROTO_TCP,
- IPPROTO_UDP,
- SO_ACCEPTCONN,
- SO_BROADCAST,
- SO_DEBUG,
- SO_ERROR,
- SO_DONTROUTE,
- SO_KEEPALIVE,
- SO_LINGER,
- SO_OOBINLINE,
- SO_RCVBUF,
- SO_RCVLOWAT,
- SO_SNDLOWAT,
- SO_RCVTIMEO,
- SO_SNDTIMEO,
- SO_REUSEADDR,
- // SO_REUSEPORT,
- SO_SNDBUF,
- SO_TIMESTAMP,
- SO_TYPE,
- TCP_NODELAY,
- TCP_MAXSEG,
- IP_MULTICAST_IF,
- IP_MULTICAST_TTL,
- IP_MULTICAST_LOOP,
- IP_ADD_MEMBERSHIP,
- IP_DROP_MEMBERSHIP,
- INADDR_ANY,
- INADDR_NONE,
- INADDR_BROADCAST,
- MSG_OOB,
- MSG_PEEK,
- MSG_DONTWAIT,
- MSG_EOR,
- MSG_TRUNC,
- MSG_CTRUNC,
- SHUT_RD,
- SHUT_WR,
- SHUT_RDWR
- );
-
-
- }
-
- #[cfg(target_os = "linux")]
- #[test]
- pub fn test_general_linux_consts() {
- // TODO Figure out how to test new constants
- check_const!(
- SOL_IP,
- SOL_TCP,
- SOL_UDP,
- SOL_IPV6,
- SO_BINDTODEVICE,
- SO_BSDCOMPAT,
- // SO_DOMAIN,
- // SO_MARK,
- TCP_CORK,
- // SO_BUSY_POLL,
- // SO_RXQ_OVFL,
- SO_PRIORITY,
- // SO_PROTOCOL,
- SO_RCVBUFFORCE,
- // SO_PEEK_OFF,
- MSG_ERRQUEUE);
- }
-
- #[cfg(all(target_os = "linux", not(target_arch="arm")))]
- #[test]
- pub fn test_linux_not_arm_consts() {
- // TODO Figure out how to test new constants
- check_const!(
- SO_PASSCRED,
- SO_PEERCRED,
- SO_SNDBUFFORCE);
- }
-
-}
diff --git a/src/sys/socket/mod.rs b/src/sys/socket/mod.rs
index c11b5367..338eee5f 100644
--- a/src/sys/socket/mod.rs
+++ b/src/sys/socket/mod.rs
@@ -9,9 +9,9 @@ use libc::{c_void, c_int, socklen_t, size_t, pid_t, uid_t, gid_t};
use std::{mem, ptr, slice};
use std::os::unix::io::RawFd;
use sys::uio::IoVec;
+use libc;
mod addr;
-mod consts;
mod ffi;
mod multicast;
pub mod sockopt;
@@ -48,18 +48,17 @@ pub use self::multicast::{
ip_mreq,
ipv6_mreq,
};
-pub use self::consts::*;
pub use libc::sockaddr_storage;
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
#[repr(i32)]
pub enum SockType {
- Stream = consts::SOCK_STREAM,
- Datagram = consts::SOCK_DGRAM,
- SeqPacket = consts::SOCK_SEQPACKET,
- Raw = consts::SOCK_RAW,
- Rdm = consts::SOCK_RDM,
+ Stream = libc::SOCK_STREAM,
+ Datagram = libc::SOCK_DGRAM,
+ SeqPacket = libc::SOCK_SEQPACKET,
+ Raw = libc::SOCK_RAW,
+ Rdm = libc::SOCK_RDM,
}
// Extra flags - Supported by Linux 2.6.27, normalized on other platforms
@@ -70,6 +69,22 @@ bitflags!(
}
);
+// Flags for send/recv and their relatives
+libc_bitflags!{
+ pub flags MsgFlags: libc::c_int {
+ MSG_OOB,
+ MSG_PEEK,
+ MSG_DONTWAIT,
+ MSG_CTRUNC,
+ MSG_TRUNC,
+ MSG_EOR,
+ #[cfg(any(target_os = "linux", target_os = "android"))]
+ MSG_ERRQUEUE,
+ #[cfg(any(target_os = "linux", target_os = "android"))]
+ MSG_CMSG_CLOEXEC,
+ }
+}
+
/// Copy the in-memory representation of src into the byte slice dst,
/// updating the slice to point to the remainder of dst only. Unsafe
/// because it exposes all bytes in src, which may be UB if some of them
@@ -157,7 +172,7 @@ impl<'a> Iterator for CmsgIterator<'a> {
self.0 = &buf[cmsg_align(cmsg_len)..];
match (cmsg.cmsg_level, cmsg.cmsg_type) {
- (SOL_SOCKET, SCM_RIGHTS) => unsafe {
+ (libc::SOL_SOCKET, libc::SCM_RIGHTS) => unsafe {
Some(ControlMessage::ScmRights(
slice::from_raw_parts(
&cmsg.cmsg_data as *const _ as *const _, 1)))
@@ -221,8 +236,8 @@ impl<'a> ControlMessage<'a> {
ControlMessage::ScmRights(fds) => {
let cmsg = cmsghdr {
cmsg_len: self.len() as type_of_cmsg_len,
- cmsg_level: SOL_SOCKET,
- cmsg_type: SCM_RIGHTS,
+ cmsg_level: libc::SOL_SOCKET,
+ cmsg_type: libc::SCM_RIGHTS,
cmsg_data: [],
};
copy_bytes(&cmsg, buf);
@@ -551,13 +566,13 @@ pub struct ucred {
/// [Further reading](http://man7.org/linux/man-pages/man2/setsockopt.2.html)
#[repr(i32)]
pub enum SockLevel {
- Socket = SOL_SOCKET,
- Tcp = IPPROTO_TCP,
- Ip = IPPROTO_IP,
- Ipv6 = IPPROTO_IPV6,
- Udp = IPPROTO_UDP,
+ Socket = libc::SOL_SOCKET,
+ Tcp = libc::IPPROTO_TCP,
+ Ip = libc::IPPROTO_IP,
+ Ipv6 = libc::IPPROTO_IPV6,
+ Udp = libc::IPPROTO_UDP,
#[cfg(any(target_os = "linux", target_os = "android"))]
- Netlink = SOL_NETLINK,
+ Netlink = libc::SOL_NETLINK,
}
/// Represents a socket option that can be accessed or set. Used as an argument
@@ -639,22 +654,22 @@ pub unsafe fn sockaddr_storage_to_addr(
}
match addr.ss_family as c_int {
- consts::AF_INET => {
+ libc::AF_INET => {
assert!(len as usize == mem::size_of::<sockaddr_in>());
let ret = *(addr as *const _ as *const sockaddr_in);
Ok(SockAddr::Inet(InetAddr::V4(ret)))
}
- consts::AF_INET6 => {
+ libc::AF_INET6 => {
assert!(len as usize == mem::size_of::<sockaddr_in6>());
Ok(SockAddr::Inet(InetAddr::V6((*(addr as *const _ as *const sockaddr_in6)))))
}
- consts::AF_UNIX => {
+ libc::AF_UNIX => {
let sun = *(addr as *const _ as *const sockaddr_un);
let pathlen = len - offset_of!(sockaddr_un, sun_path);
Ok(SockAddr::Unix(UnixAddr(sun, pathlen)))
}
#[cfg(any(target_os = "linux", target_os = "android"))]
- consts::AF_NETLINK => {
+ libc::AF_NETLINK => {
use libc::sockaddr_nl;
Ok(SockAddr::Netlink(NetlinkAddr(*(addr as *const _ as *const sockaddr_nl))))
}
@@ -681,9 +696,9 @@ pub fn shutdown(df: RawFd, how: Shutdown) -> Result<()> {
use libc::shutdown;
let how = match how {
- Shutdown::Read => consts::SHUT_RD,
- Shutdown::Write => consts::SHUT_WR,
- Shutdown::Both => consts::SHUT_RDWR,
+ Shutdown::Read => libc::SHUT_RD,
+ Shutdown::Write => libc::SHUT_WR,
+ Shutdown::Both => libc::SHUT_RDWR,
};
Errno::result(shutdown(df, how)).map(drop)
diff --git a/src/sys/socket/sockopt.rs b/src/sys/socket/sockopt.rs
index 61d85ec3..792bcb00 100644
--- a/src/sys/socket/sockopt.rs
+++ b/src/sys/socket/sockopt.rs
@@ -1,4 +1,5 @@
-use super::{ffi, consts, GetSockOpt, SetSockOpt};
+use super::{ffi, GetSockOpt, SetSockOpt};
+use libc;
use {Errno, Result};
use sys::time::TimeVal;
use libc::{c_int, uint8_t, c_void, socklen_t};
@@ -130,52 +131,49 @@ macro_rules! sockopt_impl {
*
*/
-sockopt_impl!(Both, ReuseAddr, consts::SOL_SOCKET, consts::SO_REUSEADDR, bool);
-sockopt_impl!(Both, ReusePort, consts::SOL_SOCKET, consts::SO_REUSEPORT, bool);
-sockopt_impl!(Both, TcpNoDelay, consts::IPPROTO_TCP, consts::TCP_NODELAY, bool);
-sockopt_impl!(Both, Linger, consts::SOL_SOCKET, consts::SO_LINGER, super::linger);
-sockopt_impl!(SetOnly, IpAddMembership, consts::IPPROTO_IP, consts::IP_ADD_MEMBERSHIP, super::ip_mreq);
-sockopt_impl!(SetOnly, IpDropMembership, consts::IPPROTO_IP, consts::IP_DROP_MEMBERSHIP, super::ip_mreq);
+sockopt_impl!(Both, ReuseAddr, libc::SOL_SOCKET, libc::SO_REUSEADDR, bool);
+sockopt_impl!(Both, ReusePort, libc::SOL_SOCKET, libc::SO_REUSEPORT, bool);
+sockopt_impl!(Both, TcpNoDelay, libc::IPPROTO_TCP, libc::TCP_NODELAY, bool);
+sockopt_impl!(Both, Linger, libc::SOL_SOCKET, libc::SO_LINGER, super::linger);
+sockopt_impl!(SetOnly, IpAddMembership, libc::IPPROTO_IP, libc::IP_ADD_MEMBERSHIP, super::ip_mreq);
+sockopt_impl!(SetOnly, IpDropMembership, libc::IPPROTO_IP, libc::IP_DROP_MEMBERSHIP, super::ip_mreq);
#[cfg(not(any(target_os = "dragonfly", target_os = "freebsd", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd")))]
-sockopt_impl!(SetOnly, Ipv6AddMembership, consts::IPPROTO_IPV6, consts::IPV6_ADD_MEMBERSHIP, super::ipv6_mreq);
+sockopt_impl!(SetOnly, Ipv6AddMembership, libc::IPPROTO_IPV6, libc::IPV6_ADD_MEMBERSHIP, super::ipv6_mreq);
#[cfg(not(any(target_os = "dragonfly", target_os = "freebsd", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd")))]
-sockopt_impl!(SetOnly, Ipv6DropMembership, consts::IPPROTO_IPV6, consts::IPV6_DROP_MEMBERSHIP, super::ipv6_mreq);
+sockopt_impl!(SetOnly, Ipv6DropMembership, libc::IPPROTO_IPV6, libc::IPV6_DROP_MEMBERSHIP, super::ipv6_mreq);
#[cfg(any(target_os = "dragonfly", target_os = "freebsd", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd"))]
-sockopt_impl!(SetOnly, Ipv6AddMembership, consts::IPPROTO_IPV6, consts::IPV6_JOIN_GROUP, super::ipv6_mreq);
+sockopt_impl!(SetOnly, Ipv6AddMembership, libc::IPPROTO_IPV6, libc::IPV6_JOIN_GROUP, super::ipv6_mreq);
#[cfg(any(target_os = "dragonfly", target_os = "freebsd", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd"))]
-sockopt_impl!(SetOnly, Ipv6DropMembership, consts::IPPROTO_IPV6, consts::IPV6_LEAVE_GROUP, super::ipv6_mreq);
-sockopt_impl!(Both, IpMulticastTtl, consts::IPPROTO_IP, consts::IP_MULTICAST_TTL, u8);
-sockopt_impl!(Both, IpMulticastLoop, consts::IPPROTO_IP, consts::IP_MULTICAST_LOOP, bool);
-sockopt_impl!(Both, ReceiveTimeout, consts::SOL_SOCKET, consts::SO_RCVTIMEO, TimeVal);
-sockopt_impl!(Both, SendTimeout, consts::SOL_SOCKET, consts::SO_SNDTIMEO, TimeVal);
-sockopt_impl!(Both, Broadcast, consts::SOL_SOCKET, consts::SO_BROADCAST, bool);
-sockopt_impl!(Both, OobInline, consts::SOL_SOCKET, consts::SO_OOBINLINE, bool);
-sockopt_impl!(GetOnly, SocketError, consts::SOL_SOCKET, consts::SO_ERROR, i32);
-sockopt_impl!(Both, KeepAlive, consts::SOL_SOCKET, consts::SO_KEEPALIVE, bool);
+sockopt_impl!(SetOnly, Ipv6DropMembership, libc::IPPROTO_IPV6, libc::IPV6_LEAVE_GROUP, super::ipv6_mreq);
+sockopt_impl!(Both, IpMulticastTtl, libc::IPPROTO_IP, libc::IP_MULTICAST_TTL, u8);
+sockopt_impl!(Both, IpMulticastLoop, libc::IPPROTO_IP, libc::IP_MULTICAST_LOOP, bool);
+sockopt_impl!(Both, ReceiveTimeout, libc::SOL_SOCKET, libc::SO_RCVTIMEO, TimeVal);
+sockopt_impl!(Both, SendTimeout, libc::SOL_SOCKET, libc::SO_SNDTIMEO, TimeVal);
+sockopt_impl!(Both, Broadcast, libc::SOL_SOCKET, libc::SO_BROADCAST, bool);
+sockopt_impl!(Both, OobInline, libc::SOL_SOCKET, libc::SO_OOBINLINE, bool);
+sockopt_impl!(GetOnly, SocketError, libc::SOL_SOCKET, libc::SO_ERROR, i32);
+sockopt_impl!(Both, KeepAlive, libc::SOL_SOCKET, libc::SO_KEEPALIVE, bool);
#[cfg(all(target_os = "linux", not(target_arch="arm")))]
-sockopt_impl!(GetOnly, PeerCredentials, consts::SOL_SOCKET, consts::SO_PEERCRED, super::ucred);
+sockopt_impl!(GetOnly, PeerCredentials, libc::SOL_SOCKET, libc::SO_PEERCRED, super::ucred);
#[cfg(any(target_os = "macos",
target_os = "ios"))]
-sockopt_impl!(Both, TcpKeepAlive, consts::IPPROTO_TCP, consts::TCP_KEEPALIVE, u32);
+sockopt_impl!(Both, TcpKeepAlive, libc::IPPROTO_TCP, libc::TCP_KEEPALIVE, u32);
#[cfg(any(target_os = "freebsd",
target_os = "dragonfly",
target_os = "linux",
target_os = "android",
target_os = "nacl"))]
-sockopt_impl!(Both, TcpKeepIdle, consts::IPPROTO_TCP, consts::TCP_KEEPIDLE, u32);
-sockopt_impl!(Both, RcvBuf, consts::SOL_SOCKET, consts::SO_RCVBUF, usize);
-sockopt_impl!(Both, SndBuf, consts::SOL_SOCKET, consts::SO_SNDBUF, usize);
-#[cfg(target_os = "linux")]
-sockopt_impl!(SetOnly, RcvBufForce, consts::SOL_SOCKET, consts::SO_RCVBUFFORCE, usize);
-#[cfg(all(target_os = "linux", not(target_arch="arm")))]
-sockopt_impl!(SetOnly, SndBufForce, consts::SOL_SOCKET, consts::SO_SNDBUFFORCE, usize);
-sockopt_impl!(GetOnly, SockType, consts::SOL_SOCKET, consts::SO_TYPE, super::SockType);
-#[cfg(any(target_os = "freebsd",
- target_os = "linux",
- target_os = "nacl"))]
-sockopt_impl!(GetOnly, AcceptConn, consts::SOL_SOCKET, consts::SO_ACCEPTCONN, bool);
-#[cfg(target_os = "linux")]
-sockopt_impl!(GetOnly, OriginalDst, consts::SOL_IP, consts::SO_ORIGINAL_DST, sockaddr_in);
+sockopt_impl!(Both, TcpKeepIdle, libc::IPPROTO_TCP, libc::TCP_KEEPIDLE, u32);
+sockopt_impl!(Both, RcvBuf, libc::SOL_SOCKET, libc::SO_RCVBUF, usize);
+sockopt_impl!(Both, SndBuf, libc::SOL_SOCKET, libc::SO_SNDBUF, usize);
+#[cfg(any(target_os = "linux", target_os = "android"))]
+sockopt_impl!(SetOnly, RcvBufForce, libc::SOL_SOCKET, libc::SO_RCVBUFFORCE, usize);
+#[cfg(any(target_os = "linux", target_os = "android"))]
+sockopt_impl!(SetOnly, SndBufForce, libc::SOL_SOCKET, libc::SO_SNDBUFFORCE, usize);
+sockopt_impl!(GetOnly, SockType, libc::SOL_SOCKET, libc::SO_TYPE, super::SockType);
+sockopt_impl!(GetOnly, AcceptConn, libc::SOL_SOCKET, libc::SO_ACCEPTCONN, bool);
+#[cfg(any(target_os = "linux", target_os = "android"))]
+sockopt_impl!(GetOnly, OriginalDst, libc::SOL_IP, libc::SO_ORIGINAL_DST, sockaddr_in);
/*
*