Windows dynamic libraries, calling conventions, and transmute
So, how doesRead more
ping.exeactually send a ping? It seems unrealistic that
ping.exeitself implements all the protocols involved in sending a ping. So it must be calling some sort of library. Also, since it ends up talking to the outside world via a NIC (network interface...
FFI-safe types in Rust, newtypes, MaybeUninit, and references vs pointers
It’s time to make
sup, our own take on
ping, use the Win32 APIs to send an ICMP echo. Earlier we discovered that Windows’s
IcmpSendEcho2Ex. But for our purposes, the simpler
IcmpSendEchowill do just fine.
As we mentioned earlier, it’s provided...Read more
Designing and implementing a safer API on top of LoadLibrary
It’s refactor time!
Our complete program is now about a hundred lines, counting blank lines (see the end of part 3 for a complete listing).
While this is pretty good for a zero-dependency project (save for
pretty-hex), we can do better.
First off, concerns are mixed...Read more
A simple ping library, parsing strings into IPv4 address
We’ve just spent a lot of time abstracting over LoadLibrary, but we still have all the gory details of the Win32 ICMP API straight in our main.rs file! That won’t do.
This time will be much quicker, since we already learned about carefully designing an API, hiding...Read more
The builder pattern, and a macro that keeps FFI code DRY
Our ping API is simple, but it’s also very limited:
pub fn ping(dest: ipv4::Addr) -> Result<(), String> // called as: ping(ipv4::Addr([8, 8, 8, 8])).unwrap();
It doesn’t allow specifying the TTL (time to live) of packets, it doesn’t allow...Read more