1
0
Fork 0

Try libc sockets

This commit is contained in:
Alex Kotov 2020-12-31 13:43:06 +05:00
parent 753cd0f58f
commit 08fb8dd01e
Signed by: kotovalexarian
GPG Key ID: 553C0EBBEB5D5F08
3 changed files with 26 additions and 0 deletions

1
Cargo.lock generated
View File

@ -154,6 +154,7 @@ name = "rustraceroute"
version = "0.0.0"
dependencies = [
"clap",
"libc",
]
[[package]]

View File

@ -12,3 +12,4 @@ categories = ["command-line-utilities", "network-programming"]
[dependencies]
clap = "3.0.0-beta.2"
libc = "0.2.81"

View File

@ -1,4 +1,5 @@
use clap::{Clap};
use libc;
const CRATE_NAME: &str = env!("CARGO_PKG_NAME");
@ -37,4 +38,27 @@ fn main() {
let options = Options::parse();
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);
}