rcodes.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. 'use strict'
  2. /*
  3. * Traditional DNS header RCODEs (4-bits) defined by IANA in
  4. * https://www.iana.org/assignments/dns-parameters/dns-parameters.xhtml
  5. */
  6. exports.toString = function (rcode) {
  7. switch (rcode) {
  8. case 0: return 'NOERROR'
  9. case 1: return 'FORMERR'
  10. case 2: return 'SERVFAIL'
  11. case 3: return 'NXDOMAIN'
  12. case 4: return 'NOTIMP'
  13. case 5: return 'REFUSED'
  14. case 6: return 'YXDOMAIN'
  15. case 7: return 'YXRRSET'
  16. case 8: return 'NXRRSET'
  17. case 9: return 'NOTAUTH'
  18. case 10: return 'NOTZONE'
  19. case 11: return 'RCODE_11'
  20. case 12: return 'RCODE_12'
  21. case 13: return 'RCODE_13'
  22. case 14: return 'RCODE_14'
  23. case 15: return 'RCODE_15'
  24. }
  25. return 'RCODE_' + rcode
  26. }
  27. exports.toRcode = function (code) {
  28. switch (code.toUpperCase()) {
  29. case 'NOERROR': return 0
  30. case 'FORMERR': return 1
  31. case 'SERVFAIL': return 2
  32. case 'NXDOMAIN': return 3
  33. case 'NOTIMP': return 4
  34. case 'REFUSED': return 5
  35. case 'YXDOMAIN': return 6
  36. case 'YXRRSET': return 7
  37. case 'NXRRSET': return 8
  38. case 'NOTAUTH': return 9
  39. case 'NOTZONE': return 10
  40. case 'RCODE_11': return 11
  41. case 'RCODE_12': return 12
  42. case 'RCODE_13': return 13
  43. case 'RCODE_14': return 14
  44. case 'RCODE_15': return 15
  45. }
  46. return 0
  47. }