rcodes.js 1.2 KB

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