Beispiel #1
0
 /**
  * Decode a question record
  *
  * @param \LibDNS\Decoder\DecodingContext $decodingContext
  * @return \LibDNS\Records\Question
  * @throws \UnexpectedValueException When the record is invalid
  */
 private function decodeQuestionRecord(DecodingContext $decodingContext)
 {
     /** @var \LibDNS\Records\Types\DomainName $domainName */
     $domainName = $this->typeBuilder->build(Types::DOMAIN_NAME);
     $this->decodeDomainName($decodingContext, $domainName);
     $meta = unpack('ntype/nclass', $this->readDataFromPacket($decodingContext->getPacket(), 4));
     $question = $this->questionFactory->create($meta['type']);
     $question->setName($domainName);
     $question->setClass($meta['class']);
     return $question;
 }
Beispiel #2
0
 /**
  * @param   string $name
  * @param   string|int $type
  *
  * @return \LibDNS\Records\Question
  *
  * @throws \Icicle\Dns\Exception\InvalidTypeError If the record type given is invalid.
  */
 protected function createQuestion(string $name, $type) : Question
 {
     if (!is_int($type)) {
         $type = strtoupper($type);
         $types = static::getRecordTypes();
         if (!array_key_exists($type, $types)) {
             throw new InvalidTypeError($type);
         }
         $type = $types[$type];
     } elseif (0 > $type || 0xffff < $type) {
         throw new InvalidTypeError($type);
     }
     $question = $this->questionFactory->create($type);
     $question->setName($name);
     return $question;
 }