For years now I have wanted to write a DI framework for Rust like I wrote for C++:
http://adam.younglogic.com/2008/07/dependency-injection-in-c/
However, I have not been able to wrap my head around how to do that. The problem is that the DI framework, which both creates and shares the instances, will come in to conflict with the borrow checker.
Category Archives: Rust
Hello World in rust on ARM64 includes a lot of code
I had not taken the time to try and work with Rust on ARM64 in the past. Since I was doing disassembly of simple C programs on an one of our servers, I figured it couldn’t hurt to try the same thing with rust.
Continue readingDHCP Lease Design
The key piece of persisted data in an DHCP server is the lease. A lease is a the mapping between a MAC address and an IP address, limited in time. A Lease typically has a start time and an end time, but can be renewed. Because I am still living in an IPV4 world, I have to deal with arbitrarily small pools of IP addresses. Thus, the design needs to strike the balance between static and dynamic: a machine should generally get back the same IP address each time. However, if addresses get tight, address reuse should be aggressive.
Continue readingInterpreting DHCP packets
To capture DHCP packets I ran:
tcpdump port 67 -i vnet0 -vvvv -w /tmp/packets.bin
That gave me a binary file 940 bytes long. This is actually 2 packets: the request and the response. This has the IP header, the UDP header, and the DHCP packet payload in it.
Continue readingExtract Function Refactoring using inline functions.
The Extract Function refactoring is the starting point for much of my code clean up. Once a “Main” function gets sufficiently complicated, I pull pieces of it out into their own functions, often with an eye to making them methods of the involved classes.
While working with some rust code, I encountered an opportunity to execute this refactoring on some logging code. Here’s how I executed it.
Continue readingAccessing C Arrays of String from Rust
Now that I can list the group names, I want to be able to list the member of the groups.
Continue readingIterating through an FFI API in Rust
Now that I know I can read a single group, the next step is to iterate.
Continue readingReading Linux groups via the Rust Foreign Function Interface
The world continues to embraces Rust for its safety properties. While writing utilities in Rust, we are going to have to work with existing code to perform common tasks. I recently needed to list the set of Linux groups registered on a system, and get access to the users assigned to each. Here’s my notes of what I learned.
Continue readingExtract Method Refactoring in Rust
I’m writing a simple utility for manage the /etc/hosts file. I want it in a native language so I can make it SUID, or even better, to lock it down via capabilities. I want to remember how to code in rust. Once I get a simple bit working, I want to refactor. Here’s what I did.
Continue readingA TFTP Server in Rust
Rust is Pedantic. I’m Pedantic. We get along wonderfully. Since HTTP is way too overdone, I wanted to try something at the Byte twiddling level. I got a very, very basic TFTP server to run and fetch a larger binary file without corrupting it. Time to celebrate with a bragpost.
Continue reading