summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2017-09-20 03:04:39 +0000
committerbors <bors@rust-lang.org>2017-09-20 03:04:39 +0000
commit322e59f06538a57f1d930a4871c4ee93bec040ba (patch)
treee93d5e0617b9af98673d3971f0a744e012e616d2
parent44e4018e1a37716286ec98cb5b7dd7d33ecaf940 (diff)
parentd18565cf6fbfedaa12b7d0046f50e73d7aa5343e (diff)
downloadrust-libc-322e59f06538a57f1d930a4871c4ee93bec040ba.tar.gz
Auto merge of #769 - redox-os:master, r=alexcrichton
[Redox] add net functions, fcntl, and close This adds net functions and two file functions: fcntl and close. It also adds related constants. The net functions are in a separate file for better organization.
-rw-r--r--src/redox/mod.rs (renamed from src/redox.rs)68
-rw-r--r--src/redox/net.rs110
2 files changed, 148 insertions, 30 deletions
diff --git a/src/redox.rs b/src/redox/mod.rs
index 7ff4ea05fd..82b296f965 100644
--- a/src/redox.rs
+++ b/src/redox/mod.rs
@@ -11,40 +11,17 @@ pub type pid_t = usize;
pub type gid_t = usize;
pub type uid_t = usize;
-pub type in_addr_t = u32;
-pub type in_port_t = u16;
-
-pub type socklen_t = u32;
-pub type sa_family_t = u16;
+pub type suseconds_t = i64;
s! {
- pub struct in_addr {
- pub s_addr: in_addr_t,
- }
-
- pub struct in6_addr {
- pub s6_addr: [u8; 16],
- __align: [u32; 0],
+ pub struct timeval {
+ pub tv_sec: time_t,
+ pub tv_usec: suseconds_t,
}
- pub struct sockaddr {
- pub sa_family: sa_family_t,
- pub sa_data: [::c_char; 14],
- }
-
- pub struct sockaddr_in {
- pub sin_family: sa_family_t,
- pub sin_port: ::in_port_t,
- pub sin_addr: ::in_addr,
- pub sin_zero: [u8; 8],
- }
-
- pub struct sockaddr_in6 {
- pub sin6_family: sa_family_t,
- pub sin6_port: in_port_t,
- pub sin6_flowinfo: u32,
- pub sin6_addr: ::in6_addr,
- pub sin6_scope_id: u32,
+ pub struct timespec {
+ pub tv_sec: time_t,
+ pub tv_nsec: c_long,
}
}
@@ -83,14 +60,45 @@ pub const S_IXOTH: mode_t = 0x1;
pub const S_IWOTH: mode_t = 0x2;
pub const S_IROTH: mode_t = 0x4;
+pub const F_DUPFD: ::c_int = 0;
+pub const F_GETFD: ::c_int = 1;
+pub const F_SETFD: ::c_int = 2;
+pub const F_GETFL: ::c_int = 3;
+pub const F_SETFL: ::c_int = 4;
+
+pub const O_RDONLY: ::c_int = 0x0001_0000;
+pub const O_WRONLY: ::c_int = 0x0002_0000;
+pub const O_RDWR: ::c_int = 0x0003_0000;
+pub const O_NONBLOCK: ::c_int = 0x0004_0000;
+pub const O_APPEND: ::c_int = 0x0008_0000;
+pub const O_SHLOCK: ::c_int = 0x0010_0000;
+pub const O_EXLOCK: ::c_int = 0x0020_0000;
+pub const O_ASYNC: ::c_int = 0x0040_0000;
+pub const O_FSYNC: ::c_int = 0x0080_0000;
+pub const O_CLOEXEC: ::c_int = 0x0100_0000;
+pub const O_CREAT: ::c_int = 0x0200_0000;
+pub const O_TRUNC: ::c_int = 0x0400_0000;
+pub const O_EXCL: ::c_int = 0x0800_0000;
+pub const O_DIRECTORY: ::c_int = 0x1000_0000;
+pub const O_STAT: ::c_int = 0x2000_0000;
+pub const O_SYMLINK: ::c_int = 0x4000_0000;
+pub const O_NOFOLLOW: ::c_int = 0x8000_0000;
+pub const O_ACCMODE: ::c_int = O_RDONLY | O_WRONLY | O_RDWR;
+
extern {
pub fn memalign(align: ::size_t, size: ::size_t) -> *mut ::c_void;
pub fn read(fd: ::c_int, buf: *mut ::c_void, count: ::size_t)
-> ::ssize_t;
pub fn write(fd: ::c_int, buf: *const ::c_void, count: ::size_t)
-> ::ssize_t;
+ pub fn fcntl(fd: ::c_int, cmd: ::c_int, ...) -> ::c_int;
+ pub fn close(fd: ::c_int) -> ::c_int;
}
#[link(name = "c")]
#[link(name = "m")]
extern {}
+
+pub use self::net::*;
+
+mod net;
diff --git a/src/redox/net.rs b/src/redox/net.rs
new file mode 100644
index 0000000000..0916916430
--- /dev/null
+++ b/src/redox/net.rs
@@ -0,0 +1,110 @@
+pub type in_addr_t = u32;
+pub type in_port_t = u16;
+
+pub type socklen_t = u32;
+pub type sa_family_t = u16;
+
+s! {
+ pub struct in_addr {
+ pub s_addr: in_addr_t,
+ }
+
+ pub struct in6_addr {
+ pub s6_addr: [u8; 16],
+ __align: [u32; 0],
+ }
+
+ pub struct ip_mreq {
+ pub imr_multiaddr: in_addr,
+ pub imr_interface: in_addr,
+ }
+
+ pub struct ipv6_mreq {
+ pub ipv6mr_multiaddr: in6_addr,
+ pub ipv6mr_interface: ::c_uint,
+ }
+
+ pub struct linger {
+ pub l_onoff: ::c_int,
+ pub l_linger: ::c_int,
+ }
+
+ pub struct sockaddr {
+ pub sa_family: sa_family_t,
+ pub sa_data: [::c_char; 14],
+ }
+
+ pub struct sockaddr_in {
+ pub sin_family: sa_family_t,
+ pub sin_port: ::in_port_t,
+ pub sin_addr: ::in_addr,
+ pub sin_zero: [u8; 8],
+ }
+
+ pub struct sockaddr_in6 {
+ pub sin6_family: sa_family_t,
+ pub sin6_port: in_port_t,
+ pub sin6_flowinfo: u32,
+ pub sin6_addr: ::in6_addr,
+ pub sin6_scope_id: u32,
+ }
+
+ pub struct sockaddr_storage {
+ pub ss_family: sa_family_t,
+ pub __ss_padding: [u8; 26],
+ }
+}
+
+pub const AF_INET: ::c_int = 2;
+pub const AF_INET6: ::c_int = 23;
+
+pub const SOCK_STREAM: ::c_int = 1;
+pub const SOCK_DGRAM: ::c_int = 2;
+
+pub const IPPROTO_TCP: ::c_int = 6;
+pub const IPPROTO_IP: ::c_int = 0;
+pub const IPPROTO_IPV6: ::c_int = 41;
+
+pub const TCP_KEEPIDLE: ::c_int = 4;
+pub const TCP_NODELAY: ::c_int = 8193;
+
+pub const IP_TTL: ::c_int = 8;
+pub const IP_MULTICAST_LOOP: ::c_int = 9;
+pub const IP_MULTICAST_TTL: ::c_int = 10;
+pub const IP_ADD_MEMBERSHIP: ::c_int = 11;
+pub const IP_DROP_MEMBERSHIP: ::c_int = 12;
+
+pub const IPV6_MULTICAST_LOOP: ::c_int = 19;
+pub const IPV6_ADD_MEMBERSHIP: ::c_int = 20;
+pub const IPV6_DROP_MEMBERSHIP: ::c_int = 21;
+pub const IPV6_V6ONLY: ::c_int = 26;
+
+pub const SOL_SOCKET: ::c_int = 65535;
+
+pub const SO_REUSEADDR: ::c_int = 4;
+pub const SO_BROADCAST: ::c_int = 6;
+pub const SO_KEEPALIVE: ::c_int = 8;
+pub const SO_RCVTIMEO: ::c_int = 20;
+pub const SO_SNDTIMEO: ::c_int = 21;
+pub const SO_LINGER: ::c_int = 128;
+pub const SO_SNDBUF: ::c_int = 4097;
+pub const SO_RCVBUF: ::c_int = 4098;
+pub const SO_ERROR: ::c_int = 4105;
+
+extern {
+ pub fn socket(domain: ::c_int, ty: ::c_int, protocol: ::c_int) -> ::c_int;
+ pub fn bind(fd: ::c_int, addr: *const sockaddr, len: socklen_t) -> ::c_int;
+ pub fn connect(socket: ::c_int, address: *const sockaddr,
+ len: socklen_t) -> ::c_int;
+ pub fn listen(socket: ::c_int, backlog: ::c_int) -> ::c_int;
+ pub fn getsockname(socket: ::c_int, address: *mut sockaddr,
+ address_len: *mut socklen_t) -> ::c_int;
+ pub fn getsockopt(sockfd: ::c_int,
+ level: ::c_int,
+ optname: ::c_int,
+ optval: *mut ::c_void,
+ optlen: *mut ::socklen_t) -> ::c_int;
+ pub fn setsockopt(socket: ::c_int, level: ::c_int, name: ::c_int,
+ value: *const ::c_void,
+ option_len: socklen_t) -> ::c_int;
+}