A short (and mostly wrong) history of computer networking
When I launched my Patreon, I vowed to explain how computers work. But in 2019, computers rarely work in isolation. So let’s take the time to write a few articles about how computers talk to each other.
The history of network protocols and standards is long and...Read more
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
Down, down, down the stack
Let’s set aside our
supproject for a while.
Don’t get me wrong - it’s a perfectly fine project, and, were we simply rewriting “ping” for Windows in Rust, we could (almost) stop there.
We’re currently using the operating system’s...Read more
Okay, I lied.
I’m deciding - right this instant - that using wmic is cheating too. Oh, it was fair game when we were learning about Windows, but we’re past that now.
We know there’s IPv4 routing tables, and we know network interfaces have indices (yes, they...Read more
Consuming Ethernet with nom
Now that we’ve found the best way to find the “default network interface”… what can we do with that interface?
Well, listen for network traffic of course!
use rawsock::open_best_library; use std::time::Instant; fn main() -> Result<(), Error>...