You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
1.3 KiB

4 years ago
  1. /*
  2. * Traditional DNS header OPCODEs (4-bits) defined by IANA in
  3. * https://www.iana.org/assignments/dns-parameters/dns-parameters.xhtml#dns-parameters-5
  4. */
  5. exports.toString = function (opcode) {
  6. switch (opcode) {
  7. case 0: return 'QUERY'
  8. case 1: return 'IQUERY'
  9. case 2: return 'STATUS'
  10. case 3: return 'OPCODE_3'
  11. case 4: return 'NOTIFY'
  12. case 5: return 'UPDATE'
  13. case 6: return 'OPCODE_6'
  14. case 7: return 'OPCODE_7'
  15. case 8: return 'OPCODE_8'
  16. case 9: return 'OPCODE_9'
  17. case 10: return 'OPCODE_10'
  18. case 11: return 'OPCODE_11'
  19. case 12: return 'OPCODE_12'
  20. case 13: return 'OPCODE_13'
  21. case 14: return 'OPCODE_14'
  22. case 15: return 'OPCODE_15'
  23. }
  24. return 'OPCODE_' + opcode
  25. }
  26. exports.toOpcode = function (code) {
  27. switch (code.toUpperCase()) {
  28. case 'QUERY': return 0
  29. case 'IQUERY': return 1
  30. case 'STATUS': return 2
  31. case 'OPCODE_3': return 3
  32. case 'NOTIFY': return 4
  33. case 'UPDATE': return 5
  34. case 'OPCODE_6': return 6
  35. case 'OPCODE_7': return 7
  36. case 'OPCODE_8': return 8
  37. case 'OPCODE_9': return 9
  38. case 'OPCODE_10': return 10
  39. case 'OPCODE_11': return 11
  40. case 'OPCODE_12': return 12
  41. case 'OPCODE_13': return 13
  42. case 'OPCODE_14': return 14
  43. case 'OPCODE_15': return 15
  44. }
  45. return 0
  46. }