Conversation
This commit updates the `udnspkt` module to make it work with current MicroPython versions. The code depended on two functions called `readbin` and `writebin` that operate on byte buffers, which are not present anymore in neither micropython-lib or micropython repositories. Those calls have been replaced with equivalent code that uses the `struct` module instead, or hardcoding a byte buffer with the static data being encoded. The module API was tweaked slightly, in which `udnspkt.parse_resp` now raises an exception if the DNS server on the other end refuses the request. The exception's payload is the raw response flags value from the server, in integer form. The sample code was also updated to make it work with CPython, to make sure the behaviour is consistent across interpreters too. And finally, the module is now 33 bytes shorter when compiled. Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
|
Nice improvement. Two consequences, if anything here grows an EDNS0 option later:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR updates the
udnspktmodule to make it work with current MicroPython versions.The code depended on two functions called
readbinandwritebinthat operate on byte buffers, which are not present anymore in neither micropython-lib or micropython repositories.Those calls have been replaced with equivalent code that uses the
structmodule instead, or hardcoding a byte buffer with the static data being encoded.The module API was tweaked slightly, in which
udnspkt.parse_respnow raises an exception if the DNS server on the other end refuses the request. The exception's payload is the raw response flags value from the server, in integer form.The sample code was also updated to make it work with CPython, to make sure the behaviour is consistent across interpreters too.
And finally, the module is now 33 bytes shorter when compiled :)
Testing
This was tested on Linux/x64 on both MicroPython built from current git
masterand CPython 3.14. The supplied sample code, once modified to make it work on CPython, behaves the same with both interpreters.The DNS server was changed to 8.8.8.8 and 9.9.9.9 to solicit valid responses and rejections (9.9.9.9 doesn't like being queried for google.com..).
Trade-offs and Alternatives
The main behaviour of the module wasn't changed, as in it will always return the first entry matching the required response type (IPv4 or IPv6), even if the server returned a list of possible IP addresses of a given type.
The module could be updated to return a generator instead and maybe still be smaller than the original once compiled.
Generative AI
I did not use generative AI tools when creating this PR.