{
    "mode": "perldoc",
    "parameter": "Net::DNS::Header",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/Net%3A%3ADNS%3A%3AHeader/json",
    "generated": "2026-09-23T11:00:54Z",
    "synopsis": "use Net::DNS;\n$packet = Net::DNS::Packet->new();\n$header = $packet->header;",
    "sections": {
        "NAME": {
            "content": "Net::DNS::Header - DNS packet header\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "use Net::DNS;\n\n$packet = Net::DNS::Packet->new();\n$header = $packet->header;\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "\"Net::DNS::Header\" represents the header portion of a DNS packet.\n",
            "subsections": []
        },
        "METHODS": {
            "content": "$packet->header\n$packet = Net::DNS::Packet->new();\n$header = $packet->header;\n\nNet::DNS::Header objects emanate from the Net::DNS::Packet header() method, and contain an\nopaque reference to the parent Packet object.\n\nHeader objects may be assigned to suitably scoped lexical variables. They should never be stored\nin global variables or persistent data structures.\n\nstring\nprint $packet->header->string;\n\nReturns a string representation of the packet header.\n\nprint\n$packet->header->print;\n\nPrints the string representation of the packet header.\n\nid\nprint \"query id = \", $packet->header->id, \"\\n\";\n$packet->header->id(1234);\n\nGets or sets the query identification number.\n\nA random value is assigned if the argument value is undefined.\n\nopcode\nprint \"query opcode = \", $packet->header->opcode, \"\\n\";\n$packet->header->opcode(\"UPDATE\");\n\nGets or sets the query opcode (the purpose of the query).\n\nrcode\nprint \"query response code = \", $packet->header->rcode, \"\\n\";\n$packet->header->rcode(\"SERVFAIL\");\n\nGets or sets the query response code (the status of the query).\n\nqr\nprint \"query response flag = \", $packet->header->qr, \"\\n\";\n$packet->header->qr(0);\n\nGets or sets the query response flag.\n\naa\nprint \"response is \", $packet->header->aa ? \"\" : \"non-\", \"authoritative\\n\";\n$packet->header->aa(0);\n\nGets or sets the authoritative answer flag.\n\ntc\nprint \"packet is \", $packet->header->tc ? \"\" : \"not \", \"truncated\\n\";\n$packet->header->tc(0);\n\nGets or sets the truncated packet flag.\n\nrd\nprint \"recursion was \", $packet->header->rd ? \"\" : \"not \", \"desired\\n\";\n$packet->header->rd(0);\n\nGets or sets the recursion desired flag.\n\nra\nprint \"recursion is \", $packet->header->ra ? \"\" : \"not \", \"available\\n\";\n$packet->header->ra(0);\n\nGets or sets the recursion available flag.\n\nz\nUnassigned bit, should always be zero.\n\nad\nprint \"The response has \", $packet->header->ad ? \"\" : \"not\", \"been verified\\n\";\n\nRelevant in DNSSEC context.\n\n(The AD bit is only set on a response where signatures have been cryptographically verified or\nthe server is authoritative for the data and is allowed to set the bit by policy.)\n\ncd\nprint \"checking was \", $packet->header->cd ? \"not\" : \"\", \"desired\\n\";\n$packet->header->cd(0);\n\nGets or sets the checking disabled flag.\n\nqdcount, zocount\nprint \"# of question records: \", $packet->header->qdcount, \"\\n\";\n\nReturns the number of records in the question section of the packet. In dynamic update packets,\nthis field is known as \"zocount\" and refers to the number of RRs in the zone section.\n\nancount, prcount\nprint \"# of answer records: \", $packet->header->ancount, \"\\n\";\n\nReturns the number of records in the answer section of the packet which may, in the case of\ncorrupt packets, differ from the actual number of records. In dynamic update packets, this field\nis known as \"prcount\" and refers to the number of RRs in the prerequisite section.\n\nnscount, upcount\nprint \"# of authority records: \", $packet->header->nscount, \"\\n\";\n\nReturns the number of records in the authority section of the packet which may, in the case of\ncorrupt packets, differ from the actual number of records. In dynamic update packets, this field\nis known as \"upcount\" and refers to the number of RRs in the update section.\n\narcount, adcount\nprint \"# of additional records: \", $packet->header->arcount, \"\\n\";\n\nReturns the number of records in the additional section of the packet which may, in the case of\ncorrupt packets, differ from the actual number of records. In dynamic update packets, this field\nis known as \"adcount\".\n\nEDNS Protocol Extensions\ndo\nprint \"DNSSECOK flag was \", $packet->header->do ? \"not\" : \"\", \"set\\n\";\n$packet->header->do(1);\n\nGets or sets the EDNS DNSSEC OK flag.\n",
            "subsections": [
                {
                    "name": "Extended rcode",
                    "content": "EDNS extended rcodes are handled transparently by $packet->header->rcode().\n\nUDP packet size\n$udpmax = $packet->edns->UDPsize;\n\nEDNS offers a mechanism to advertise the maximum UDP packet size which can be assembled by the\nlocal network stack.\n\nedns\n$header  = $packet->header;\n$version = $header->edns->version;\n@options = $header->edns->options;\n$option  = $header->edns->option(n);\n$udpmax = $packet->edns->UDPsize;\n\nAuxiliary function which provides access to the EDNS protocol extension OPT RR.\n"
                }
            ]
        },
        "COPYRIGHT": {
            "content": "Copyright (c)1997 Michael Fuhr.\n\nPortions Copyright (c)2002,2003 Chris Reinhardt.\n\nPortions Copyright (c)2012,2022 Dick Franks.\n\nAll rights reserved.\n",
            "subsections": []
        },
        "LICENSE": {
            "content": "Permission to use, copy, modify, and distribute this software and its documentation for any\npurpose and without fee is hereby granted, provided that the original copyright notices appear\nin all copies and that both copyright notice and this permission notice appear in supporting\ndocumentation, and that the name of the author not be used in advertising or publicity\npertaining to distribution of the software without specific prior written permission.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING\nBUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\nNONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,\nDAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "perl Net::DNS Net::DNS::Packet Net::DNS::RR::OPT RFC1035(4.1.1)\n<https://tools.ietf.org/html/rfc1035>\n",
            "subsections": []
        }
    },
    "summary": "Net::DNS::Header - DNS packet header",
    "flags": [],
    "examples": [],
    "see_also": []
}