Method: Net::DNS::Header#format

Defined in:
lib/net/dns/header.rb

#formatObject

The Net::DNS::Header#format method prints out the header in a special ascii representation of data, in a way similar to those often found on RFCs.

p Net::DNS::Header.new.format
#  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
#  |             18123             |
#  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
#  |0|   0   |0|0|1|0|0| 0 |   0   |
#  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
#  |               1               |
#  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
#  |               0               |
#  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
#  |               0               |
#  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
#  |               0               |
#  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

This can be very usefull for didactical purpouses :)



297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
# File 'lib/net/dns/header.rb', line 297

def format
  del = ("+-" * 16) + "+\n"
  len = del.length
  str = del + "|" + @id.to_s.center(len-3) + "|\n"
  str += del + "|" + @qr.to_s
  str += "|" + @opCode.to_s.center(7)
  str += "|" + @aa.to_s
  str += "|" + @tc.to_s
  str += "|" + @rd.to_s
  str += "|" + @ra.to_s
  str += "|" + @ad.to_s
  str += "|" + @cd.to_s.center(3)
  str += "|" + @rCode.to_s.center(7) + "|\n"
  str += del + "|" + @qdCount.to_s.center(len-3) + "|\n"
  str += del + "|" + @anCount.to_s.center(len-3) + "|\n"
  str += del + "|" + @nsCount.to_s.center(len-3) + "|\n"
  str += del + "|" + @arCount.to_s.center(len-3) + "|\n" + del
  str
end