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.

DNSQuestion-class.R 1.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. R6Class(
  2. classname = "DNSQuestion",
  3. public = list(
  4. qname = NULL,
  5. qtype = NULL,
  6. qclass = NULL,
  7. initialize = function(qname = NULL, qtype = 1L, qclass = 1L) {
  8. if (inherits(qname, "DNSLabel")) {
  9. self$qname <- qname
  10. } else {
  11. if (length(qname)) self$qname <- DNSLabel$new(qname)
  12. }
  13. self$qtype <- qtype
  14. self$qclass <- qclass
  15. },
  16. pack = function() {
  17. c(
  18. self$qname$encode(),
  19. writeBin(as.integer(self$qtype), raw(), size = 2, endian = "big"),
  20. writeBin(as.integer(self$qclass), raw(), size = 2, endian = "big")
  21. )
  22. },
  23. parse = function(buf, buf_pos = 1L) {
  24. ret <- DNSLabel$new()$parse(buf, buf_pos)
  25. self$qname <- ret
  26. buf_pos <- buf_pos + attr(ret, "buflen")
  27. self$qtype <- readBin(buf[buf_pos:(buf_pos+1)], "int", size = 2, endian = "big")
  28. self$qclass <- readBin(buf[(buf_pos+2):(buf_pos+3)], "int", size = 2, endian = "big")
  29. attr(self, "buflen") <- attr(ret, "buflen") + 4L
  30. self
  31. }
  32. )
  33. ) -> DNSQuestion