Skip to content

Commit

Permalink
feat(net): add support for ping sockets (#101) - WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
fujiapple852 committed Oct 16, 2023
1 parent 84020e4 commit 03d2327
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
9 changes: 5 additions & 4 deletions src/caps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ pub fn drop_caps() -> anyhow::Result<()> {
#[allow(clippy::unnecessary_wraps)]
/// Ensure the effective user is `root`.
pub fn ensure_caps() -> anyhow::Result<()> {
if !nix::unistd::Uid::effective().is_root() {
eprintln!("root user required to use raw sockets, see https://github.com/fujiapple852/trippy#privileges");
std::process::exit(-1);
}
// TODO we need a way to know if we're going to need caps before we check this
// if !nix::unistd::Uid::effective().is_root() {
// eprintln!("root user required to use raw sockets, see https://github.com/fujiapple852/trippy#privileges");
// std::process::exit(-1);
// }
Ok(())
}

Expand Down
1 change: 1 addition & 0 deletions src/tracing/net/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ impl<S: Socket> TracerChannel<S> {
TracerProtocol::Udp => Some(make_udp_send_socket(config.source_addr)?),
TracerProtocol::Tcp => None,
};

let recv_socket = make_recv_socket(config.source_addr)?;
Ok(Self {
protocol: config.protocol,
Expand Down
8 changes: 6 additions & 2 deletions src/tracing/net/platform/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,9 @@ impl SocketImpl {
impl Socket for SocketImpl {
#[instrument]
fn new_icmp_send_socket_ipv4() -> IoResult<Self> {
let socket = Self::new_raw_ipv4(Protocol::from(nix::libc::IPPROTO_RAW))?;
let socket = Self::new(Domain::IPV4, Type::DGRAM, Protocol::ICMPV4)?;
// TODO
// let socket = Self::new_raw_ipv4(Protocol::from(nix::libc::IPPROTO_RAW))?;
socket.set_nonblocking(true)?;
socket.set_header_included(true)?;
Ok(socket)
Expand All @@ -235,7 +237,9 @@ impl Socket for SocketImpl {
}
#[instrument]
fn new_recv_socket_ipv4(addr: Ipv4Addr) -> IoResult<Self> {
let socket = Self::new_raw_ipv4(Protocol::ICMPV4)?;
let socket = Self::new(Domain::IPV4, Type::DGRAM, Protocol::ICMPV4)?;
// TODO
// let socket = Self::new_raw_ipv4(Protocol::ICMPV4)?;
socket.set_nonblocking(true)?;
socket.set_header_included(true)?;
Ok(socket)
Expand Down

0 comments on commit 03d2327

Please sign in to comment.