No Description
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.

DNSRecord-class.R 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. R6Class(
  2. classname = "DNSRecord",
  3. public = list(
  4. header = NULL,
  5. questions = list(),
  6. rr = list(),
  7. auth = list(),
  8. ar = list(),
  9. initialize = function(header = NULL, questions = NULL,
  10. rr = NULL, q = NULL, a = NULL,
  11. auth = NULL, ar = NULL) {
  12. self$header <- header %||% DNSHeader$new()
  13. self$questions <- questions %||% list()
  14. self$rr <- rr %||% list()
  15. self$auth <- auth %||% list()
  16. self$ar <- ar %||% list()
  17. if (length(q)) self$questions <- append(self$questions, q)
  18. if (length(a)) self$rr <- append(self$rr, a)
  19. self$set_header_qa()
  20. },
  21. question = function(qname, qtype = "A", qclass = "IN") {
  22. DNSRecord$new(
  23. q = DNSQuestion$new(
  24. qname = qname,
  25. qtype = .qtype[toupper(qtype)],
  26. qclass = .class[toupper(qclass)]
  27. )
  28. )
  29. },
  30. parse = function(buf, buf_pos = 1L) {
  31. #self$header <- NULL
  32. self$questions <- list()
  33. self$rr <- list()
  34. self$auth <- list()
  35. self$ar <- list()
  36. buf_pos <- 1L
  37. ret <- DNSHeader$new()$parse(buf)
  38. self$header <- ret
  39. buf_pos <- attr(ret, "buflen") + 1L
  40. message(buf_pos)
  41. self$questions <- lapply(1:self$header$q, function(.idx) {
  42. ret <- DNSQuestion$new()$parse(buf, buf_pos)
  43. buf_pos <<- buf_pos + attr(ret, "buflen")
  44. ret
  45. })
  46. self
  47. },
  48. # Reset header q/a/auth/ar counts to match numver of records (normally done transparently)
  49. set_header_qa = function() {
  50. self$header$q <- length(self$questions)
  51. self$header$a <- length(self$rr)
  52. self$header$auth <- length(self$auth)
  53. self$header$ar <- length(self$ar)
  54. },
  55. pack = function() {
  56. out <- self$header$pack()
  57. for (q in self$questions) out <- c(out, q$pack())
  58. out
  59. }
  60. ),
  61. private = list(
  62. )
  63. ) -> DNSRecord