/** * Parse a DNS answer record and add it to the given response. * * @param Response $response */ protected function parseAnswer(Response $response) : \Generator { $host = (yield from $this->transport->readLabel()); $type = (yield from $this->transport->readShort()); $class = (yield from $this->transport->readShort()); $ttl = (yield from $this->transport->readLong()); $len = (yield from $this->transport->readShort()); switch ($type) { case Message::TYPE_A: case Message::TYPE_AAAA: $data = \inet_ntop(yield from $this->transport->read($len)); break; case Message::TYPE_CNAME: $data = (yield from $this->transport->readLabel()); break; default: $data = (yield from $this->transport->read($len)); } $response->addAnswer($host, $type, $class, $data, $ttl & 0x80000000 ? $ttl - 0xffffffff : $ttl); }