
On Sun, Aug 10, 2025 at 3:41 AM Etienne-Victor Depasquale <edepa@ieee.org> wrote:
Python is, well, Python. It makes as much sense to me to write a DNS server in Perl or Javascript, which is to say: not much.
I don't follow. What's the objection?
Howdy, On the way in, DNS takes a data buffer delivered from the network stack and imposes a strange and complex order on the bytes. On the way back out, it takes complex data and arranges it back into the same precise structure before passing a simple array of bytes down into the network stack. Some languages are well suited to this sort of task. In C, for example, you mostly just "cast" a well designed data structure from the pointer to the buffer of bytes. You haven't moved or interpreted or copied around the data in the buffer, but viola - you can now directly access the bits and bytes by mnemonic reference. C has adapted itself to your precise data structure with minimal fuss. Python doesn't work this way. Its memory management is abstracted away from the programmer and the programmer does not control its precise structure. For Python to access a DNS packet, the programmer must pack and unpack an array of bytes using complex software of their own devising. You can't just tell Python, "This is the complex data structure these bytes contain, let me access the data without unpacking it." This makes Python code for network handling more complex and much slower than comparable code for C needs to be. That's not a knock against Python. Most high-level languages abstract away the exact handling of data in memory so that programmers can focus on what their data contains instead of how it's stored. For many programming tasks that makes programming easier. But not for handling network packets which differ from the language's internal structure. Let me leave you with an example to make things more clear. Consider the following data structures for accessing an IPv4 or IPv6 header in C: https://github.com/CAIDA/mrt-tools/blob/main/src/addresses.h With these data structures you can: header = (struct ipv4_header*) byte_buffer; printf ("Don't fragment bit is: %s\n", header->dont_fragment?"set":"unset"); Not only is that code simple, the amount of work the CPU has to do to execute that code is trivial. Regards, Bill Herrin -- William Herrin bill@herrin.us https://bill.herrin.us/