Comments (5)
Just released v0.3.2. Thanks for your help!
from dns-parser.
First, I was wondering if there was a reason you hadn't implemented nameservers yet. It looks like it's trivially easy since the parsing is the same as parsing Answers, at least it seems that way to me. I did that and it worked. Is there some edge case I'm missing?
If you've done that, please provide a pull request.
I don't think there is an edge case, I just never needed it myself.
My other more important question is do you think there is a good way in the Name struct to store the display version of the name (ie a vec of www.google.com instead of the label slice which would be the offset value to www.google.com)?
I wanted to avoid memory allocations at this level.
I could just convert the label into a string since you have it implemented, but I don't like the idea of having to parse the data again to convert it when we've already done the offset parsing during the validation.
You need another level of abstraction anyway. For example, here is a wrapper structure of rotor-dns. If we decode names in dns-parser we would need to clone strings twice (or alternatively decompose structure in some non-convenient way).
What's your use case? Wouldn't you benefit from the rotor-dns instead of using dns-parser directly?
from dns-parser.
So I made a pull request here
#4
I could also add another loop to do additional records parsing, but I didn't want to deal with making a test for that.
I was also wondering if you'd be ok with me adding a separate function that essentially does the offset translation you do when implementing display
for name
but instead returns a vec of bytes.
Then in your display
impl, you could just call that and convert it into a str before writing it. The function would be something like this
pub fn read_from_offset(&self, mut offsetted_value: Vec<u8>) -> Result<Vec<u8>, Error> {
let data = self.labels;
let original = self.original;
let mut pos = 0;
loop {
let byte = data[pos];
if byte == 0 {
return Ok(offsetted_value);
} else if byte & 0b1100_0000 == 0b1100_0000 {
let off = (BigEndian::read_u16(&data[pos..pos+2])
& !0b1100_0000_0000_0000) as usize;
if pos != 0 {
offsetted_value.push(46u8) // '.' ascii value
}
return Name::scan(&original[off..], original).unwrap()
.read_from_offset(offsetted_value);
} else if byte & 0b1100_0000 == 0 {
if pos != 0 {
offsetted_value.push(46u8) // '.' ascii value
}
let end = pos + byte as usize + 1;
offsetted_value.extend_from_slice(&data[pos+1..end]);
pos = end;
continue;
} else {
unreachable!();
}
}
}
If you don't want to add that, I can just add that to my repo directly instead.
My use case is that I want to parse individual dns packets and output the answer and nameserver records to file in a specific format.
Rotor-dns seems like too much abstraction for me.
Thanks for taking the time to read this!
from dns-parser.
Hi,
Doing what you specified will incur a separate scan of the Vec<u8>
when doing String::from_utf8()
(to ensure that all characters are valid utf-8). Also for Display
trait we don't allocate anything. I.e. we write bytes dirrectly into the underlying buffer.
For your use case you can do the following (which I believe should be as efficient as the code above):
write!(&mut vec, "{}", name).unwrap()
Other hints to the code above:
- you can use
b'.'
instead of46u8
, this makes code clear without a comment - it's usually an anti-pattern to pass the vector by the argument, mutate and return it back, either pass a mutable reference to vector and return
Ok(())
or return a completely new vector.
from dns-parser.
Your suggestion seems like it should work. Thank you for the other tips as well.
When do you think the namesever parsing addtion will get released? I would like to not have to carry a local copy of your crate in my repo if possible.
Besides that, feel free to close my issue.
from dns-parser.
Related Issues (16)
- Couple of comments on parsing HOT 3
- Make new release with two most recent commits? HOT 3
- Unsupported query types are being parsed as A records HOT 2
- Valid TXT records may contain binary data HOT 3
- TXT: there can't be multiple chunks in a single RDATA field HOT 1
- multiple TXT records should not always be concatenated. HOT 3
- This is great! HOT 3
- Using ResourceRecord as a HashMap key HOT 1
- can't figure out how to access rdata as [u8] HOT 1
- Can't figure out how to get RRType from Resource Record HOT 1
- How do I turn dns_parser::Packet back into bytes? HOT 4
- query type 65 is invalid - unparsed HTTPS query_type HOT 2
- label is not ascii errors with hostnames containing utf8 characters HOT 1
- Make new version with additional record parsing HOT 2
- Got ReservedBitsAreNonZero errors HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dns-parser.