| ▲ | messe 6 hours ago | |||||||||||||||||||||||||||||||
> 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. You can do the same in C, by calling socket(2) with the above arguments. It hinges on Linux allowing rootless pings from the GIDs in
EDIT: s/ICMP4/ICMP/gEDIT2: more spelling mistakes | ||||||||||||||||||||||||||||||||
| ▲ | scottlamb an hour ago | parent | next [-] | |||||||||||||||||||||||||||||||
> The issue is that the rust library apparently conflates datagram and UDP, when they're not the same thing. It comes down to these two lines (using full items paths for clarity):
The latter is using this impl: https://docs.rs/socket2/0.6.1/socket2/struct.Socket.html#imp...Basically the `socket2` crate lets you convert the fd it produces into a `UdpSocket`. It doesn't verify it really is a UDP socket first; that's up to you. If you do it blindly, you can get something with the wrong name, but it's probably harmless. (At the very least, it doesn't violate memory safety guarantees, which is what Rust code tends to be very strict about.) `UdpSocket` itself has a `From<OwnedFd>` impl that similarly doesn't check it really is a UDP socket; you could convert the `socket2::Socket` to an `OwnedFd` then that to a `UdpSocket`. https://doc.rust-lang.org/stable/std/net/struct.UdpSocket.ht... https://docs.rs/socket2/0.6.1/socket2/struct.Socket.html#imp... | ||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||
| ▲ | Quarrel 3 hours ago | parent | prev | next [-] | |||||||||||||||||||||||||||||||
Thank you. I assumed this was what was happening, but conflating network layer protocols with transport layer ones isn't great. I'm surprised that pedantic zealots, like me in my youth, haven't risen up and flooded rust with issues over it way before this though. | ||||||||||||||||||||||||||||||||
| ▲ | GTP 3 hours ago | parent | prev | next [-] | |||||||||||||||||||||||||||||||
Could you please explain me the difference? As UDP is the "User Datagram Protocol" when I read about datagrams I always think about UDP and though it was just a different way of saying the same thing. Maybe "datagram" is supposed to be the packet itself, but you're still sending it via UDP, right? | ||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||
| ▲ | krater23 5 hours ago | parent | prev [-] | |||||||||||||||||||||||||||||||
[flagged] | ||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||