diff --git a/Cargo.lock b/Cargo.lock index 4eab6e0089b4d63547346eb913bc0dd5b23e3df5..b69becf5443ba5bfc82ef60de2acc639d5ccb7b2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -139,6 +139,14 @@ dependencies = [ "platform 0.1.0", ] +[[package]] +name = "in_h" +version = "0.1.0" +dependencies = [ + "cbindgen 0.5.2", + "platform 0.1.0", +] + [[package]] name = "itoa" version = "0.3.4" @@ -182,6 +190,13 @@ dependencies = [ "platform 0.1.0", ] +[[package]] +name = "netinet" +version = "0.1.0" +dependencies = [ + "in_h 0.1.0", +] + [[package]] name = "num-traits" version = "0.2.1" @@ -259,6 +274,7 @@ dependencies = [ "float 0.1.0", "grp 0.1.0", "mman 0.1.0", + "netinet 0.1.0", "platform 0.1.0", "resource 0.1.0", "semaphore 0.1.0", diff --git a/Cargo.toml b/Cargo.toml index f1481acd6b3ecc9f0e818d5f729d959b64711412..42b6f836216ebcedcd8e765be556f0231fb87f95 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,6 +19,7 @@ fenv = { path = "src/fenv" } float = { path = "src/float" } grp = { path = "src/grp" } mman = { path = "src/mman" } +netinet = { path = "src/netinet" } platform = { path = "src/platform" } resource = { path = "src/resource" } semaphore = { path = "src/semaphore" } diff --git a/src/lib.rs b/src/lib.rs index 27572f76faf87d048f729af7f27319c78125d99c..2a0f87862f9b0ed2e7da31061d396d5fd65e98ca 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -11,6 +11,7 @@ extern crate fenv; extern crate float; extern crate grp; extern crate mman; +extern crate netinet; extern crate resource; extern crate semaphore; extern crate socket; diff --git a/src/netinet/Cargo.toml b/src/netinet/Cargo.toml new file mode 100644 index 0000000000000000000000000000000000000000..eccbe4ee946f16f08bdc0199b9f56eddae72f4e6 --- /dev/null +++ b/src/netinet/Cargo.toml @@ -0,0 +1,7 @@ +[package] +name = "netinet" +version = "0.1.0" +authors = ["Dan Robertson <danlrobertson89@gmail.com>"] + +[dependencies] +in_h = { path = "in" } diff --git a/src/netinet/in/Cargo.toml b/src/netinet/in/Cargo.toml new file mode 100644 index 0000000000000000000000000000000000000000..4bd5518ba25d7b3200171f5777861d8f1fd56353 --- /dev/null +++ b/src/netinet/in/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "in_h" +version = "0.1.0" +authors = ["Dan Robertson <danlrobertson89@gmail.com>"] +build = "build.rs" + +[build-dependencies] +cbindgen = { path = "../../../cbindgen" } + +[dependencies] +platform = { path = "../../platform" } +socket = { path = "../../socket" } diff --git a/src/netinet/in/build.rs b/src/netinet/in/build.rs new file mode 100644 index 0000000000000000000000000000000000000000..f9df3f1a781856bd52f511d854dc728929e80483 --- /dev/null +++ b/src/netinet/in/build.rs @@ -0,0 +1,12 @@ +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"); + fs::create_dir_all("../../../target/include/netinet").expect("failed to create include directory"); + cbindgen::generate(crate_dir) + .expect("failed to generate bindings") + .write_to_file("../../../target/include/netinet/in.h"); +} diff --git a/src/netinet/in/cbindgen.toml b/src/netinet/in/cbindgen.toml new file mode 100644 index 0000000000000000000000000000000000000000..0067295d34e11baab150431dfa4dc8246bb5a541 --- /dev/null +++ b/src/netinet/in/cbindgen.toml @@ -0,0 +1,10 @@ +sys_includes = ["sys/types.h", "sys/socket.h"] +include_guard = "_NETINET_IN_H" +style = "Tag" +language = "C" + +[export] +include = ["sockaddr_in6", "sockaddr_in", "ipv6_mreq"] + +[enum] +prefix_with_name = true diff --git a/src/netinet/in/src/lib.rs b/src/netinet/in/src/lib.rs new file mode 100644 index 0000000000000000000000000000000000000000..789a9e4b4b02309951b05a7ce0da7863dbd7f791 --- /dev/null +++ b/src/netinet/in/src/lib.rs @@ -0,0 +1,58 @@ +#![no_std] + +#![allow(non_camel_case_types)] + +extern crate platform; +extern crate socket; + +use platform::types::*; +use socket::sa_family_t; + +pub type in_addr_t = u32; +pub type in_port_t = u16; + +#[repr(C)] +#[derive(Debug)] +pub struct in_addr { + pub s_addr: in_addr_t +} + +#[repr(C)] +pub struct in6_addr { + pub s6_addr: [u8; 16] +} + +#[repr(C)] +pub struct sockaddr_in { + pub sa_family: sa_family_t, + pub sin_port: in_port_t, + pub sin_addr: in_addr +} + +#[repr(C)] +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 +} + +#[repr(C)] +pub struct ipv6_mreq { + pub ipv6mr_multiaddr: in6_addr, + pub ipv6mr_interface: u32, +} + +// Address String Lengths +pub const INET_ADDRSTRLEN: c_int = 16; +pub const INET6_ADDRSTRLEN: c_int = 46; + +// Protocol Numbers +pub const IPPROTO_IP: u8 = 0x00; +pub const IPPROTO_ICMP: u8 = 0x01; +pub const IPPROTO_TCP: u8 = 0x06; +pub const IPPROTO_UDP: u8 = 0x11; +pub const IPPROTO_IPV6: u8 = 0x29; +pub const IPPROTO_RAW: u8 = 0xff; +pub const IPPROTO_MAX: u8 = 0xff; diff --git a/src/netinet/src/lib.rs b/src/netinet/src/lib.rs new file mode 100644 index 0000000000000000000000000000000000000000..40de25ffa28c14860ecd6c0810bc3bdefef45359 --- /dev/null +++ b/src/netinet/src/lib.rs @@ -0,0 +1,3 @@ +#![no_std] + +extern crate in_h;