From 992e50ef0f34e753bf4786ce315a5a8a88b530b8 Mon Sep 17 00:00:00 2001 From: jD91mZM2 Date: Wed, 25 Jul 2018 14:04:36 +0200 Subject: [PATCH] Fix a few things with openssl --- Cargo.lock | 10 ++++++++++ Cargo.toml | 3 ++- src/lib.rs | 1 + src/netinet/in/src/lib.rs | 16 +++++++++++++--- src/platform/src/redox/mod.rs | 13 +++---------- src/sys_un/Cargo.toml | 12 ++++++++++++ src/sys_un/build.rs | 11 +++++++++++ src/sys_un/cbindgen.toml | 10 ++++++++++ src/sys_un/src/lib.rs | 13 +++++++++++++ 9 files changed, 75 insertions(+), 14 deletions(-) create mode 100644 src/sys_un/Cargo.toml create mode 100644 src/sys_un/build.rs create mode 100644 src/sys_un/cbindgen.toml create mode 100644 src/sys_un/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index c0c253e6e0..b5492d7c19 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -322,6 +322,7 @@ dependencies = [ "sys_socket 0.1.0", "sys_stat 0.1.0", "sys_time 0.1.0", + "sys_un 0.1.0", "sys_utsname 0.1.0", "sys_wait 0.1.0", "time 0.1.0", @@ -533,6 +534,15 @@ dependencies = [ "platform 0.1.0", ] +[[package]] +name = "sys_un" +version = "0.1.0" +dependencies = [ + "cbindgen 0.5.2", + "platform 0.1.0", + "sys_socket 0.1.0", +] + [[package]] name = "sys_utsname" version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml index ae570caa2d..a1879aa122 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,8 +25,8 @@ inttypes = { path = "src/inttypes" } locale = { path = "src/locale" } netinet = { path = "src/netinet" } platform = { path = "src/platform" } -setjmp = { path = "src/setjmp" } semaphore = { path = "src/semaphore" } +setjmp = { path = "src/setjmp" } signal = { path = "src/signal" } stdio = { path = "src/stdio" } stdlib = { path = "src/stdlib" } @@ -37,6 +37,7 @@ sys_resource = { path = "src/sys_resource" } sys_socket = { path = "src/sys_socket" } sys_stat = { path = "src/sys_stat" } sys_time = { path = "src/sys_time" } +sys_un = { path = "src/sys_un" } sys_utsname = { path = "src/sys_utsname" } sys_wait = { path = "src/sys_wait" } time = { path = "src/time" } diff --git a/src/lib.rs b/src/lib.rs index 050e466eea..bb95601c78 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -27,6 +27,7 @@ pub extern crate sys_resource; pub extern crate sys_socket; pub extern crate sys_stat; pub extern crate sys_time; +pub extern crate sys_un; pub extern crate sys_utsname; pub extern crate sys_wait; pub extern crate time; diff --git a/src/netinet/in/src/lib.rs b/src/netinet/in/src/lib.rs index 0994028d65..2f909a3d75 100644 --- a/src/netinet/in/src/lib.rs +++ b/src/netinet/in/src/lib.rs @@ -6,13 +6,13 @@ extern crate platform; extern crate sys_socket; use platform::types::*; -use sys_socket::sa_family_t; +use sys_socket::{sa_family_t, sockaddr}; pub type in_addr_t = u32; pub type in_port_t = u16; #[repr(C)] -#[derive(Debug)] +#[derive(Debug, Clone, Copy)] pub struct in_addr { pub s_addr: in_addr_t } @@ -24,7 +24,7 @@ pub struct in6_addr { #[repr(C)] pub struct sockaddr_in { - pub sa_family: sa_family_t, + pub sin_family: sa_family_t, pub sin_port: in_port_t, pub sin_addr: in_addr } @@ -56,3 +56,13 @@ pub const IPPROTO_UDP: u8 = 0x11; pub const IPPROTO_IPV6: u8 = 0x29; pub const IPPROTO_RAW: u8 = 0xff; pub const IPPROTO_MAX: u8 = 0xff; + +pub const INADDR_ANY: u32 = 0; // Can't use in_addr_t alias because cbindgen :( +pub const INADDR_BROADCAST: u32 = 0xFFFFFFFF; // Can't use core::u32::MAX because cbindgen :( +pub const INADDR_NONE: u32 = 0xFFFFFFFF; +pub const INADDR_LOOPBACK: u32 = 0x7F000001; + +pub const INADDR_UNSPEC_GROUP: u32 = 0xE0000000; +pub const INADDR_ALLHOSTS_GROUP: u32 = 0xE0000001; +pub const INADDR_ALLRTRS_GROUP: u32 = 0xE0000002; +pub const INADDR_MAX_LOCAL_GROUP: u32 = 0xE00000FF; diff --git a/src/platform/src/redox/mod.rs b/src/platform/src/redox/mod.rs index 8ac654c377..6cfbecf139 100644 --- a/src/platform/src/redox/mod.rs +++ b/src/platform/src/redox/mod.rs @@ -21,13 +21,6 @@ extern "C" fn sig_handler(sig: usize) { } } -#[repr(C)] -struct SockData { - port: in_port_t, - addr: in_addr_t, - _pad: [c_char; 8], -} - fn e(sys: Result) -> usize { match sys { Ok(ok) => ok, @@ -56,9 +49,9 @@ macro_rules! bind_or_connect { errno = syscall::EINVAL; return -1; } - let data: &SockData = mem::transmute(&(*$address).data); - let addr = &data.addr; - let port = in_port_t::from_be(data.port); // This is transmuted from bytes in BigEndian order + let data = &*($address as *const sockaddr_in); + let addr = &data.sin_addr.s_addr; + let port = in_port_t::from_be(data.sin_port); // This is transmuted from bytes in BigEndian order let path = format!(bind_or_connect!($mode "{}.{}.{}.{}:{}"), addr[0], addr[1], addr[2], addr[3], port); // Duplicate the socket, and then duplicate the copy back to the original fd diff --git a/src/sys_un/Cargo.toml b/src/sys_un/Cargo.toml new file mode 100644 index 0000000000..be0e821f65 --- /dev/null +++ b/src/sys_un/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "sys_un" +version = "0.1.0" +authors = ["jD91mZM2 "] +build = "build.rs" + +[build-dependencies] +cbindgen = { path = "../../cbindgen" } + +[dependencies] +platform = { path = "../platform" } +sys_socket = { path = "../sys_socket" } diff --git a/src/sys_un/build.rs b/src/sys_un/build.rs new file mode 100644 index 0000000000..fcf990a9ff --- /dev/null +++ b/src/sys_un/build.rs @@ -0,0 +1,11 @@ +extern crate cbindgen; + +use std::{env, fs}; + +fn main() { + let crate_dir = env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR not set"); + fs::create_dir_all("../../target/include").expect("failed to create include directory"); + cbindgen::generate(crate_dir) + .expect("failed to generate bindings") + .write_to_file("../../target/include/sys/un.h"); +} diff --git a/src/sys_un/cbindgen.toml b/src/sys_un/cbindgen.toml new file mode 100644 index 0000000000..8a6d7cdf4e --- /dev/null +++ b/src/sys_un/cbindgen.toml @@ -0,0 +1,10 @@ +sys_includes = ["sys/socket.h"] +include_guard = "_SYS_UN_H" +language = "C" +style = "Tag" + +[export] +include = ["sockaddr_un"] + +[enum] +prefix_with_name = true diff --git a/src/sys_un/src/lib.rs b/src/sys_un/src/lib.rs new file mode 100644 index 0000000000..577f49a048 --- /dev/null +++ b/src/sys_un/src/lib.rs @@ -0,0 +1,13 @@ +#![no_std] + +extern crate platform; +extern crate sys_socket; + +use platform::types::*; +use sys_socket::sa_family_t; + +#[repr(C)] +pub struct sockaddr_un { + sun_family: sa_family_t, + sun_path: [c_char; 108] +}