Live data from Hacker News

Rootless Pings in Rust

bou.ke

31–40 of 87 posts

Re: Rootless Pings in Rust

#31
post #22
post #16

This is interesting, but falls just short of explaining what's going on. Why does UDP work for ICMP? What does the final packet look like, and how is ICMP different from UDP? None of that is explained, it's just "do you want ICMP? Just use UDP" and that's it. It would have been OK if it were posted as a short reference to something common people might wonder about, but I don't know how often people try to reimplement…

The BSD socket API has 3 parameters when creating a socket with socket(), the family (e.g. inet) the kind (datagram in this case) and the protocol (often 0, but IPPROTO_ICMP in this case). Because when the protocol is 0 it means a UDP socket Rust has called its API for creating any(?) datagram sockets UdpSocket, partly resulting in this confusion. The kernel patch introducing the API also explains it was partly based…

So UdpSocket should really be called DatagramSocket, UDP being the protocol that operates on these datagrams?

Surprising that they got such a fundamental thing wrong.

Re: Rootless Pings in Rust

#32
post #27

Earlier quoted context omitted.

ICMP is just different protocol from UDP. There's field "Protocol" in IP packet. 0x01 = ICMP, 0x06 = TCP, 0x11 = UDP. I think that this article gets terminology wrong. It's not UDP socket that gets created here, but Datagram socket. Seems to be bad API naming in Rust library.

> It's not UDP socket that gets created here, but Datagram socket A datagram socket is a UDP socket, though. That's what the D stands for.

Wrong way around: UDP sockets are datagram sockets, there are datagram sockets that are not UDP.

Re: Rootless Pings in Rust

#33
post #22

Earlier quoted context omitted.

The BSD socket API has 3 parameters when creating a socket with socket(), the family (e.g. inet) the kind (datagram in this case) and the protocol (often 0, but IPPROTO_ICMP in this case). Because when the protocol is 0 it means a UDP socket Rust has called its API for creating any(?) datagram sockets UdpSocket, partly resulting in this confusion. The kernel patch introducing the API also explains it was partly based…

So UdpSocket should really be called DatagramSocket, UDP being the protocol that operates on these datagrams? Surprising that they got such a fundamental thing wrong.

That happens when someones learning project ("I rewrite a library in the new language I want to learn") ends up in productive code.

Re: Rootless Pings in Rust

#34
post #25

> It turns out you can create a UDP socket with a protocol flag, which allows you to send the ping rootless This is wrong, despite the Rust library in question's naming convention. You're not creating a UDP socket. You're creating an IP (AF_INET), datagram socket (SOCK_DGRAM), using protocol ICMP (IPPROTO_ICMP). The issue is that the rust library apparently conflates datagram and UDP, when they're not the same thing.…

[flagged]

Re: Rootless Pings in Rust

#35

Earlier quoted context omitted.

So UdpSocket should really be called DatagramSocket, UDP being the protocol that operates on these datagrams? Surprising that they got such a fundamental thing wrong.

That happens when someones learning project ("I rewrite a library in the new language I want to learn") ends up in productive code.

This is in the standard library; it's not a learning project. And it also isn't even incorrect - see erk__'s comment.

Rust is an excellent language and fully capable of production use.

Re: Rootless Pings in Rust

#36
post #27

Earlier quoted context omitted.

ICMP is just different protocol from UDP. There's field "Protocol" in IP packet. 0x01 = ICMP, 0x06 = TCP, 0x11 = UDP. I think that this article gets terminology wrong. It's not UDP socket that gets created here, but Datagram socket. Seems to be bad API naming in Rust library.

> It's not UDP socket that gets created here, but Datagram socket A datagram socket is a UDP socket, though. That's what the D stands for.

No? Why would you think a datagram socket is UDP?

Re: Rootless Pings in Rust

#37
post #30
post #22

Earlier quoted context omitted.

The BSD socket API has 3 parameters when creating a socket with socket(), the family (e.g. inet) the kind (datagram in this case) and the protocol (often 0, but IPPROTO_ICMP in this case). Because when the protocol is 0 it means a UDP socket Rust has called its API for creating any(?) datagram sockets UdpSocket, partly resulting in this confusion. The kernel patch introducing the API also explains it was partly based…

The std api can only create UdpSockets, the trick here is that you use Socket2 which allows more kinds of sockets and then you tell UdpSocket that some raw file descriptor is a upd socket through a unsafe api with no checks and I guess it works because they use the same api on posix. Edit: It is possible in safe rust as well, see child comment. The macro used by socket2: https://docs.rs/socket2/0.6.1/src/socket2/lib.…

From/Into conversion via OwnedFd is the safe API, RawFd is the older and lower-level one.

Re: Rootless Pings in Rust

#38
Great article, it lead me to the `icmplib`[0] Python project, which has a `privileged` option:

  When this option is enabled, this library fully manages the exchanges and the structure of ICMP packets. Disable this option if you want to use this function without root privileges and let the kernel handle ICMP headers.
[0] https://github.com/ValentinBELYN/icmplib

Re: Rootless Pings in Rust

#39
post #27

Earlier quoted context omitted.

> It's not UDP socket that gets created here, but Datagram socket A datagram socket is a UDP socket, though. That's what the D stands for.

No? Why would you think a datagram socket is UDP?

What a reasonable question to be asked today.

Re: Rootless Pings in Rust

#40
post #4

I struggled in vain to see what this has to do with rust. The answer is nothing other than the 4 lines of sample code shown are in Rust. The actually useful nugget of knowledge contained therein (one can create ICMP packets without being root on MacOS or Linux) is language agnostic. So... why? Should I now add "in C" or "in assembly" to the end of all my article titles?

Agreed. I don't dislike Rust as a language, but it annoys me how its practitioners add the "[written] in Rust" tagline to every single thing they do that's otherwise unrelated to Rust. Specially when their code or dependencies are full of unverified unsafe blocks, which defeats the selling point.
Post reply on HN