tjfontaine / native-dns-packet

DNS parsing and writing in javascript
MIT License
58 stars 36 forks source link

packet buffer length #19

Open jots opened 9 years ago

jots commented 9 years ago

how can I get Packet to write into a buffer of the exact length that is needed? for instance, now I do:

  buf = new Buffer(1024) # too big 
  Packet.write(buf, pre)
  server.send(buf, 0, buf.length, 53, ns)
  buf = null

but I think that ends up sending too large packets in most cases. Is there a way to get the "buf" to the correct length before sending?

stephenwvickers commented 8 years ago

Packet.write() returns a length which you can use:

var len = Packet.write(buf, pre)

Then use len in send():

server.send(buf, 0, len , 53, ns)