Skip to content

Cannot access the RCODE returned by the DNS server #27

Closed

Description

@Legendary4226

Hi again haha :)

I found out that I need to know if a domain exists or not. According to the RFC 1035, it's the RCODE value that gives me this answer and can be one of :

https://www.rfc-editor.org/rfc/rfc1035
RCODE           Response code - this 4 bit field is set as part of
                responses.  The values have the following
                interpretation:

                0               No error condition

                1               Format error - The name server was
                                unable to interpret the query.

                2               Server failure - The name server was
                                unable to process this query due to a
                                problem with the name server.

                3               Name Error - Meaningful only for
                                responses from an authoritative name
                                server, this code signifies that the
                                domain name referenced in the query does
                                not exist.

                4               Not Implemented - The name server does
                                not support the requested kind of query.

                5               Refused - The name server refuses to
                                perform the specified operation for
                                policy reasons.  For example, a name
                                server may not wish to provide the
                                information to the particular requester,
                                or a name server may not wish to perform
                                a particular operation (e.g., zone

I read the code and saw you extract the $rcode at line 515 in DNSQuery.php for debug purposes :
$rcode = $this->header['spec'] & 15;
And never integrate it to DNSResult or DNSAnswer.

Is-it possible to add such data in the DNSAnswer object ? (I don't think the DNSResult need it)
In fact, I only need the raw data (but I'm not saying that a little enumeration could be really cool haha).

Activity

  1. purplepixie commented on Sep 29, 2025

    @purplepixie
    Owner

    Welcome back :) I think this seems like a nice enhancement so I'll add it to the queue.

  2. self-assigned this
    on Sep 29, 2025
  3. purplepixie commented on Sep 29, 2025

    @purplepixie
    Owner

    This has been addressed in the rcode branch #28 and merged back into master.

    The DNSAnswer object now has the following methods:

    DNSAnswer::setRcode(int): void sets the RCODE, DNSAnswer::getRCode():int returns the RCODE from the transaction (RCODE is initialised as -1 as a sanity check). DNSAnswer::getRcodeDescription(): string returns a brief textual status of the current RCODE (decided this was cleaner than creating a new class to store but could be re-factored).

    Example test code:

    $server = "dns0.verrotech.com";
    $query = new DNSQuery($server, 53, 60, true);
    
    $a = $query->query("www.verrotech.com", DNSTypes::NAME_A);
    echo "RC = ".$a->getRcode()." '".$a->getRcodeDescription()."'\n";
    
    $a = $query->query("www.google.com", DNSTypes::NAME_A);
    echo "RC = ".$a->getRcode()." '".$a->getRcodeDescription()."'\n";

    Produces:

    RC = 0 'No error condition'
    RC = 5 'Refused'
    

    @Legendary4226 please feel free to test this on the current master, once confirmed this meets your requirements I'll put it into a release.

    Thanks again for your suggestion.

  4. purplepixie commented on Sep 29, 2025

    @purplepixie
    Owner

    Documentation: added RCODE into to usage document.

  5. Legendary4226 commented on Sep 29, 2025

    @Legendary4226
    Author

    I can easily access the RCODE as an int, that's perfect

    Thank's you very much :)

  6. purplepixie commented on Sep 30, 2025

    @purplepixie
    Owner

    Released in 2.3.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions