>
> 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."


Yes you can.

https://docs.python.org/3/library/socket.html

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.



    df_status = s.getsockopt(socket.IPPROTO_IP, socket.IP_DONTFRAG)
    print(f"Don't Fragment flag status: {df_status}")


On Sun, Aug 10, 2025 at 9:31 PM William Herrin via NANOG <
[email protected]> wrote:

> On Sun, Aug 10, 2025 at 5:56 PM John Levine <[email protected]> wrote:
> > It appears that William Herrin via NANOG <[email protected]> said:
> > >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."
> >
> > The python struct module is pretty fast, since it's written in C.
>
> Hi John,
>
> That's the difference. In Python you have a complex software library
> which can shuttle data back and forth between Python's internal data
> management process and an arbitrary byte-oriented data structure. In
> C, that arbitrary data structure is a first class citizen in the core
> language and no translation is needed.
>
> You could pull apart a DNS packet in a Bash shell script if you really
> wanted to. The code complexity would be out of sight and it would run
> orders of magnitude slower than Python or C, but it can be done. Just
> because a thing can be done doesn't mean the language is an optimal
> choice for the task.
>
> Regards,
> Bill Herrin
>
>
> --
> William Herrin
> [email protected]
> https://bill.herrin.us/
> _______________________________________________
> NANOG mailing list
>
> https://lists.nanog.org/archives/list/[email protected]/message/LVNUTOYAVDB5AEQSPNQI22YJCLYUBRFJ/
_______________________________________________
NANOG mailing list 
https://lists.nanog.org/archives/list/[email protected]/message/AKI6PGZI5DRVDNQQ2TGFD74MEEX7BHNR/

Reply via email to