{"_id":"@homebridge/dns-packet","_rev":"4208774","name":"@homebridge/dns-packet","description":"An abstract-encoding compliant module for encoding / decoding DNS packets","dist-tags":{"latest":"5.4.1"},"maintainers":[{"name":"bwp91","email":""},{"name":"donavanbecker","email":""},{"name":"dustin.greif","email":"dustin.greif@gmail.com"},{"name":"ebaauw","email":""},{"name":"khaost","email":""},{"name":"nfarina","email":"nfarina@gmail.com"},{"name":"northernman","email":""},{"name":"oznu","email":""},{"name":"supereg","email":""}],"time":{"modified":"2026-03-04T17:04:37.000Z","created":"2020-05-02T22:06:51.123Z","5.4.1":"2020-06-28T22:59:13.094Z","5.4.0":"2020-05-05T04:15:42.829Z","5.3.0":"2020-05-02T22:52:30.022Z","5.2.1":"2020-05-02T22:06:51.123Z"},"users":{},"author":{"name":"Mathias Buus"},"repository":{"type":"git","url":"git+https://github.com/homebridge/dns-packet.git"},"versions":{"5.4.1":{"name":"@homebridge/dns-packet","version":"5.4.1","description":"An abstract-encoding compliant module for encoding / decoding DNS packets","author":{"name":"Mathias Buus"},"license":"MIT","homepage":"https://github.com/homebridge/dns-packet","repository":{"type":"git","url":"git+https://github.com/homebridge/dns-packet.git"},"bugs":{"url":"https://github.com/homebridge/dns-packet/issues"},"engines":{"node":">=10.17.0"},"scripts":{"clean":"rimraf coverage && rimraf .nyc_output/","lint":"eslint --color *.js examples/*.js","test":"tape test.js","test-coverage":"nyc --reporter=lcovonly npm run test"},"dependencies":{"ip":"^1.1.5"},"devDependencies":{"eslint":"^6.8.0","eslint-config-standard":"^14.1.1","eslint-plugin-import":"^2.20.2","eslint-plugin-node":"^11.1.0","eslint-plugin-promise":"^4.2.1","eslint-plugin-standard":"^4.0.1","nyc":"^15.0.1","tape":"^5.0.0","rimraf":"^3.0.2"},"keywords":["dns","packet","encodings","encoding","encoder","abstract-encoding"],"gitHead":"f0a213710f3d8475523373e896fa0a7101572592","_id":"@homebridge/dns-packet@5.4.1","_nodeVersion":"10.21.0","_npmVersion":"6.14.4","dist":{"shasum":"a6271f013e78af700f64d903120ddca0758fd7da","size":13020,"noattachment":false,"key":"/@homebridge/dns-packet/-/@homebridge/dns-packet-5.4.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/@homebridge/dns-packet/download/@homebridge/dns-packet-5.4.1.tgz"},"maintainers":[{"name":"bwp91","email":""},{"name":"donavanbecker","email":""},{"name":"dustin.greif","email":"dustin.greif@gmail.com"},{"name":"ebaauw","email":""},{"name":"khaost","email":""},{"name":"nfarina","email":"nfarina@gmail.com"},{"name":"northernman","email":""},{"name":"oznu","email":""},{"name":"supereg","email":""}],"_npmUser":{"name":"supereg","email":"mail@anderl-bauer.de"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/dns-packet_5.4.1_1593385152946_0.1321187959621435"},"_hasShrinkwrap":false,"deprecated":"This package is no longer maintained","_cnpmcore_publish_time":"2021-12-25T05:24:13.939Z","publish_time":1593385153094,"_cnpm_publish_time":1593385153094},"5.4.0":{"name":"@homebridge/dns-packet","version":"5.4.0","description":"An abstract-encoding compliant module for encoding / decoding DNS packets","author":{"name":"Mathias Buus"},"license":"MIT","homepage":"https://github.com/homebridge/dns-packet","repository":{"type":"git","url":"git+https://github.com/homebridge/dns-packet.git"},"bugs":{"url":"https://github.com/homebridge/dns-packet/issues"},"engines":{"node":">=10.17.0"},"scripts":{"clean":"rimraf coverage && rimraf .nyc_output/","lint":"eslint --color *.js examples/*.js","test":"tape test.js","test-coverage":"nyc --reporter=lcovonly npm run test"},"dependencies":{"ip":"^1.1.5"},"devDependencies":{"eslint":"^6.8.0","eslint-config-standard":"^14.1.1","eslint-plugin-import":"^2.20.2","eslint-plugin-node":"^11.1.0","eslint-plugin-promise":"^4.2.1","eslint-plugin-standard":"^4.0.1","nyc":"^15.0.1","tape":"^5.0.0","rimraf":"^3.0.2"},"keywords":["dns","packet","encodings","encoding","encoder","abstract-encoding"],"gitHead":"8b898100b51f7ef09e749c1a8c454a3af378a98c","_id":"@homebridge/dns-packet@5.4.0","_nodeVersion":"10.20.1","_npmVersion":"6.14.4","dist":{"shasum":"1fedda0e23578c2a39233f86b8cc02d260d9c971","size":12730,"noattachment":false,"key":"/@homebridge/dns-packet/-/@homebridge/dns-packet-5.4.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/@homebridge/dns-packet/download/@homebridge/dns-packet-5.4.0.tgz"},"maintainers":[{"name":"bwp91","email":""},{"name":"donavanbecker","email":""},{"name":"dustin.greif","email":"dustin.greif@gmail.com"},{"name":"ebaauw","email":""},{"name":"khaost","email":""},{"name":"nfarina","email":"nfarina@gmail.com"},{"name":"northernman","email":""},{"name":"oznu","email":""},{"name":"supereg","email":""}],"_npmUser":{"name":"supereg","email":"mail@anderl-bauer.de"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/dns-packet_5.4.0_1588652142684_0.4670837928376126"},"_hasShrinkwrap":false,"deprecated":"This package is no longer maintained","_cnpmcore_publish_time":"2021-12-25T05:24:12.077Z","publish_time":1588652142829,"_cnpm_publish_time":1588652142829},"5.3.0":{"name":"@homebridge/dns-packet","version":"5.3.0","description":"An abstract-encoding compliant module for encoding / decoding DNS packets","author":{"name":"Mathias Buus"},"license":"MIT","homepage":"https://github.com/homebridge/dns-packet","repository":{"type":"git","url":"git+https://github.com/homebridge/dns-packet.git"},"bugs":{"url":"https://github.com/homebridge/dns-packet/issues"},"engines":{"node":">=10.17.0"},"scripts":{"clean":"rimraf coverage && rimraf .nyc_output/","lint":"eslint --color *.js examples/*.js","test":"tape test.js","test-coverage":"nyc --reporter=lcovonly npm run test"},"dependencies":{"ip":"^1.1.5"},"devDependencies":{"eslint":"^6.8.0","eslint-config-standard":"^14.1.1","eslint-plugin-import":"^2.20.2","eslint-plugin-node":"^11.1.0","eslint-plugin-promise":"^4.2.1","eslint-plugin-standard":"^4.0.1","nyc":"^15.0.1","tape":"^5.0.0","rimraf":"^3.0.2"},"keywords":["dns","packet","encodings","encoding","encoder","abstract-encoding"],"gitHead":"4664846f836e918582c2205ba2c4d91ff8aed93c","_id":"@homebridge/dns-packet@5.3.0","_nodeVersion":"10.20.1","_npmVersion":"6.14.4","dist":{"shasum":"838a4a704dcba4cf42dbd70745dc7af395100cc3","size":12663,"noattachment":false,"key":"/@homebridge/dns-packet/-/@homebridge/dns-packet-5.3.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/@homebridge/dns-packet/download/@homebridge/dns-packet-5.3.0.tgz"},"maintainers":[{"name":"bwp91","email":""},{"name":"donavanbecker","email":""},{"name":"dustin.greif","email":"dustin.greif@gmail.com"},{"name":"ebaauw","email":""},{"name":"khaost","email":""},{"name":"nfarina","email":"nfarina@gmail.com"},{"name":"northernman","email":""},{"name":"oznu","email":""},{"name":"supereg","email":""}],"_npmUser":{"name":"supereg","email":"mail@anderl-bauer.de"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/dns-packet_5.3.0_1588459949880_0.9751678957621603"},"_hasShrinkwrap":false,"deprecated":"This package is no longer maintained","_cnpmcore_publish_time":"2021-12-25T05:24:10.443Z","publish_time":1588459950022,"_cnpm_publish_time":1588459950022},"5.2.1":{"name":"@homebridge/dns-packet","version":"5.2.1","description":"An abstract-encoding compliant module for encoding / decoding DNS packets","author":{"name":"Mathias Buus"},"license":"MIT","homepage":"https://github.com/homebridge/dns-packet","repository":{"type":"git","url":"git+https://github.com/homebridge/dns-packet.git"},"bugs":{"url":"https://github.com/homebridge/dns-packet/issues"},"engines":{"node":">=6"},"scripts":{"clean":"rm -rf coverage .nyc_output/","lint":"eslint --color *.js examples/*.js","pretest":"npm run lint","test":"tape test.js","coverage":"nyc -r html npm test"},"dependencies":{"ip":"^1.1.5"},"devDependencies":{"eslint":"^6.8.0","eslint-config-standard":"^14.1.1","eslint-plugin-import":"^2.20.2","eslint-plugin-node":"^11.1.0","eslint-plugin-promise":"^4.2.1","eslint-plugin-standard":"^4.0.1","nyc":"^15.0.1","tape":"^5.0.0"},"keywords":["dns","packet","encodings","encoding","encoder","abstract-encoding"],"gitHead":"7a16d7a1996ea75f364e8e9566d63f82c56d631e","_id":"@homebridge/dns-packet@5.2.1","_nodeVersion":"13.13.0","_npmVersion":"6.14.4","dist":{"shasum":"23a4b9941403cd926673200c3d9ad0ef29a6a242","size":12559,"noattachment":false,"key":"/@homebridge/dns-packet/-/@homebridge/dns-packet-5.2.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/@homebridge/dns-packet/download/@homebridge/dns-packet-5.2.1.tgz"},"maintainers":[{"name":"bwp91","email":""},{"name":"donavanbecker","email":""},{"name":"dustin.greif","email":"dustin.greif@gmail.com"},{"name":"ebaauw","email":""},{"name":"khaost","email":""},{"name":"nfarina","email":"nfarina@gmail.com"},{"name":"northernman","email":""},{"name":"oznu","email":""},{"name":"supereg","email":""}],"_npmUser":{"name":"supereg","email":"mail@anderl-bauer.de"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/dns-packet_5.2.1_1588457211019_0.5774398850897959"},"_hasShrinkwrap":false,"deprecated":"This package is no longer maintained","_cnpmcore_publish_time":"2021-12-25T05:24:08.759Z","publish_time":1588457211123,"_cnpm_publish_time":1588457211123}},"readme":"# dns-packet\n[![](https://badgen.net/npm/v/@homebridge/dns-packet)](https://www.npmjs.org/package/@homebridge/dns-packet)\n[![](https://badgen.net/npm/dt/@homebridge/dns-packet)](https://www.npmjs.org/package/@homebridge/dns-packet)\n![Node-CI](https://github.com/homebridge/dns-packet/workflows/Node-CI/badge.svg)\n[![Coverage Status](https://coveralls.io/repos/github/homebridge/dns-packet/badge.svg?branch=master)](https://coveralls.io/github/homebridge/dns-packet?branch=master)\n\nAn [abstract-encoding](https://github.com/mafintosh/abstract-encoding) compliant module for encoding / decoding DNS packets.\nLifted out of [multicast-dns](https://github.com/mafintosh/multicast-dns) as a separate module.\n\n```\nnpm install @homebridge/dns-packet\n```\n\n## Notice\n\nThis fork of the original [dns-packet](https://github.com/mafintosh/dns-packet) library was used in the early \nbeta builds of the [ciao](https://github.com/homebridge/ciao) library. It was replaced with an encoder/decoder\ndirectly packaged into ciao improving on dns-packet with support for message compression, properly splitting\ndns packets according to the MTU and generally improving readability and maintainability (as it is also \nwritten in TypeScript).  \nYou may or may not use this fork or derive your work from it. Though keep in mind, that it is no longer maintained.\n\n## UDP Usage\n\n``` js\nconst dnsPacket = require('@homebridge/dns-packet')\nconst dgram = require('dgram')\n\nconst socket = dgram.createSocket('udp4')\n\nconst buf = dnsPacket.encode({\n  type: 'query',\n  id: 1,\n  flags: dnsPacket.RECURSION_DESIRED,\n  questions: [{\n    type: 'A',\n    name: 'google.com'\n  }]\n})\n\nsocket.on('message', message => {\n  console.log(dnsPacket.decode(message)) // prints out a response from google dns\n})\n\nsocket.send(buf, 0, buf.length, 53, '8.8.8.8')\n```\n\nAlso see [the UDP example](examples/udp.js).\n\n## TCP, TLS, HTTPS\n\nWhile DNS has traditionally been used over a datagram transport, it is increasingly being carried over TCP for larger\nresponses commonly including DNSSEC responses and TLS or HTTPS for enhanced security.\nSee below examples on how to use `dns-packet` to wrap DNS packets in these protocols:\n\n- [TCP](examples/tcp.js)\n- [DNS over TLS](examples/tls.js)\n- [DNS over HTTPS](examples/doh.js)\n\n## API\n\n#### `var buf = packets.encode(packet, [buf], [offset])`\n\nEncodes a DNS packet into a buffer containing a UDP payload.\n\n#### `var packet = packets.decode(buf, [offset])`\n\nDecode a DNS packet from a buffer containing a UDP payload.\n\n#### `var buf = packets.streamEncode(packet, [buf], [offset])`\n\nEncodes a DNS packet into a buffer containing a TCP payload.\n\n#### `var packet = packets.streamDecode(buf, [offset])`\n\nDecode a DNS packet from a buffer containing a TCP payload.\n\n#### `var len = packets.encodingLength(packet)`\n\nReturns how many bytes are needed to encode the DNS packet\n\n## Packets\n\nPackets look like this\n\n``` js\n{\n  type: 'query|response',\n  id: optionalIdNumber,\n  flags: optionalBitFlags,\n  questions: [...],\n  answers: [...],\n  additionals: [...],\n  authorities: [...]\n}\n```\n\nThe bit flags available are\n\n``` js\npacket.RECURSION_DESIRED\npacket.RECURSION_AVAILABLE\npacket.TRUNCATED_RESPONSE\npacket.AUTHORITATIVE_ANSWER\npacket.AUTHENTIC_DATA\npacket.CHECKING_DISABLED\n```\n\nTo use more than one flag bitwise-or them together\n\n``` js\nvar flags = packet.RECURSION_DESIRED | packet.RECURSION_AVAILABLE\n```\n\nAnd to check for a flag use bitwise-and\n\n``` js\nvar isRecursive = message.flags & packet.RECURSION_DESIRED\n```\n\nA question looks like this\n\n``` js\n{\n  type: 'A', // or SRV, AAAA, etc\n  class: 'IN', // one of IN, CS, CH, HS, ANY. Default: IN\n  name: 'google.com' // which record are you looking for\n}\n```\n\nAnd an answer, additional, or authority looks like this\n\n``` js\n{\n  type: 'A', // or SRV, AAAA, etc\n  class: 'IN', // one of IN, CS, CH, HS\n  name: 'google.com', // which name is this record for\n  ttl: optionalTimeToLiveInSeconds,\n  (record specific data, see below)\n}\n```\n\n## Supported record types\n\n#### `A`\n\n``` js\n{\n  data: 'IPv4 address' // fx 127.0.0.1\n}\n```\n\n#### `AAAA`\n\n``` js\n{\n  data: 'IPv6 address' // fx fe80::1\n}\n```\n\n#### `CAA`\n\n``` js\n{\n  flags: 128, // octet\n  tag: 'issue|issuewild|iodef',\n  value: 'ca.example.net',\n  issuerCritical: false\n}\n```\n\n#### `CNAME`\n\n``` js\n{\n  data: 'cname.to.another.record'\n}\n```\n\n#### `DNAME`\n\n``` js\n{\n  data: 'dname.to.another.record'\n}\n```\n\n#### `DNSKEY`\n\n``` js\n{\n  flags: 257, // 16 bits\n  algorithm: 1, // octet\n  key: Buffer\n}\n```\n\n#### `DS`\n\n``` js\n{\n  keyTag: 12345,\n  algorithm: 8,\n  digestType: 1,\n  digest: Buffer\n}\n```\n\n#### `HINFO`\n\n``` js\n{\n  data: {\n    cpu: 'cpu info',\n    os: 'os info'\n  }\n}\n```\n\n#### `MX`\n\n``` js\n{\n  preference: 10,\n  exchange: 'mail.example.net'\n}\n```\n\n#### `NS`\n\n``` js\n{\n  data: nameServer\n}\n```\n\n#### `NSEC`\n\n``` js\n{\n  nextDomain: 'a.domain',\n  rrtypes: ['A', 'TXT', 'RRSIG']\n}\n```\n\n#### `NSEC3`\n\n``` js\n{\n  algorithm: 1,\n  flags: 0,\n  iterations: 2,\n  salt: Buffer,\n  nextDomain: Buffer, // Hashed per RFC5155\n  rrtypes: ['A', 'TXT', 'RRSIG']\n}\n```\n\n#### `NULL`\n\n``` js\n{\n  data: Buffer('any binary data')\n}\n```\n\n#### `OPT`\n\n[EDNS0](https://tools.ietf.org/html/rfc6891) options.\n\n``` js\n{\n  type: 'OPT',\n  name: '.',\n  udpPayloadSize: 4096,\n  flags: packet.DNSSEC_OK,\n  options: [{\n    // pass in any code/data for generic EDNS0 options\n    code: 12,\n    data: Buffer.alloc(31)\n  }, {\n    // Several EDNS0 options have enhanced support\n    code: 'PADDING',\n    length: 31,\n  }, {\n    code: 'CLIENT_SUBNET',\n    family: 2, // 1 for IPv4, 2 for IPv6\n    sourcePrefixLength: 64, // used to truncate IP address\n    scopePrefixLength: 0,\n    ip: 'fe80::',\n  }, {\n    code: 'TCP_KEEPALIVE',\n    timeout: 150 // increments of 100ms.  This means 15s.\n  }, {\n    code: 'KEY_TAG',\n    tags: [1, 2, 3],\n  }]\n}\n```\n\nThe options `PADDING`, `CLIENT_SUBNET`, `TCP_KEEPALIVE` and `KEY_TAG` support enhanced de/encoding.\nSee [optionscodes.js](optioncodes.js) for all supported option codes. If the `data` property is present on an option,\nit takes precedence. On decoding, `data` will always be defined.\n\n#### `PTR`\n\n``` js\n{\n  data: 'points.to.another.record'\n}\n```\n\n#### `RP`\n\n``` js\n{\n  mbox: 'admin.example.com',\n  txt: 'txt.example.com'\n}\n```\n\n#### `RRSIG`\n\n``` js\n{\n  typeCovered: 'A',\n  algorithm: 8,\n  labels: 1,\n  originalTTL: 3600,\n  expiration: timestamp,\n  inception: timestamp,\n  keyTag: 12345,\n  signersName: 'a.name',\n  signature: Buffer\n}\n```\n\n#### `SOA`\n\n``` js\n{\n  data:\n    {\n      mname: domainName,\n      rname: mailbox,\n      serial: zoneSerial,\n      refresh: refreshInterval,\n      retry: retryInterval,\n      expire: expireInterval,\n      minimum: minimumTTL\n    }\n}\n```\n\n#### `SRV`\n\n``` js\n{\n  data: {\n    port: servicePort,\n    target: serviceHostName,\n    priority: optionalServicePriority,\n    weight: optionalServiceWeight\n  }\n}\n```\n\n#### `TXT`\n\n``` js\n{\n  data: 'text' || Buffer || [ Buffer || 'text' ]\n}\n```\n\nWhen encoding, scalar values are converted to an array and strings are converted to UTF-8 encoded Buffers.\nWhen decoding, the return value will always be an array of Buffer.\n\nIf you need another record type, open an issue and we'll try to add it.\n\n## License\n\nMIT\n","_attachments":{},"homepage":"https://github.com/homebridge/dns-packet","bugs":{"url":"https://github.com/homebridge/dns-packet/issues"},"license":"MIT"}