Try libc sockets
This commit is contained in:
parent
753cd0f58f
commit
08fb8dd01e
3 changed files with 26 additions and 0 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -154,6 +154,7 @@ name = "rustraceroute"
|
||||||
version = "0.0.0"
|
version = "0.0.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"clap",
|
"clap",
|
||||||
|
"libc",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|
|
@ -12,3 +12,4 @@ categories = ["command-line-utilities", "network-programming"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
clap = "3.0.0-beta.2"
|
clap = "3.0.0-beta.2"
|
||||||
|
libc = "0.2.81"
|
||||||
|
|
24
src/main.rs
24
src/main.rs
|
@ -1,4 +1,5 @@
|
||||||
use clap::{Clap};
|
use clap::{Clap};
|
||||||
|
use libc;
|
||||||
|
|
||||||
const CRATE_NAME: &str = env!("CARGO_PKG_NAME");
|
const CRATE_NAME: &str = env!("CARGO_PKG_NAME");
|
||||||
|
|
||||||
|
@ -37,4 +38,27 @@ fn main() {
|
||||||
let options = Options::parse();
|
let options = Options::parse();
|
||||||
|
|
||||||
println!("{:?}", options);
|
println!("{:?}", options);
|
||||||
|
|
||||||
|
let socket = unsafe {
|
||||||
|
libc::socket(libc::AF_INET, libc::SOCK_RAW, libc::IPPROTO_ICMP)
|
||||||
|
};
|
||||||
|
|
||||||
|
let sockaddr = libc::sockaddr_in {
|
||||||
|
sin_family: libc::AF_INET as libc::sa_family_t,
|
||||||
|
sin_port: 0,
|
||||||
|
sin_addr: libc::in_addr {
|
||||||
|
s_addr: 0,
|
||||||
|
},
|
||||||
|
sin_zero: [0; 8],
|
||||||
|
};
|
||||||
|
|
||||||
|
let bind_result = unsafe {
|
||||||
|
libc::bind(
|
||||||
|
socket,
|
||||||
|
&sockaddr as *const libc::sockaddr_in as *const libc::sockaddr,
|
||||||
|
std::mem::size_of::<libc::sockaddr_in>() as libc::socklen_t
|
||||||
|
)
|
||||||
|
};
|
||||||
|
|
||||||
|
assert!(bind_result == 0);
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue