Compare commits
	
		
			103 Commits
		
	
	
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 727e1c506b | |||
| 1321e5170b | |||
| 
						 | 
					092008f766 | ||
| 
						 | 
					93d1c0f8e2 | ||
| 
						 | 
					12038465f6 | ||
| 
						 | 
					c0f5e0cb17 | ||
| 
						 | 
					6093d772fc | ||
| 
						 | 
					58351275d0 | ||
| 
						 | 
					57065d9bd4 | ||
| 
						 | 
					513e2c2af9 | ||
| 
						 | 
					60775ba9d0 | ||
| 
						 | 
					dc3ff59362 | ||
| 
						 | 
					748bb40ffb | ||
| 
						 | 
					f90149784f | ||
| 
						 | 
					74f7b5b1ff | ||
| 
						 | 
					3b0e1de7a2 | ||
| 4063b8724d | |||
| 
						 | 
					e01bf74e93 | ||
| 
						 | 
					f2abd03cf7 | ||
| 
						 | 
					9525082936 | ||
| 
						 | 
					6352cf4b51 | ||
| 
						 | 
					afd8b6fb90 | ||
| 
						 | 
					3b65560818 | ||
| 
						 | 
					e2338f1b50 | ||
| 
						 | 
					b2dd53dcb1 | ||
| 
						 | 
					c6715ee6bf | ||
| 
						 | 
					908fd5314c | ||
| 
						 | 
					d743b8f3d0 | ||
| 
						 | 
					471a80638d | ||
| 
						 | 
					ef3f2ae941 | ||
| 
						 | 
					ed28de4e59 | ||
| 
						 | 
					e16e7efe9e | ||
| 
						 | 
					5fff05a76f | ||
| 
						 | 
					b5af1bfe24 | ||
| 
						 | 
					633e60d643 | ||
| 
						 | 
					2f4807d1b4 | ||
| 
						 | 
					6b8a8664f8 | ||
| 
						 | 
					a5586f6b2c | ||
| 
						 | 
					b0e8f1f55b | ||
| 
						 | 
					059b605121 | ||
| 
						 | 
					ed591d91f7 | ||
| 
						 | 
					0768e17bfa | ||
| 
						 | 
					b24345fe26 | ||
| 
						 | 
					84908c62df | ||
| 
						 | 
					eca24330e1 | ||
| 
						 | 
					5b99427102 | ||
| 
						 | 
					7ed1e7c3d8 | ||
| 
						 | 
					3692e4c828 | ||
| 
						 | 
					4dadc1c443 | ||
| 
						 | 
					5f338a7186 | ||
| 
						 | 
					7b37adffff | ||
| 
						 | 
					93cdeaa71b | ||
| 
						 | 
					777bbd679f | ||
| 
						 | 
					d66624df8e | ||
| 
						 | 
					a287abb991 | ||
| 
						 | 
					a538fa4f58 | ||
| 
						 | 
					98187043ec | ||
| 
						 | 
					4ffce1d405 | ||
| 
						 | 
					49b588c7a6 | ||
| 
						 | 
					e0af1007c7 | ||
| 
						 | 
					e9169d7ef1 | ||
| 
						 | 
					ab533ab36c | ||
| 
						 | 
					8f09c4f4d3 | ||
| 
						 | 
					f992b37800 | ||
| 
						 | 
					0567aa31c8 | ||
| 
						 | 
					12093c52d3 | ||
| 
						 | 
					8d1cb165ae | ||
| 
						 | 
					950867c452 | ||
| 
						 | 
					a09dd27c7d | ||
| 
						 | 
					a295f9c3e7 | ||
| 
						 | 
					523dad1697 | ||
| 
						 | 
					a137d6b937 | ||
| 
						 | 
					f8cf8aef77 | ||
| 
						 | 
					8960b9ae2a | ||
| 
						 | 
					53cae83af4 | ||
| 
						 | 
					d5c20c58a3 | ||
| 
						 | 
					8fc78f35f0 | ||
| 
						 | 
					e9a2794990 | ||
| 
						 | 
					9b8526dc06 | ||
| 
						 | 
					d43696b54e | ||
| 
						 | 
					d00f83c625 | ||
| 
						 | 
					937e93d1df | ||
| 
						 | 
					28fbc44824 | ||
| 
						 | 
					cfae86e5f1 | ||
| 
						 | 
					e98b3dd1a6 | ||
| 
						 | 
					2388b46c74 | ||
| 
						 | 
					50b134f33b | ||
| 
						 | 
					12cb2887fa | ||
| 
						 | 
					16dd91ace0 | ||
| 
						 | 
					792bea258d | ||
| 
						 | 
					05beaa480b | ||
| 
						 | 
					43360a75da | ||
| 
						 | 
					4df82c456e | ||
| 
						 | 
					8129863dc6 | ||
| 
						 | 
					0ba8871c3a | ||
| 
						 | 
					571e4959cf | ||
| 
						 | 
					c0338ef3fa | ||
| 
						 | 
					089e4414e3 | ||
| 
						 | 
					a408f97537 | ||
| 
						 | 
					2726e20622 | ||
| 
						 | 
					de648a3883 | ||
| 
						 | 
					0b7077cdc8 | ||
| 
						 | 
					2062e359ae | 
							
								
								
									
										8
									
								
								.prettierrc
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								.prettierrc
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,8 @@
 | 
				
			|||||||
 | 
					{
 | 
				
			||||||
 | 
					  "bracketSpacing": true,
 | 
				
			||||||
 | 
					  "printWidth": 80,
 | 
				
			||||||
 | 
					  "singleQuote": true,
 | 
				
			||||||
 | 
					  "tabWidth": 4,
 | 
				
			||||||
 | 
					  "trailingComma": "none",
 | 
				
			||||||
 | 
					  "useTabs": true
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										3
									
								
								CHANGELOG
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								CHANGELOG
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,3 @@
 | 
				
			|||||||
 | 
					v1.2.10 - Tested with dig.js, deployed to production with digd.js
 | 
				
			||||||
 | 
					    * Parses and packs common record types including:
 | 
				
			||||||
 | 
					        * A,AAAA,CAA,CNAME,MX,NS,PTR,SOA,SRV,TXT
 | 
				
			||||||
							
								
								
									
										375
									
								
								LICENSE
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										375
									
								
								LICENSE
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,375 @@
 | 
				
			|||||||
 | 
					Copyright 2015-2019 AJ ONeal
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Mozilla Public License Version 2.0
 | 
				
			||||||
 | 
					==================================
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					1. Definitions
 | 
				
			||||||
 | 
					--------------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					1.1. "Contributor"
 | 
				
			||||||
 | 
					    means each individual or legal entity that creates, contributes to
 | 
				
			||||||
 | 
					    the creation of, or owns Covered Software.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					1.2. "Contributor Version"
 | 
				
			||||||
 | 
					    means the combination of the Contributions of others (if any) used
 | 
				
			||||||
 | 
					    by a Contributor and that particular Contributor's Contribution.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					1.3. "Contribution"
 | 
				
			||||||
 | 
					    means Covered Software of a particular Contributor.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					1.4. "Covered Software"
 | 
				
			||||||
 | 
					    means Source Code Form to which the initial Contributor has attached
 | 
				
			||||||
 | 
					    the notice in Exhibit A, the Executable Form of such Source Code
 | 
				
			||||||
 | 
					    Form, and Modifications of such Source Code Form, in each case
 | 
				
			||||||
 | 
					    including portions thereof.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					1.5. "Incompatible With Secondary Licenses"
 | 
				
			||||||
 | 
					    means
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    (a) that the initial Contributor has attached the notice described
 | 
				
			||||||
 | 
					        in Exhibit B to the Covered Software; or
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    (b) that the Covered Software was made available under the terms of
 | 
				
			||||||
 | 
					        version 1.1 or earlier of the License, but not also under the
 | 
				
			||||||
 | 
					        terms of a Secondary License.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					1.6. "Executable Form"
 | 
				
			||||||
 | 
					    means any form of the work other than Source Code Form.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					1.7. "Larger Work"
 | 
				
			||||||
 | 
					    means a work that combines Covered Software with other material, in
 | 
				
			||||||
 | 
					    a separate file or files, that is not Covered Software.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					1.8. "License"
 | 
				
			||||||
 | 
					    means this document.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					1.9. "Licensable"
 | 
				
			||||||
 | 
					    means having the right to grant, to the maximum extent possible,
 | 
				
			||||||
 | 
					    whether at the time of the initial grant or subsequently, any and
 | 
				
			||||||
 | 
					    all of the rights conveyed by this License.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					1.10. "Modifications"
 | 
				
			||||||
 | 
					    means any of the following:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    (a) any file in Source Code Form that results from an addition to,
 | 
				
			||||||
 | 
					        deletion from, or modification of the contents of Covered
 | 
				
			||||||
 | 
					        Software; or
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    (b) any new file in Source Code Form that contains any Covered
 | 
				
			||||||
 | 
					        Software.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					1.11. "Patent Claims" of a Contributor
 | 
				
			||||||
 | 
					    means any patent claim(s), including without limitation, method,
 | 
				
			||||||
 | 
					    process, and apparatus claims, in any patent Licensable by such
 | 
				
			||||||
 | 
					    Contributor that would be infringed, but for the grant of the
 | 
				
			||||||
 | 
					    License, by the making, using, selling, offering for sale, having
 | 
				
			||||||
 | 
					    made, import, or transfer of either its Contributions or its
 | 
				
			||||||
 | 
					    Contributor Version.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					1.12. "Secondary License"
 | 
				
			||||||
 | 
					    means either the GNU General Public License, Version 2.0, the GNU
 | 
				
			||||||
 | 
					    Lesser General Public License, Version 2.1, the GNU Affero General
 | 
				
			||||||
 | 
					    Public License, Version 3.0, or any later versions of those
 | 
				
			||||||
 | 
					    licenses.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					1.13. "Source Code Form"
 | 
				
			||||||
 | 
					    means the form of the work preferred for making modifications.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					1.14. "You" (or "Your")
 | 
				
			||||||
 | 
					    means an individual or a legal entity exercising rights under this
 | 
				
			||||||
 | 
					    License. For legal entities, "You" includes any entity that
 | 
				
			||||||
 | 
					    controls, is controlled by, or is under common control with You. For
 | 
				
			||||||
 | 
					    purposes of this definition, "control" means (a) the power, direct
 | 
				
			||||||
 | 
					    or indirect, to cause the direction or management of such entity,
 | 
				
			||||||
 | 
					    whether by contract or otherwise, or (b) ownership of more than
 | 
				
			||||||
 | 
					    fifty percent (50%) of the outstanding shares or beneficial
 | 
				
			||||||
 | 
					    ownership of such entity.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					2. License Grants and Conditions
 | 
				
			||||||
 | 
					--------------------------------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					2.1. Grants
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Each Contributor hereby grants You a world-wide, royalty-free,
 | 
				
			||||||
 | 
					non-exclusive license:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					(a) under intellectual property rights (other than patent or trademark)
 | 
				
			||||||
 | 
					    Licensable by such Contributor to use, reproduce, make available,
 | 
				
			||||||
 | 
					    modify, display, perform, distribute, and otherwise exploit its
 | 
				
			||||||
 | 
					    Contributions, either on an unmodified basis, with Modifications, or
 | 
				
			||||||
 | 
					    as part of a Larger Work; and
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					(b) under Patent Claims of such Contributor to make, use, sell, offer
 | 
				
			||||||
 | 
					    for sale, have made, import, and otherwise transfer either its
 | 
				
			||||||
 | 
					    Contributions or its Contributor Version.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					2.2. Effective Date
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					The licenses granted in Section 2.1 with respect to any Contribution
 | 
				
			||||||
 | 
					become effective for each Contribution on the date the Contributor first
 | 
				
			||||||
 | 
					distributes such Contribution.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					2.3. Limitations on Grant Scope
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					The licenses granted in this Section 2 are the only rights granted under
 | 
				
			||||||
 | 
					this License. No additional rights or licenses will be implied from the
 | 
				
			||||||
 | 
					distribution or licensing of Covered Software under this License.
 | 
				
			||||||
 | 
					Notwithstanding Section 2.1(b) above, no patent license is granted by a
 | 
				
			||||||
 | 
					Contributor:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					(a) for any code that a Contributor has removed from Covered Software;
 | 
				
			||||||
 | 
					    or
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					(b) for infringements caused by: (i) Your and any other third party's
 | 
				
			||||||
 | 
					    modifications of Covered Software, or (ii) the combination of its
 | 
				
			||||||
 | 
					    Contributions with other software (except as part of its Contributor
 | 
				
			||||||
 | 
					    Version); or
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					(c) under Patent Claims infringed by Covered Software in the absence of
 | 
				
			||||||
 | 
					    its Contributions.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					This License does not grant any rights in the trademarks, service marks,
 | 
				
			||||||
 | 
					or logos of any Contributor (except as may be necessary to comply with
 | 
				
			||||||
 | 
					the notice requirements in Section 3.4).
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					2.4. Subsequent Licenses
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					No Contributor makes additional grants as a result of Your choice to
 | 
				
			||||||
 | 
					distribute the Covered Software under a subsequent version of this
 | 
				
			||||||
 | 
					License (see Section 10.2) or under the terms of a Secondary License (if
 | 
				
			||||||
 | 
					permitted under the terms of Section 3.3).
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					2.5. Representation
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Each Contributor represents that the Contributor believes its
 | 
				
			||||||
 | 
					Contributions are its original creation(s) or it has sufficient rights
 | 
				
			||||||
 | 
					to grant the rights to its Contributions conveyed by this License.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					2.6. Fair Use
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					This License is not intended to limit any rights You have under
 | 
				
			||||||
 | 
					applicable copyright doctrines of fair use, fair dealing, or other
 | 
				
			||||||
 | 
					equivalents.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					2.7. Conditions
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted
 | 
				
			||||||
 | 
					in Section 2.1.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					3. Responsibilities
 | 
				
			||||||
 | 
					-------------------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					3.1. Distribution of Source Form
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					All distribution of Covered Software in Source Code Form, including any
 | 
				
			||||||
 | 
					Modifications that You create or to which You contribute, must be under
 | 
				
			||||||
 | 
					the terms of this License. You must inform recipients that the Source
 | 
				
			||||||
 | 
					Code Form of the Covered Software is governed by the terms of this
 | 
				
			||||||
 | 
					License, and how they can obtain a copy of this License. You may not
 | 
				
			||||||
 | 
					attempt to alter or restrict the recipients' rights in the Source Code
 | 
				
			||||||
 | 
					Form.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					3.2. Distribution of Executable Form
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					If You distribute Covered Software in Executable Form then:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					(a) such Covered Software must also be made available in Source Code
 | 
				
			||||||
 | 
					    Form, as described in Section 3.1, and You must inform recipients of
 | 
				
			||||||
 | 
					    the Executable Form how they can obtain a copy of such Source Code
 | 
				
			||||||
 | 
					    Form by reasonable means in a timely manner, at a charge no more
 | 
				
			||||||
 | 
					    than the cost of distribution to the recipient; and
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					(b) You may distribute such Executable Form under the terms of this
 | 
				
			||||||
 | 
					    License, or sublicense it under different terms, provided that the
 | 
				
			||||||
 | 
					    license for the Executable Form does not attempt to limit or alter
 | 
				
			||||||
 | 
					    the recipients' rights in the Source Code Form under this License.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					3.3. Distribution of a Larger Work
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					You may create and distribute a Larger Work under terms of Your choice,
 | 
				
			||||||
 | 
					provided that You also comply with the requirements of this License for
 | 
				
			||||||
 | 
					the Covered Software. If the Larger Work is a combination of Covered
 | 
				
			||||||
 | 
					Software with a work governed by one or more Secondary Licenses, and the
 | 
				
			||||||
 | 
					Covered Software is not Incompatible With Secondary Licenses, this
 | 
				
			||||||
 | 
					License permits You to additionally distribute such Covered Software
 | 
				
			||||||
 | 
					under the terms of such Secondary License(s), so that the recipient of
 | 
				
			||||||
 | 
					the Larger Work may, at their option, further distribute the Covered
 | 
				
			||||||
 | 
					Software under the terms of either this License or such Secondary
 | 
				
			||||||
 | 
					License(s).
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					3.4. Notices
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					You may not remove or alter the substance of any license notices
 | 
				
			||||||
 | 
					(including copyright notices, patent notices, disclaimers of warranty,
 | 
				
			||||||
 | 
					or limitations of liability) contained within the Source Code Form of
 | 
				
			||||||
 | 
					the Covered Software, except that You may alter any license notices to
 | 
				
			||||||
 | 
					the extent required to remedy known factual inaccuracies.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					3.5. Application of Additional Terms
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					You may choose to offer, and to charge a fee for, warranty, support,
 | 
				
			||||||
 | 
					indemnity or liability obligations to one or more recipients of Covered
 | 
				
			||||||
 | 
					Software. However, You may do so only on Your own behalf, and not on
 | 
				
			||||||
 | 
					behalf of any Contributor. You must make it absolutely clear that any
 | 
				
			||||||
 | 
					such warranty, support, indemnity, or liability obligation is offered by
 | 
				
			||||||
 | 
					You alone, and You hereby agree to indemnify every Contributor for any
 | 
				
			||||||
 | 
					liability incurred by such Contributor as a result of warranty, support,
 | 
				
			||||||
 | 
					indemnity or liability terms You offer. You may include additional
 | 
				
			||||||
 | 
					disclaimers of warranty and limitations of liability specific to any
 | 
				
			||||||
 | 
					jurisdiction.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					4. Inability to Comply Due to Statute or Regulation
 | 
				
			||||||
 | 
					---------------------------------------------------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					If it is impossible for You to comply with any of the terms of this
 | 
				
			||||||
 | 
					License with respect to some or all of the Covered Software due to
 | 
				
			||||||
 | 
					statute, judicial order, or regulation then You must: (a) comply with
 | 
				
			||||||
 | 
					the terms of this License to the maximum extent possible; and (b)
 | 
				
			||||||
 | 
					describe the limitations and the code they affect. Such description must
 | 
				
			||||||
 | 
					be placed in a text file included with all distributions of the Covered
 | 
				
			||||||
 | 
					Software under this License. Except to the extent prohibited by statute
 | 
				
			||||||
 | 
					or regulation, such description must be sufficiently detailed for a
 | 
				
			||||||
 | 
					recipient of ordinary skill to be able to understand it.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					5. Termination
 | 
				
			||||||
 | 
					--------------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					5.1. The rights granted under this License will terminate automatically
 | 
				
			||||||
 | 
					if You fail to comply with any of its terms. However, if You become
 | 
				
			||||||
 | 
					compliant, then the rights granted under this License from a particular
 | 
				
			||||||
 | 
					Contributor are reinstated (a) provisionally, unless and until such
 | 
				
			||||||
 | 
					Contributor explicitly and finally terminates Your grants, and (b) on an
 | 
				
			||||||
 | 
					ongoing basis, if such Contributor fails to notify You of the
 | 
				
			||||||
 | 
					non-compliance by some reasonable means prior to 60 days after You have
 | 
				
			||||||
 | 
					come back into compliance. Moreover, Your grants from a particular
 | 
				
			||||||
 | 
					Contributor are reinstated on an ongoing basis if such Contributor
 | 
				
			||||||
 | 
					notifies You of the non-compliance by some reasonable means, this is the
 | 
				
			||||||
 | 
					first time You have received notice of non-compliance with this License
 | 
				
			||||||
 | 
					from such Contributor, and You become compliant prior to 30 days after
 | 
				
			||||||
 | 
					Your receipt of the notice.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					5.2. If You initiate litigation against any entity by asserting a patent
 | 
				
			||||||
 | 
					infringement claim (excluding declaratory judgment actions,
 | 
				
			||||||
 | 
					counter-claims, and cross-claims) alleging that a Contributor Version
 | 
				
			||||||
 | 
					directly or indirectly infringes any patent, then the rights granted to
 | 
				
			||||||
 | 
					You by any and all Contributors for the Covered Software under Section
 | 
				
			||||||
 | 
					2.1 of this License shall terminate.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					5.3. In the event of termination under Sections 5.1 or 5.2 above, all
 | 
				
			||||||
 | 
					end user license agreements (excluding distributors and resellers) which
 | 
				
			||||||
 | 
					have been validly granted by You or Your distributors under this License
 | 
				
			||||||
 | 
					prior to termination shall survive termination.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					************************************************************************
 | 
				
			||||||
 | 
					*                                                                      *
 | 
				
			||||||
 | 
					*  6. Disclaimer of Warranty                                           *
 | 
				
			||||||
 | 
					*  -------------------------                                           *
 | 
				
			||||||
 | 
					*                                                                      *
 | 
				
			||||||
 | 
					*  Covered Software is provided under this License on an "as is"       *
 | 
				
			||||||
 | 
					*  basis, without warranty of any kind, either expressed, implied, or  *
 | 
				
			||||||
 | 
					*  statutory, including, without limitation, warranties that the       *
 | 
				
			||||||
 | 
					*  Covered Software is free of defects, merchantable, fit for a        *
 | 
				
			||||||
 | 
					*  particular purpose or non-infringing. The entire risk as to the     *
 | 
				
			||||||
 | 
					*  quality and performance of the Covered Software is with You.        *
 | 
				
			||||||
 | 
					*  Should any Covered Software prove defective in any respect, You     *
 | 
				
			||||||
 | 
					*  (not any Contributor) assume the cost of any necessary servicing,   *
 | 
				
			||||||
 | 
					*  repair, or correction. This disclaimer of warranty constitutes an   *
 | 
				
			||||||
 | 
					*  essential part of this License. No use of any Covered Software is   *
 | 
				
			||||||
 | 
					*  authorized under this License except under this disclaimer.         *
 | 
				
			||||||
 | 
					*                                                                      *
 | 
				
			||||||
 | 
					************************************************************************
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					************************************************************************
 | 
				
			||||||
 | 
					*                                                                      *
 | 
				
			||||||
 | 
					*  7. Limitation of Liability                                          *
 | 
				
			||||||
 | 
					*  --------------------------                                          *
 | 
				
			||||||
 | 
					*                                                                      *
 | 
				
			||||||
 | 
					*  Under no circumstances and under no legal theory, whether tort      *
 | 
				
			||||||
 | 
					*  (including negligence), contract, or otherwise, shall any           *
 | 
				
			||||||
 | 
					*  Contributor, or anyone who distributes Covered Software as          *
 | 
				
			||||||
 | 
					*  permitted above, be liable to You for any direct, indirect,         *
 | 
				
			||||||
 | 
					*  special, incidental, or consequential damages of any character      *
 | 
				
			||||||
 | 
					*  including, without limitation, damages for lost profits, loss of    *
 | 
				
			||||||
 | 
					*  goodwill, work stoppage, computer failure or malfunction, or any    *
 | 
				
			||||||
 | 
					*  and all other commercial damages or losses, even if such party      *
 | 
				
			||||||
 | 
					*  shall have been informed of the possibility of such damages. This   *
 | 
				
			||||||
 | 
					*  limitation of liability shall not apply to liability for death or   *
 | 
				
			||||||
 | 
					*  personal injury resulting from such party's negligence to the       *
 | 
				
			||||||
 | 
					*  extent applicable law prohibits such limitation. Some               *
 | 
				
			||||||
 | 
					*  jurisdictions do not allow the exclusion or limitation of           *
 | 
				
			||||||
 | 
					*  incidental or consequential damages, so this exclusion and          *
 | 
				
			||||||
 | 
					*  limitation may not apply to You.                                    *
 | 
				
			||||||
 | 
					*                                                                      *
 | 
				
			||||||
 | 
					************************************************************************
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					8. Litigation
 | 
				
			||||||
 | 
					-------------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Any litigation relating to this License may be brought only in the
 | 
				
			||||||
 | 
					courts of a jurisdiction where the defendant maintains its principal
 | 
				
			||||||
 | 
					place of business and such litigation shall be governed by laws of that
 | 
				
			||||||
 | 
					jurisdiction, without reference to its conflict-of-law provisions.
 | 
				
			||||||
 | 
					Nothing in this Section shall prevent a party's ability to bring
 | 
				
			||||||
 | 
					cross-claims or counter-claims.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					9. Miscellaneous
 | 
				
			||||||
 | 
					----------------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					This License represents the complete agreement concerning the subject
 | 
				
			||||||
 | 
					matter hereof. If any provision of this License is held to be
 | 
				
			||||||
 | 
					unenforceable, such provision shall be reformed only to the extent
 | 
				
			||||||
 | 
					necessary to make it enforceable. Any law or regulation which provides
 | 
				
			||||||
 | 
					that the language of a contract shall be construed against the drafter
 | 
				
			||||||
 | 
					shall not be used to construe this License against a Contributor.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					10. Versions of the License
 | 
				
			||||||
 | 
					---------------------------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					10.1. New Versions
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Mozilla Foundation is the license steward. Except as provided in Section
 | 
				
			||||||
 | 
					10.3, no one other than the license steward has the right to modify or
 | 
				
			||||||
 | 
					publish new versions of this License. Each version will be given a
 | 
				
			||||||
 | 
					distinguishing version number.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					10.2. Effect of New Versions
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					You may distribute the Covered Software under the terms of the version
 | 
				
			||||||
 | 
					of the License under which You originally received the Covered Software,
 | 
				
			||||||
 | 
					or under the terms of any subsequent version published by the license
 | 
				
			||||||
 | 
					steward.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					10.3. Modified Versions
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					If you create software not governed by this License, and you want to
 | 
				
			||||||
 | 
					create a new license for such software, you may create and use a
 | 
				
			||||||
 | 
					modified version of this License if you rename the license and remove
 | 
				
			||||||
 | 
					any references to the name of the license steward (except to note that
 | 
				
			||||||
 | 
					such modified license differs from this License).
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					10.4. Distributing Source Code Form that is Incompatible With Secondary
 | 
				
			||||||
 | 
					Licenses
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					If You choose to distribute Source Code Form that is Incompatible With
 | 
				
			||||||
 | 
					Secondary Licenses under the terms of this version of the License, the
 | 
				
			||||||
 | 
					notice described in Exhibit B of this License must be attached.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Exhibit A - Source Code Form License Notice
 | 
				
			||||||
 | 
					-------------------------------------------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  This Source Code Form is subject to the terms of the Mozilla Public
 | 
				
			||||||
 | 
					  License, v. 2.0. If a copy of the MPL was not distributed with this
 | 
				
			||||||
 | 
					  file, You can obtain one at http://mozilla.org/MPL/2.0/.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					If it is not possible or desirable to put the notice in a particular
 | 
				
			||||||
 | 
					file, then You may include the notice in a location (such as a LICENSE
 | 
				
			||||||
 | 
					file in a relevant directory) where a recipient would be likely to look
 | 
				
			||||||
 | 
					for such a notice.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					You may add additional accurate notices of copyright ownership.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Exhibit B - "Incompatible With Secondary Licenses" Notice
 | 
				
			||||||
 | 
					---------------------------------------------------------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  This Source Code Form is "Incompatible With Secondary Licenses", as
 | 
				
			||||||
 | 
					  defined by the Mozilla Public License, v. 2.0.
 | 
				
			||||||
							
								
								
									
										472
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										472
									
								
								README.md
									
									
									
									
									
								
							@ -1,143 +1,418 @@
 | 
				
			|||||||
dns-suite
 | 
					# [dns-suite.js](https://git.rootprojects.org/root/dns-suite.js)
 | 
				
			||||||
========
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
Fast, lightweight, and easy-to-extend **pure JavaScript** (ES5.1) implementation for DNS / mDNS.
 | 
					| Built by [Root](https://rootprojects.org) for [Telebit](https://telebit.io) and [Hub](https://rootprojects.org/hub)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Works great in **Web Browsers** and in node.js!
 | 
					| **dns-suite.js**
 | 
				
			||||||
 | 
					| [dig.js](https://git.coolaj86.com/coolaj86/dig.js)
 | 
				
			||||||
 | 
					| [mdig.js](https://git.coolaj86.com/coolaj86/mdig.js)
 | 
				
			||||||
 | 
					| [digd.js](https://git.coolaj86.com/coolaj86/digd.js)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Detailed error checking makes it great for
 | 
					Fast, lightweight, and easy-to-extend Vanilla JS (ES5.1) implementation of DNS / mDNS for Node.js and Browsers.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
* capture
 | 
					-   [x] Full DNS Support
 | 
				
			||||||
* packing (JSON to DNS/mDNS)
 | 
					    -   [x] Queries
 | 
				
			||||||
* parsing (DNS/mDNS to JSON)
 | 
					    -   [x] Answers
 | 
				
			||||||
* linting (finding errors in packets)
 | 
					    -   [x] Authority
 | 
				
			||||||
* debugging
 | 
					    -   [x] Additional
 | 
				
			||||||
 | 
					-   [x] Built for Debugging
 | 
				
			||||||
 | 
					    -   [x] capture
 | 
				
			||||||
 | 
					    -   [x] packing (JSON to DNS/mDNS)
 | 
				
			||||||
 | 
					    -   [x] parsing (DNS/mDNS to JSON)
 | 
				
			||||||
 | 
					    -   [x] linting (finding errors in packets)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
**No external dependencies** for node.js or modern browsers. Uses `DataView`, `Uint8Array`, `Uint16Array`, and `ArrayBuffer`
 | 
					Uses `DataView`, `Uint8Array`, `Uint16Array`, and `ArrayBuffer`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Similar API to `dns.js` and `native-dns-packet`.
 | 
					Similar API to `dns.js` and `native-dns-packet`.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
```json
 | 
					# Example Query
 | 
				
			||||||
{ "header": {
 | 
					
 | 
				
			||||||
    "id": 5423
 | 
					```js
 | 
				
			||||||
  , "qr": 0
 | 
					var DNSPacket = require('dns-suite').DNSPacket;
 | 
				
			||||||
  , "opcode": 0
 | 
					
 | 
				
			||||||
  , "aa": 0
 | 
					var query = {
 | 
				
			||||||
  , "tc": 0
 | 
						header: {
 | 
				
			||||||
  , "rd": 1
 | 
							id: rnd,
 | 
				
			||||||
  , "ra": 0
 | 
							qr: 0,
 | 
				
			||||||
  , "res1": 0
 | 
							opcode: 0,
 | 
				
			||||||
  , "res2": 0
 | 
							aa: 0,
 | 
				
			||||||
  , "res3": 0
 | 
							rd: 1,
 | 
				
			||||||
  , "rcode": 0
 | 
							ra: 0,
 | 
				
			||||||
  }
 | 
							rcode: 0
 | 
				
			||||||
, "question": [
 | 
						},
 | 
				
			||||||
    { "name": "bowie._sftp-ssh._tcp.local"
 | 
						question: [
 | 
				
			||||||
    , "type": 1
 | 
							{
 | 
				
			||||||
    , "typeName": "A"
 | 
								name: 'google.com',
 | 
				
			||||||
    , "class": 1
 | 
								typeName: 'A',
 | 
				
			||||||
    , "className": "IN"
 | 
								className: 'IN'
 | 
				
			||||||
    , "byteLength": 32
 | 
					 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	]
 | 
						]
 | 
				
			||||||
, "answer": []
 | 
					};
 | 
				
			||||||
, "authority": []
 | 
					var buffer = DNSPacket.pack(query);
 | 
				
			||||||
, "additional": []
 | 
					```
 | 
				
			||||||
, "edns_options": []
 | 
					
 | 
				
			||||||
, "byteLength": 44
 | 
					# Example Response
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					```js
 | 
				
			||||||
 | 
					var DNSPacket = require('dns-suite').DNSPacket;
 | 
				
			||||||
 | 
					DNSPacket.parse(buffer);
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					```json
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						"header": {
 | 
				
			||||||
 | 
							"id": 5423,
 | 
				
			||||||
 | 
							"qr": 0,
 | 
				
			||||||
 | 
							"opcode": 0,
 | 
				
			||||||
 | 
							"aa": 0,
 | 
				
			||||||
 | 
							"tc": 0,
 | 
				
			||||||
 | 
							"rd": 1,
 | 
				
			||||||
 | 
							"ra": 0,
 | 
				
			||||||
 | 
							"res1": 0,
 | 
				
			||||||
 | 
							"res2": 0,
 | 
				
			||||||
 | 
							"res3": 0,
 | 
				
			||||||
 | 
							"rcode": 0
 | 
				
			||||||
 | 
						},
 | 
				
			||||||
 | 
						"question": [
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								"name": "bowie._sftp-ssh._tcp.local",
 | 
				
			||||||
 | 
								"type": 1,
 | 
				
			||||||
 | 
								"typeName": "A",
 | 
				
			||||||
 | 
								"class": 1,
 | 
				
			||||||
 | 
								"className": "IN",
 | 
				
			||||||
 | 
								"byteLength": 32
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						],
 | 
				
			||||||
 | 
						"answer": [],
 | 
				
			||||||
 | 
						"authority": [],
 | 
				
			||||||
 | 
						"additional": [],
 | 
				
			||||||
 | 
						"edns_options": [],
 | 
				
			||||||
 | 
						"byteLength": 44
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
```
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Install
 | 
					## Install
 | 
				
			||||||
-------
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
```bash
 | 
					```
 | 
				
			||||||
npm install git+https://git@git.daplie.com:Daplie/dns-suite
 | 
					npm install --save dns-suite
 | 
				
			||||||
```
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
**Test**:
 | 
					**Test**:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
```bash
 | 
					```bash
 | 
				
			||||||
pushd node_modules/dns-suite
 | 
					node ./node_modules/dns-suite/examples/dns-pack.js
 | 
				
			||||||
 | 
					 | 
				
			||||||
npm test
 | 
					 | 
				
			||||||
```
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Usage
 | 
					## Usage
 | 
				
			||||||
-----
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
**CLI**
 | 
					-   CLI
 | 
				
			||||||
 | 
					-   API
 | 
				
			||||||
 | 
					
 | 
				
			||||||
You can work directly from `node_modules/dns-suite`:
 | 
					### CLI Usage
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					When installed globally you can use these commands:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					dns-parse.js </path/to/packet.dns.bin> [out.json]   # parses a saved DNS packet to JSON
 | 
				
			||||||
 | 
					dns-pack.js </path/to/packet.dns.json> [out.bin]    # packs a JSON DNS packet to binary
 | 
				
			||||||
 | 
					dns-test.js </path/to/packet.dns(.json|.bin)>       # convert a packet back and forth to test reciprocity of the packer and parser
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					For **capturing packets** you should use [`dig.js`](https://git.coolaj86.com/coolaj86/dig.js#options) with the `--output` option.
 | 
				
			||||||
 | 
					It can capture mDNS as well. See <https://git.coolaj86.com/coolaj86/dig.js#options>.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					You can also access them directly from `node_modules/dns-suite` in a project:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
```bash
 | 
					```bash
 | 
				
			||||||
pushd node_modules/dns-suite/
 | 
					node node_modules/dns-suite/bin/dns-parse.js node_modules/dns-suite/samples/a-0.mdns.bin
 | 
				
			||||||
```
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Capture mDNS broadcast packets
 | 
					### Library API
 | 
				
			||||||
 | 
					
 | 
				
			||||||
```bash
 | 
					-   `DNSPacket.parse(nodeOrArrayBuffer)` returns json (as shown above)
 | 
				
			||||||
# example
 | 
					-   `DNSPacket.pack(packet)` returns ArrayBuffer (browser and node)
 | 
				
			||||||
# node bin/mdns-capture.js <file-prefix>
 | 
					-   `DNSPacket.write(packet)` returns NodeBuffer (node only)
 | 
				
			||||||
node bin/mdns-capture.js mdns-test
 | 
					 | 
				
			||||||
```
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
```bash
 | 
					 | 
				
			||||||
# in another terminal
 | 
					 | 
				
			||||||
dig @224.0.0.251 -p 5353 -t PTR _services._dns-sd._udp.local
 | 
					 | 
				
			||||||
```
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
Parsing a saved packet
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
```bash
 | 
					 | 
				
			||||||
# example
 | 
					 | 
				
			||||||
# node bin/dns-parse.js </path/to/packet.dns.bin>
 | 
					 | 
				
			||||||
node bin/dns-parse.js samples/a-0.mdns.bin
 | 
					 | 
				
			||||||
```
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
You can also parse a saved packet from the `native-dns-packet` directory.
 | 
					 | 
				
			||||||
these test packets have the binary for each record type and what it's parsed output
 | 
					 | 
				
			||||||
should be.
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
**Library**
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
* `packet = dnsjs.unpack(arrayBuffer)`
 | 
					 | 
				
			||||||
* `packet = dnsjs.unpackRdatas(arrayBuffer, packet)`
 | 
					 | 
				
			||||||
* `packet.answers[0].data = dnsjs.unpackRdatas(arrayBuffer, packet, packet.answers[0])`
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
node.js:
 | 
					node.js:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
```js
 | 
					```js
 | 
				
			||||||
var nodeBuffer = fs.readFileSync('./samples/a-0.mdns.bin');
 | 
					var nodeBuffer = fs.readFileSync('./samples/a-0.mdns.bin');
 | 
				
			||||||
var arrayBuffer = nodeBuffer.buffer;
 | 
					var arrayBuffer = nodeBuffer.buffer;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
var dnsjs = require('dns-suite');
 | 
					var DNSPacket = require('dns-suite').DNSPacket;
 | 
				
			||||||
var packet = dnsjs.unpack(arrayBuffer);
 | 
					var packet = DNSPacket.parse(arrayBuffer);
 | 
				
			||||||
 | 
					var ab = DNSPacket.pack(packet);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
console.log(packet);
 | 
					console.log(packet);
 | 
				
			||||||
 | 
					console.log(new Uint8Array(ab));
 | 
				
			||||||
```
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Browser:
 | 
					Browser:
 | 
				
			||||||
```js
 | 
					 | 
				
			||||||
var arrayBuffer = new Uint8Array.from([ /* bytes */ ]).buffer;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
var packet = pdns.unpack(arrayBuffer);
 | 
					```js
 | 
				
			||||||
 | 
					var arrayBuffer = new Uint8Array.from([
 | 
				
			||||||
 | 
						/* bytes */
 | 
				
			||||||
 | 
					]).buffer;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					var packet = DNSPacket.parse(arrayBuffer);
 | 
				
			||||||
 | 
					var ab = DNSPacket.pack(packet);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
console.log(packet);
 | 
					console.log(packet);
 | 
				
			||||||
 | 
					console.log(new Uint8Array(ab));
 | 
				
			||||||
```
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Contributing and Development
 | 
					## Capturing Packets
 | 
				
			||||||
============================
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
How to add a new parser
 | 
					We have a command line tool for that! See [dig.js](https://git.coolaj86.com/coolaj86/dig.js).
 | 
				
			||||||
-----------------------
 | 
					
 | 
				
			||||||
 | 
					```bash
 | 
				
			||||||
 | 
					# Install
 | 
				
			||||||
 | 
					npm install -g 'git+https://git.coolaj86.com/coolaj86/dig.js.git'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Use with DNS
 | 
				
			||||||
 | 
					dig.js A coolaj86.com --output .
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Use with mDNS
 | 
				
			||||||
 | 
					dig.js --mdns PTR _services._dns-sd._udp.local --output .
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Resource Record Examples
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					-   SOA
 | 
				
			||||||
 | 
					-   NS
 | 
				
			||||||
 | 
					-   A
 | 
				
			||||||
 | 
					-   AAAA
 | 
				
			||||||
 | 
					-   CNAME
 | 
				
			||||||
 | 
					-   MX
 | 
				
			||||||
 | 
					-   TXT
 | 
				
			||||||
 | 
					-   SRV
 | 
				
			||||||
 | 
					-   PTR
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					## SOA
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					I'm pretty sure that the SOA only goes in the `authority` section
 | 
				
			||||||
 | 
					(except when SOA is queried explicitly)
 | 
				
			||||||
 | 
					and that it's only given as a response to any empty set
 | 
				
			||||||
 | 
					(where `RCODE == NXDOMAIN`)
 | 
				
			||||||
 | 
					to affirm "yes, I am responsible for this domain but, no, I don't have a record for it".
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					If another nameserver has been delegated authority for a particular subdomain
 | 
				
			||||||
 | 
					a set of `NS` records should be returned instead.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					```json
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						"name": "yahoo.com",
 | 
				
			||||||
 | 
						"type": 6,
 | 
				
			||||||
 | 
						"typeName": "SOA",
 | 
				
			||||||
 | 
						"class": 1,
 | 
				
			||||||
 | 
						"className": "IN",
 | 
				
			||||||
 | 
						"ttl": 599,
 | 
				
			||||||
 | 
						"primary": "ns1.yahoo.com",
 | 
				
			||||||
 | 
						"admin": "hostmaster.yahoo-inc.com",
 | 
				
			||||||
 | 
						"serial": 2017092539,
 | 
				
			||||||
 | 
						"refresh": 3600,
 | 
				
			||||||
 | 
						"retry": 300,
 | 
				
			||||||
 | 
						"expiration": 1814400,
 | 
				
			||||||
 | 
						"minimum": 600
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					## NS
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					I'm also pretty sure that the NS only goes in the `authority` section
 | 
				
			||||||
 | 
					(except when NS is queried explicitly)
 | 
				
			||||||
 | 
					and that it's given as a successful response
 | 
				
			||||||
 | 
					(`RCODE == SUCCESS`)
 | 
				
			||||||
 | 
					to any query type
 | 
				
			||||||
 | 
					(`A` or `AAAA`, `MX`, `TXT`, or `SRV`)
 | 
				
			||||||
 | 
					where the answer sections is an empty set because the records in
 | 
				
			||||||
 | 
					question have been delegated to another nameserver.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					```json
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						"name": "google.com",
 | 
				
			||||||
 | 
						"type": 2,
 | 
				
			||||||
 | 
						"typeName": "NS",
 | 
				
			||||||
 | 
						"class": 1,
 | 
				
			||||||
 | 
						"className": "IN",
 | 
				
			||||||
 | 
						"ttl": 82790,
 | 
				
			||||||
 | 
						"data": "ns3.google.com"
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					## A
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					The most common type of record. Returns the IPv4 address for a given domain.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					```json
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						"name": "www.linode.com",
 | 
				
			||||||
 | 
						"type": 1,
 | 
				
			||||||
 | 
						"typeName": "A",
 | 
				
			||||||
 | 
						"class": 1,
 | 
				
			||||||
 | 
						"className": "IN",
 | 
				
			||||||
 | 
						"ttl": 291,
 | 
				
			||||||
 | 
						"address": "72.14.191.202"
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					## AAAA
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Returns the IPv6 address for a given domain.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					```json
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						"name": "irc6.geo.oftc.net",
 | 
				
			||||||
 | 
						"type": 28,
 | 
				
			||||||
 | 
						"typeName": "AAAA",
 | 
				
			||||||
 | 
						"class": 1,
 | 
				
			||||||
 | 
						"className": "IN",
 | 
				
			||||||
 | 
						"ttl": 59,
 | 
				
			||||||
 | 
						"address": "2607:f8f0:610:4000:211:11ff:fe1c:7bec"
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					## CNAME
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					The CNAME is used to look up the IP address for the given alias.
 | 
				
			||||||
 | 
					(the alias is often referred to incorrectly as a CNAME but it is, in fact, the alias)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					```json
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						"name": "www.nodejs.org",
 | 
				
			||||||
 | 
						"type": 5,
 | 
				
			||||||
 | 
						"typeName": "CNAME",
 | 
				
			||||||
 | 
						"class": 1,
 | 
				
			||||||
 | 
						"className": "IN",
 | 
				
			||||||
 | 
						"ttl": 3600,
 | 
				
			||||||
 | 
						"data": "nodejs.org"
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					## MX
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Mail Exchange Records show the alias that should be looked up to know where incoming mail should
 | 
				
			||||||
 | 
					be sent.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					```json
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						"name": "microsoft.com",
 | 
				
			||||||
 | 
						"type": 15,
 | 
				
			||||||
 | 
						"typeName": "MX",
 | 
				
			||||||
 | 
						"class": 1,
 | 
				
			||||||
 | 
						"className": "IN",
 | 
				
			||||||
 | 
						"ttl": 197,
 | 
				
			||||||
 | 
						"priority": 10,
 | 
				
			||||||
 | 
						"exchange": "microsoft-com.mail.protection.outlook.com"
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					## TXT
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Often used for outgoing mail validations, public keys, lots of arbitrary stuff.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					```json
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						"name": "aol.com",
 | 
				
			||||||
 | 
						"type": 16,
 | 
				
			||||||
 | 
						"typeName": "TXT",
 | 
				
			||||||
 | 
						"class": 1,
 | 
				
			||||||
 | 
						"className": "IN",
 | 
				
			||||||
 | 
						"ttl": 1926,
 | 
				
			||||||
 | 
						"data": ["v=spf1 ptr:mx.aol.com ?all"]
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					## SRV
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					A way to associate a service with a port and other relevant information.
 | 
				
			||||||
 | 
					Used for federated / dencentralized protocols (like XMPP) and mDNS/DLNA/UPnP/DNS-SD type stuff.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					```json
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						"name": "_xmpp-server._tcp.gmail.com",
 | 
				
			||||||
 | 
						"type": 33,
 | 
				
			||||||
 | 
						"typeName": "SRV",
 | 
				
			||||||
 | 
						"class": 1,
 | 
				
			||||||
 | 
						"className": "IN",
 | 
				
			||||||
 | 
						"ttl": 900,
 | 
				
			||||||
 | 
						"priority": 5,
 | 
				
			||||||
 | 
						"weight": 0,
 | 
				
			||||||
 | 
						"port": 5269,
 | 
				
			||||||
 | 
						"target": "xmpp-server.l.google.com"
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					## PTR
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Used for mDNS/DNS-SD type discoveries and anti-spam reverse lookup verification for mail servers.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					```json
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						"name": "_pdl-datastream._tcp.local",
 | 
				
			||||||
 | 
						"type": 12,
 | 
				
			||||||
 | 
						"typeName": "PTR",
 | 
				
			||||||
 | 
						"class": 1,
 | 
				
			||||||
 | 
						"className": "IN",
 | 
				
			||||||
 | 
						"ttl": 255,
 | 
				
			||||||
 | 
						"data": "Canon MF620C Series._pdl-datastream._tcp.local"
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					## All Properties
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					For simplicity, here's a list of all properties, just for fun:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					```js
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  // All RRs
 | 
				
			||||||
 | 
					  "name": "example.com",
 | 
				
			||||||
 | 
					  "type": 1,
 | 
				
			||||||
 | 
					  "typeName": "A",
 | 
				
			||||||
 | 
					  "class": 1,
 | 
				
			||||||
 | 
					  "className": "IN",
 | 
				
			||||||
 | 
					  "ttl": 600,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // SOA
 | 
				
			||||||
 | 
					  "primary": "ns1.yahoo.com",
 | 
				
			||||||
 | 
					  "admin": "hostmaster.yahoo-inc.com",
 | 
				
			||||||
 | 
					  "serial": 2017092539,
 | 
				
			||||||
 | 
					  "refresh": 3600,
 | 
				
			||||||
 | 
					  "retry": 300,
 | 
				
			||||||
 | 
					  "expiration": 1814400,
 | 
				
			||||||
 | 
					  "minimum": 600,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // A, AAAA
 | 
				
			||||||
 | 
					  "address": "72.14.191.202",
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // CNAME, NS, PTR
 | 
				
			||||||
 | 
					  "data": "ns3.google.com",
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // TXT
 | 
				
			||||||
 | 
					  // "data": [ "v=spf1 ptr:mx.aol.com ?all" ],
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // MX
 | 
				
			||||||
 | 
					  "priority": 10,
 | 
				
			||||||
 | 
					  "exchange": "microsoft-com.mail.protection.outlook.com",
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // SRV
 | 
				
			||||||
 | 
					  "priority": 5,
 | 
				
			||||||
 | 
					  "weight": 0,
 | 
				
			||||||
 | 
					  "port": 5269,
 | 
				
			||||||
 | 
					  "target": "xmpp-server.l.google.com"
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Contributing and Development
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					## How to add a new parser
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Each RR (aka Resource Record or RData) parser is individual. Examples include:
 | 
					Each RR (aka Resource Record or RData) parser is individual. Examples include:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
* A (`parser/type.a.js`)
 | 
					-   A (`parser/type.a.js`)
 | 
				
			||||||
* AAAA (`parser/type.aaaa.js`)
 | 
					-   AAAA (`parser/type.aaaa.js`)
 | 
				
			||||||
* CNAME (`parser/type.cname.js`)
 | 
					-   CNAME (`parser/type.cname.js`)
 | 
				
			||||||
* TXT (`parser/type.txt.js`)
 | 
					-   TXT (`parser/type.txt.js`)
 | 
				
			||||||
* SRV (`parser/type.srv.js`)
 | 
					-   SRV (`parser/type.srv.js`)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Let's say that To create a parser for a type which we don't currently support,
 | 
					Let's say that To create a parser for a type which we don't currently support,
 | 
				
			||||||
just add the appropriate information to `dns.types.js` and create a file for
 | 
					just add the appropriate information to `dns.types.js` and create a file for
 | 
				
			||||||
@ -146,7 +421,7 @@ the name of the type in the format `parser/type.<typename>.js`.
 | 
				
			|||||||
For example, if `CNAME` wasn't already supported and I wanted to add support for
 | 
					For example, if `CNAME` wasn't already supported and I wanted to add support for
 | 
				
			||||||
it I would follow these steps:
 | 
					it I would follow these steps:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
1) Update `dns.types.js`
 | 
					1. Update `dns.types.js` if it's not there already.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
```
 | 
					```
 | 
				
			||||||
  A: 			0x01	//   1
 | 
					  A: 			0x01	//   1
 | 
				
			||||||
@ -155,7 +430,7 @@ it I would follow these steps:
 | 
				
			|||||||
, SOA: 		0x06  //   6
 | 
					, SOA: 		0x06  //   6
 | 
				
			||||||
```
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
2) Capture a packet to `test/fixtures/<domain>.<tld>.<type>.bin`
 | 
					2. Capture a packet to `test/fixtures/<domain>.<tld>.<type>.bin`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
This will construct and send a DNS query and save the first result
 | 
					This will construct and send a DNS query and save the first result
 | 
				
			||||||
that comes back.
 | 
					that comes back.
 | 
				
			||||||
@ -169,10 +444,11 @@ Ideally you should have some idea of what the result file should look
 | 
				
			|||||||
like and should place that in `test/fixtures/<domain>.<tld>.<type>.json`
 | 
					like and should place that in `test/fixtures/<domain>.<tld>.<type>.json`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
```bash
 | 
					```bash
 | 
				
			||||||
node bin/capture-query.js --name www.google.com --type CNAME
 | 
					npm install -g dig.js
 | 
				
			||||||
 | 
					dig.js --name www.google.com --type CNAME --output ./samples/
 | 
				
			||||||
```
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
3) Create `parser/type.cname.js`
 | 
					3. Create `parser/type.cname.js`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Copy `parser/type.TEMPLATE.js` to the type for which you wish to create support
 | 
					Copy `parser/type.TEMPLATE.js` to the type for which you wish to create support
 | 
				
			||||||
(`parser/type.cname.js` in this example) and fill in the blanks.
 | 
					(`parser/type.cname.js` in this example) and fill in the blanks.
 | 
				
			||||||
@ -190,7 +466,7 @@ exports.DNS_PARSER_TYPE_CNAME = function (ab, packet, record) {
 | 
				
			|||||||
}('undefined' !== typeof window ? window : exports));
 | 
					}('undefined' !== typeof window ? window : exports));
 | 
				
			||||||
```
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
4) Document what you've learned in `doc/<type>.txt`
 | 
					4. Document what you've learned in `doc/<type>.txt`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
You may be right or you might be wrong, but you might be right.
 | 
					You may be right or you might be wrong, but you might be right.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -200,7 +476,7 @@ record type - tips, tricks, little-known facts, etc.
 | 
				
			|||||||
This may help (or wildly mislead) others if there's a bug in your parser that they need to track down.
 | 
					This may help (or wildly mislead) others if there's a bug in your parser that they need to track down.
 | 
				
			||||||
At the very least someone can follow a few links you followed and your thought process.
 | 
					At the very least someone can follow a few links you followed and your thought process.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
5) Check that my changes include these files
 | 
					5. Check that my changes include these files
 | 
				
			||||||
 | 
					
 | 
				
			||||||
```
 | 
					```
 | 
				
			||||||
├── README.md
 | 
					├── README.md
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										219
									
								
								bin/debug.js
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										219
									
								
								bin/debug.js
									
									
									
									
									
										Executable file
									
								
							@ -0,0 +1,219 @@
 | 
				
			|||||||
 | 
					#!/usr/bin/env node
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// node bin/debug.js ../dig.js/blar.DOEsNteXiST.AJ.OnEal.DAplIE.me.any.0.bin
 | 
				
			||||||
 | 
					// node bin/debugd.js ../dig.js/blar.DOEsNteXiST.AJ.OnEal.DAplIE.me.any.0.bin
 | 
				
			||||||
 | 
					// dig @localhost -p 65053 ANY DOEsNteXiST.AJ.OnEal.DAplIE.me
 | 
				
			||||||
 | 
					// dd if=../dig.js/blar.DOEsNteXiST.AJ.OnEal.DAplIE.me.any.0.bin of=blar.DOEsNteXiST.AJ.OnEal.DAplIE.me.any.0.trunc.bin bs=1 count=78
 | 
				
			||||||
 | 
					(function () {
 | 
				
			||||||
 | 
					'use strict';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					var input = process.argv[2];
 | 
				
			||||||
 | 
					var fs = require('fs');
 | 
				
			||||||
 | 
					var nb = fs.readFileSync(input, null);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					var ab = nb.buffer.slice(nb.byteOffset, nb.byteOffset + nb.byteLength);
 | 
				
			||||||
 | 
					var dv = new DataView(ab);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					//
 | 
				
			||||||
 | 
					// read header
 | 
				
			||||||
 | 
					//
 | 
				
			||||||
 | 
					console.log('');
 | 
				
			||||||
 | 
					console.log('//////////////////');
 | 
				
			||||||
 | 
					console.log('//    HEADER    //');
 | 
				
			||||||
 | 
					console.log('//////////////////');
 | 
				
			||||||
 | 
					console.log('');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					console.log('');
 | 
				
			||||||
 | 
					console.log('byte index 0x00');
 | 
				
			||||||
 | 
					console.log('');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					console.log('id (int)', dv.getUint16(0));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					var flags = dv.getUint16(2, false);
 | 
				
			||||||
 | 
					console.log('header 0x', flags.toString(16));
 | 
				
			||||||
 | 
					var flagsstr = ''
 | 
				
			||||||
 | 
						+ 'qr ' + ((flags & 0x8000) >> 15) + ', '
 | 
				
			||||||
 | 
					  + 'opcode ' + ((flags & 0x7800) >> 11) + ', '
 | 
				
			||||||
 | 
					  + 'aa ' + ((flags &  0x400) >> 10) + ', '
 | 
				
			||||||
 | 
					  + 'tc ' + ((flags &  0x200) >>  9) + ', '
 | 
				
			||||||
 | 
					  + 'rd ' + ((flags &  0x100) >>  8) + ', '
 | 
				
			||||||
 | 
					  + 'ra ' + ((flags &   0x80) >>  7) + ', '
 | 
				
			||||||
 | 
					  + 'res1 ' + ((flags &   0x40) >>  6) + ', '
 | 
				
			||||||
 | 
					  + 'res2 ' + ((flags &   0x20) >>  5) + ', '
 | 
				
			||||||
 | 
					  + 'res3 ' + ((flags &   0x10) >>  4) + ', '
 | 
				
			||||||
 | 
					  + 'rcode ' + ((flags &    0xF));
 | 
				
			||||||
 | 
					console.log('(flags: ' + flagsstr);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					var qdcount = dv.getUint16(4, false);  // query count
 | 
				
			||||||
 | 
					var ancount = dv.getUint16(6, false);  // answer count
 | 
				
			||||||
 | 
					var nscount = dv.getUint16(8, false);  // authority count
 | 
				
			||||||
 | 
					var arcount = dv.getUint16(10, false); // additional count
 | 
				
			||||||
 | 
					var count;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					console.log('qdcount', qdcount);
 | 
				
			||||||
 | 
					console.log('ancount', ancount);
 | 
				
			||||||
 | 
					console.log('nscount', nscount);
 | 
				
			||||||
 | 
					console.log('arcount', arcount);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function unpackQuestionLabels(opts) {
 | 
				
			||||||
 | 
					  var dv = opts.dv;
 | 
				
			||||||
 | 
					  //var origTotal = opts.total;
 | 
				
			||||||
 | 
					  var total = opts.total;
 | 
				
			||||||
 | 
					  var len = opts.len;
 | 
				
			||||||
 | 
					  var qnames = [];
 | 
				
			||||||
 | 
					  var labelLen;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  while (true) {
 | 
				
			||||||
 | 
					    if (total >= len) {
 | 
				
			||||||
 | 
					      opts.trunc = true;
 | 
				
			||||||
 | 
					      console.warn('');
 | 
				
			||||||
 | 
					      console.warn('[WARNING] The label was truncated by byte length of message or rdata.');
 | 
				
			||||||
 | 
					      console.warn('[WARNING] Depending on the Resource Record type, that may be a parse error.');
 | 
				
			||||||
 | 
					      console.warn('');
 | 
				
			||||||
 | 
					      break;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    labelLen = dv.getUint8(total, false); // additional count
 | 
				
			||||||
 | 
					    total += 1;
 | 
				
			||||||
 | 
					    if (!labelLen) {
 | 
				
			||||||
 | 
					      break;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    if (labelLen >= 0xc0) {
 | 
				
			||||||
 | 
					      // (11 000000 & whatever) signifies pointer
 | 
				
			||||||
 | 
					      // (00 111111 & whatever) bitmask for potentially large pointer
 | 
				
			||||||
 | 
					      // (00 000001   11111111) largest realistic pointer value (512 byte message size)
 | 
				
			||||||
 | 
					      var pointer = ((labelLen & 0x3f) << 8) | dv.getUint8(total, false);
 | 
				
			||||||
 | 
					      console.log('Found a pointer to'
 | 
				
			||||||
 | 
					        + ' 0x' + pointer.toString(16) + ' (' + pointer + ')'
 | 
				
			||||||
 | 
					        + ' at byte index'
 | 
				
			||||||
 | 
					        + ' 0x' + leftPad(total.toString(16)) + ' (' + total + ')'
 | 
				
			||||||
 | 
					        //+ ' which back-references:'
 | 
				
			||||||
 | 
					      );
 | 
				
			||||||
 | 
					      /*
 | 
				
			||||||
 | 
					      console.log('-4', dv.getUint8(pointer - 4, false));
 | 
				
			||||||
 | 
					      console.log('-3', dv.getUint8(pointer - 3, false));
 | 
				
			||||||
 | 
					      console.log('-2', dv.getUint8(pointer - 2, false));
 | 
				
			||||||
 | 
					      console.log('-1', dv.getUint8(pointer - 1, false));
 | 
				
			||||||
 | 
					      console.log(' 0', dv.getUint8(pointer + 0, false));
 | 
				
			||||||
 | 
					      console.log('+1', dv.getUint8(pointer + 1, false));
 | 
				
			||||||
 | 
					      console.log('+2', dv.getUint8(pointer + 2, false));
 | 
				
			||||||
 | 
					      console.log('bytes near the pointer itself (not what it points to) are:');
 | 
				
			||||||
 | 
					      console.log('-2', dv.getUint8(total - 2, false));
 | 
				
			||||||
 | 
					      console.log('-1', dv.getUint8(total - 1, false));
 | 
				
			||||||
 | 
					      console.log(' 0', dv.getUint8(total + 0, false));
 | 
				
			||||||
 | 
					      console.log('+1', dv.getUint8(total + 1, false));
 | 
				
			||||||
 | 
					      console.log('+2', dv.getUint8(total + 2, false));
 | 
				
			||||||
 | 
					      console.log('+3', dv.getUint8(total + 3, false));
 | 
				
			||||||
 | 
					      console.log('+4', dv.getUint8(total + 4, false));
 | 
				
			||||||
 | 
					      */
 | 
				
			||||||
 | 
					      //total += 1;
 | 
				
			||||||
 | 
					      opts.cp = true;
 | 
				
			||||||
 | 
					      qnames.push(unpackQuestionLabels({ dv: dv, total: pointer, len: len }).qname);
 | 
				
			||||||
 | 
					      total += 1;
 | 
				
			||||||
 | 
					      break;
 | 
				
			||||||
 | 
					    } else {
 | 
				
			||||||
 | 
					      var i;
 | 
				
			||||||
 | 
					      var label = '';
 | 
				
			||||||
 | 
					      console.log('label len', labelLen);
 | 
				
			||||||
 | 
					      for (i = 0; i < labelLen; i += 1) {
 | 
				
			||||||
 | 
					        //console.log('total:', total, i);
 | 
				
			||||||
 | 
					        label += String.fromCharCode(dv.getUint8(total + i, false));
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					      total += label.length;
 | 
				
			||||||
 | 
					      console.log('label:', label);
 | 
				
			||||||
 | 
					      qnames.push(label);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  return {
 | 
				
			||||||
 | 
					    total: total
 | 
				
			||||||
 | 
					  , qname: qnames.join('.')
 | 
				
			||||||
 | 
					  };
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function unpackQuestion(dv, total, len) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  var result = unpackQuestionLabels({ dv: dv, total: total, len: len });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // leading length and (potentially) trailing null
 | 
				
			||||||
 | 
					  console.log('QNAME (len ' + (result.total - total) + '):', result.qname, result.cp ? '(pointer)' : '');
 | 
				
			||||||
 | 
					  console.log('QTYPE (len 2):', dv.getUint16(result.total, false));
 | 
				
			||||||
 | 
					  result.total += 2;
 | 
				
			||||||
 | 
					  console.log('QCLASS (len 2):', dv.getUint16(result.total, false));
 | 
				
			||||||
 | 
					  result.total += 2;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  return result;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					var q = { total: 12 };
 | 
				
			||||||
 | 
					function mapChar(ch) { return JSON.stringify(String.fromCharCode(ch)) + '(' + ch + ')'; }
 | 
				
			||||||
 | 
					function leftPad(ch) { ch = ch.toString(); while (ch.length < 2) { ch = '0' + ch; } return ch; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					console.log('');
 | 
				
			||||||
 | 
					console.log('//////////////////');
 | 
				
			||||||
 | 
					console.log('//   QUESTION   //');
 | 
				
			||||||
 | 
					console.log('//////////////////');
 | 
				
			||||||
 | 
					console.log('');
 | 
				
			||||||
 | 
					for (count = 0; count < qdcount; count += 1) {
 | 
				
			||||||
 | 
					  console.log('');
 | 
				
			||||||
 | 
					  console.log('Question ' + (count + 1) + ' of ' + qdcount + ' (byte index: 0x' + leftPad(q.total.toString(16)) + ' ' + q.total + ')');
 | 
				
			||||||
 | 
					  q = unpackQuestion(dv, q.total, ab.byteLength);
 | 
				
			||||||
 | 
					  console.log('');
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function unpackResourceRecord(dv, q, ab) {
 | 
				
			||||||
 | 
					  var _q = unpackQuestion(dv, q.total, ab.byteLength);
 | 
				
			||||||
 | 
					  q.total = _q.total;
 | 
				
			||||||
 | 
					  console.log('ttl (len 4):', dv.getUint32(q.total, false));
 | 
				
			||||||
 | 
					  q.total += 4;
 | 
				
			||||||
 | 
					  q.rdlength = dv.getUint16(q.total, false);
 | 
				
			||||||
 | 
					  console.log('rdlen (len 2):', q.rdlength);
 | 
				
			||||||
 | 
					  q.total += 2;
 | 
				
			||||||
 | 
					  console.log('rrdata (len ' + q.rdlength + '):');
 | 
				
			||||||
 | 
					  console.log([].slice.call(new Uint8Array(ab), q.total, q.total + q.rdlength).map(mapChar).join(' '));
 | 
				
			||||||
 | 
					  q.total += q.rdlength;
 | 
				
			||||||
 | 
					  console.log('');
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					console.log('');
 | 
				
			||||||
 | 
					console.log('//////////////////');
 | 
				
			||||||
 | 
					console.log('//    ANSWER    //');
 | 
				
			||||||
 | 
					console.log('//////////////////');
 | 
				
			||||||
 | 
					console.log('');
 | 
				
			||||||
 | 
					for (count = 0; count < ancount; count += 1) {
 | 
				
			||||||
 | 
					  console.log('');
 | 
				
			||||||
 | 
					  console.log('Answer', count + 1, 'of', ancount + ' (byte index: 0x' + q.total.toString(16) + ' ' + q.total + ')');
 | 
				
			||||||
 | 
					  unpackResourceRecord(dv, q, ab);
 | 
				
			||||||
 | 
					  console.log('');
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					console.log('');
 | 
				
			||||||
 | 
					console.log('//////////////////');
 | 
				
			||||||
 | 
					console.log('//   AUTHORITY  //');
 | 
				
			||||||
 | 
					console.log('//////////////////');
 | 
				
			||||||
 | 
					console.log('');
 | 
				
			||||||
 | 
					for (count = 0; count < nscount; count += 1) {
 | 
				
			||||||
 | 
					  console.log('');
 | 
				
			||||||
 | 
					  console.log('Authority', count + 1, 'of', nscount + ' (byte index: 0x' + q.total.toString(16) + ' ' + q.total + ')');
 | 
				
			||||||
 | 
					  unpackResourceRecord(dv, q, ab);
 | 
				
			||||||
 | 
					  console.log('');
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					console.log('');
 | 
				
			||||||
 | 
					console.log('//////////////////');
 | 
				
			||||||
 | 
					console.log('//  ADDITIONAL  //');
 | 
				
			||||||
 | 
					console.log('//////////////////');
 | 
				
			||||||
 | 
					console.log('');
 | 
				
			||||||
 | 
					for (count = 0; count < arcount; count += 1) {
 | 
				
			||||||
 | 
					  console.log('');
 | 
				
			||||||
 | 
					  console.log('Additional', count + 1, 'of', arcount + ' (byte index: 0x' + q.total.toString(16) + ' ' + q.total + ')');
 | 
				
			||||||
 | 
					  unpackResourceRecord(dv, q, ab);
 | 
				
			||||||
 | 
					  console.log('');
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					console.log('');
 | 
				
			||||||
 | 
					console.log('total bytes', dv.byteLength);
 | 
				
			||||||
 | 
					console.log('total bytes read', q.total);
 | 
				
			||||||
 | 
					console.log('');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}());
 | 
				
			||||||
							
								
								
									
										46
									
								
								bin/debugd.js
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										46
									
								
								bin/debugd.js
									
									
									
									
									
										Executable file
									
								
							@ -0,0 +1,46 @@
 | 
				
			|||||||
 | 
					#!/usr/bin/env
 | 
				
			||||||
 | 
					(function () {
 | 
				
			||||||
 | 
					'use strict';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					var cli = { port: 65153, address: null, udp6: false, bin: process.argv[2] };
 | 
				
			||||||
 | 
					var dgram = require('dgram');
 | 
				
			||||||
 | 
					var server = dgram.createSocket({
 | 
				
			||||||
 | 
					  type: cli.udp6 ? 'udp6' : 'udp4'
 | 
				
			||||||
 | 
					, reuseAddr: true
 | 
				
			||||||
 | 
					});
 | 
				
			||||||
 | 
					var handlers = {};
 | 
				
			||||||
 | 
					var bin = require('fs').readFileSync(cli.bin, null);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					handlers.onMessage = function (nb, rinfo) {
 | 
				
			||||||
 | 
					  console.log('[DEBUG] got a message');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // replace the id to match
 | 
				
			||||||
 | 
					  bin[0] = nb[0];
 | 
				
			||||||
 | 
					  bin[1] = nb[1];
 | 
				
			||||||
 | 
					  server.send(bin, rinfo.port, rinfo.address, function () {
 | 
				
			||||||
 | 
					    console.log('[DEBUG] sent response');
 | 
				
			||||||
 | 
					  });
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					handlers.onListening = function () {
 | 
				
			||||||
 | 
					  /*jshint validthis:true*/
 | 
				
			||||||
 | 
					  var server = this;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  if (cli.mdns || '224.0.0.251' === cli.nameserver) {
 | 
				
			||||||
 | 
					    server.setBroadcast(true);
 | 
				
			||||||
 | 
					    server.addMembership(cli.nameserver);
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  console.log('');
 | 
				
			||||||
 | 
					  console.log('Bound and Listening:');
 | 
				
			||||||
 | 
					  console.log(server.address().address + '#' + server.address().port + ' (' + server.type + ')');
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					server.bind({
 | 
				
			||||||
 | 
					  port: cli.port
 | 
				
			||||||
 | 
					, address: cli.address
 | 
				
			||||||
 | 
					});
 | 
				
			||||||
 | 
					server.on('listening', handlers.onListening);
 | 
				
			||||||
 | 
					server.on('message', handlers.onMessage);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}());
 | 
				
			||||||
							
								
								
									
										68
									
								
								bin/dns-pack.js
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										68
									
								
								bin/dns-pack.js
									
									
									
									
									
										Executable file
									
								
							@ -0,0 +1,68 @@
 | 
				
			|||||||
 | 
					#!/usr/bin/env node
 | 
				
			||||||
 | 
					'use strict';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// EXAMPLE:
 | 
				
			||||||
 | 
					// node bin/dns-parse.js samples/a-0.mdns.bin
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					var path = require('path');
 | 
				
			||||||
 | 
					// pass a terminal arg
 | 
				
			||||||
 | 
					var filename = process.argv[2];
 | 
				
			||||||
 | 
					var outname = process.argv[3];
 | 
				
			||||||
 | 
					if (!filename) {
 | 
				
			||||||
 | 
						console.error(
 | 
				
			||||||
 | 
							'Usage: node bin/dns-pack.js <path/to/sample.json> <path/to/output.bin>'
 | 
				
			||||||
 | 
						);
 | 
				
			||||||
 | 
						console.error(
 | 
				
			||||||
 | 
							'Example: node bin/dns-pack.js ./samples/services-0.mdns.json ./services-0.mdns.bin'
 | 
				
			||||||
 | 
						);
 | 
				
			||||||
 | 
						process.exit(1);
 | 
				
			||||||
 | 
						return;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					if (!outname) {
 | 
				
			||||||
 | 
						console.warn('');
 | 
				
			||||||
 | 
						console.warn(
 | 
				
			||||||
 | 
							"Usage: node bin/dns-pack.js '" +
 | 
				
			||||||
 | 
								filename +
 | 
				
			||||||
 | 
								"' './" +
 | 
				
			||||||
 | 
								path.basename(filename).replace(path.extname(filename), '') +
 | 
				
			||||||
 | 
								".bin'"
 | 
				
			||||||
 | 
						);
 | 
				
			||||||
 | 
						console.warn('');
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					var PromiseA = require('bluebird');
 | 
				
			||||||
 | 
					var fs = PromiseA.promisifyAll(require('fs'));
 | 
				
			||||||
 | 
					var dnsjs = require('../').DNSPacket;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					fs.readFileAsync(filename, null).then(function(nb) {
 | 
				
			||||||
 | 
						//
 | 
				
			||||||
 | 
						// current reference impl
 | 
				
			||||||
 | 
						//
 | 
				
			||||||
 | 
						//console.log(require('native-dns-packet').parse(nb));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						//
 | 
				
			||||||
 | 
						// other reference impl
 | 
				
			||||||
 | 
						//
 | 
				
			||||||
 | 
						//console.log(require('dns-js').DNSPacket.parse(nb));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// nb is a Uint8Array (ArrayBufferView) for nb.buffer
 | 
				
			||||||
 | 
						// nb.buffer is the actual ArrayBuffer
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						//var ab = nb.buffer.slice(nb.byteOffset, nb.byteOffset + nb.byteLength);
 | 
				
			||||||
 | 
						var packet = dnsjs.write(JSON.parse(nb.toString('ascii')));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						//console.log('[packet]', nb.byteLength, 'bytes:');
 | 
				
			||||||
 | 
						//console.log(JSON.stringify(packet, null, 2));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						//TODO hexdump packet
 | 
				
			||||||
 | 
						var hexdump = require('@root/hexdump');
 | 
				
			||||||
 | 
						var str = hexdump(packet);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						console.log(str);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (outname) {
 | 
				
			||||||
 | 
							fs.writeFileSync(outname, packet, null);
 | 
				
			||||||
 | 
							console.log('');
 | 
				
			||||||
 | 
							console.log("wrote '" + outname + "'");
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					});
 | 
				
			||||||
							
								
								
									
										1
									
								
								bin/dns-parse.js
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							
							
						
						
									
										1
									
								
								bin/dns-parse.js
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							@ -1,3 +1,4 @@
 | 
				
			|||||||
 | 
					#!/usr/bin/env node
 | 
				
			||||||
'use strict';
 | 
					'use strict';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// EXAMPLE:
 | 
					// EXAMPLE:
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										153
									
								
								bin/dns-test.js
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										153
									
								
								bin/dns-test.js
									
									
									
									
									
										Executable file
									
								
							@ -0,0 +1,153 @@
 | 
				
			|||||||
 | 
					#!/usr/bin/env node
 | 
				
			||||||
 | 
					'use strict';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// EXAMPLE:
 | 
				
			||||||
 | 
					// node bin/dns-parse.js samples/a-0.mdns.bin
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					var path = require('path');
 | 
				
			||||||
 | 
					// pass a terminal arg
 | 
				
			||||||
 | 
					var filename = process.argv[2];
 | 
				
			||||||
 | 
					var outname = process.argv[3];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					if (!filename || /(-h)|(--help)/.test(process.argv.join(' '))) {
 | 
				
			||||||
 | 
						console.error('');
 | 
				
			||||||
 | 
						console.error(
 | 
				
			||||||
 | 
							'Accepts a DNS packet (binary or json), converts it, and then converts it back to verify the function of the parser and packer'
 | 
				
			||||||
 | 
						);
 | 
				
			||||||
 | 
						console.error('');
 | 
				
			||||||
 | 
						console.error(
 | 
				
			||||||
 | 
							'Usage: node bin/dns-test.js <path/to/sample.json|.bin> <path/to/sample.bin|.json>'
 | 
				
			||||||
 | 
						);
 | 
				
			||||||
 | 
						console.error(
 | 
				
			||||||
 | 
							'Example: node bin/dns-test.js ./samples/services-0.mdns.json ./samples/services-0.mdns.bin'
 | 
				
			||||||
 | 
						);
 | 
				
			||||||
 | 
						process.exit(1);
 | 
				
			||||||
 | 
						return;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					var PromiseA = require('bluebird');
 | 
				
			||||||
 | 
					var fs = PromiseA.promisifyAll(require('fs'));
 | 
				
			||||||
 | 
					var dnsjs = require('../').DNSPacket;
 | 
				
			||||||
 | 
					var extname = path
 | 
				
			||||||
 | 
						.extname(filename)
 | 
				
			||||||
 | 
						.substr(1)
 | 
				
			||||||
 | 
						.toLowerCase();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					if ('json' !== extname && 'bin' !== extname) {
 | 
				
			||||||
 | 
						console.error(
 | 
				
			||||||
 | 
							'The file extension must end in .json or .bin (raw DNS packet)'
 | 
				
			||||||
 | 
						);
 | 
				
			||||||
 | 
						process.exit(3);
 | 
				
			||||||
 | 
						return;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					var hexdump = require('@root/hexdump');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function testJsonAsync(nb) {
 | 
				
			||||||
 | 
						var packet = dnsjs.write(JSON.parse(nb.toString('ascii')));
 | 
				
			||||||
 | 
						var str = hexdump(packet);
 | 
				
			||||||
 | 
						console.info(str);
 | 
				
			||||||
 | 
						var json = dnsjs.parse(packet);
 | 
				
			||||||
 | 
						if (json.error) {
 | 
				
			||||||
 | 
							console.error(json);
 | 
				
			||||||
 | 
							process.exit(37);
 | 
				
			||||||
 | 
							return;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						console.info('[OK] JSON -> binary -> JSON');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (!outname) {
 | 
				
			||||||
 | 
							console.warn('');
 | 
				
			||||||
 | 
							console.warn(
 | 
				
			||||||
 | 
								"Usage: node bin/dns-test.js '" +
 | 
				
			||||||
 | 
									filename +
 | 
				
			||||||
 | 
									"' './" +
 | 
				
			||||||
 | 
									path
 | 
				
			||||||
 | 
										.basename(filename)
 | 
				
			||||||
 | 
										.replace(path.extname(filename), '.bin') +
 | 
				
			||||||
 | 
									"'"
 | 
				
			||||||
 | 
							);
 | 
				
			||||||
 | 
							console.warn('');
 | 
				
			||||||
 | 
							return;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						fs.writeFileSync(outname, packet, null);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function testBinAsync(nb) {
 | 
				
			||||||
 | 
						var bin = nb.buffer.slice(nb.byteOffset, nb.byteOffset + nb.byteLength);
 | 
				
			||||||
 | 
						var json = dnsjs.parse(bin);
 | 
				
			||||||
 | 
						if (json.error) {
 | 
				
			||||||
 | 
							console.error(json);
 | 
				
			||||||
 | 
							process.exit(38);
 | 
				
			||||||
 | 
							return;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						var bin2 = dnsjs.write(json);
 | 
				
			||||||
 | 
						//var debugname = outname || path.basename(filename);
 | 
				
			||||||
 | 
						//fs.writeFileSync(debugname.replace(path.extname(debugname), '.bin'), bin2, null);
 | 
				
			||||||
 | 
						var json2 = dnsjs.parse(bin2);
 | 
				
			||||||
 | 
						if (json2.error) {
 | 
				
			||||||
 | 
							console.error(json2);
 | 
				
			||||||
 | 
							process.exit(37);
 | 
				
			||||||
 | 
							return;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						var assert = require('assert');
 | 
				
			||||||
 | 
						// EXPLANATION:
 | 
				
			||||||
 | 
						// The strategy used for compression pointers has not yet been proven
 | 
				
			||||||
 | 
						// as deterministic... and we don't implement them anyway, so this may not be the same
 | 
				
			||||||
 | 
						json = JSON.parse(
 | 
				
			||||||
 | 
							JSON.stringify(json)
 | 
				
			||||||
 | 
								.replace(/,"labels":.*?\]/, '')
 | 
				
			||||||
 | 
								.replace(/,"cpcount":\d+/, '')
 | 
				
			||||||
 | 
						);
 | 
				
			||||||
 | 
						json2 = JSON.parse(
 | 
				
			||||||
 | 
							JSON.stringify(json2)
 | 
				
			||||||
 | 
								.replace(/,"labels":.*?\]/, '')
 | 
				
			||||||
 | 
								.replace(/,"cpcount":\d+/, '')
 | 
				
			||||||
 | 
						);
 | 
				
			||||||
 | 
						//json2 = JSON.parse(JSON.stringify(json2));
 | 
				
			||||||
 | 
						try {
 | 
				
			||||||
 | 
							assert.deepEqual(json, json2);
 | 
				
			||||||
 | 
						} catch (e) {
 | 
				
			||||||
 | 
							console.error('');
 | 
				
			||||||
 | 
							console.error('Original');
 | 
				
			||||||
 | 
							console.error(JSON.stringify(json, null, 2));
 | 
				
			||||||
 | 
							console.error('');
 | 
				
			||||||
 | 
							console.error('Converted');
 | 
				
			||||||
 | 
							console.error(JSON.stringify(json2, null, 2));
 | 
				
			||||||
 | 
							console.error('');
 | 
				
			||||||
 | 
							process.exit(422);
 | 
				
			||||||
 | 
							return;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						console.info('[OK] binary -> JSON -> binary -> JSON');
 | 
				
			||||||
 | 
						console.warn(
 | 
				
			||||||
 | 
							'(compression pointer support needs to be improved in order to support direct bin -> JSON -> bin testing)'
 | 
				
			||||||
 | 
						);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (!outname) {
 | 
				
			||||||
 | 
							console.warn('');
 | 
				
			||||||
 | 
							console.warn(
 | 
				
			||||||
 | 
								"Usage: node bin/dns-test.js '" +
 | 
				
			||||||
 | 
									filename +
 | 
				
			||||||
 | 
									"' './" +
 | 
				
			||||||
 | 
									path
 | 
				
			||||||
 | 
										.basename(filename)
 | 
				
			||||||
 | 
										.replace(path.extname(filename), '.json') +
 | 
				
			||||||
 | 
									"'"
 | 
				
			||||||
 | 
							);
 | 
				
			||||||
 | 
							console.warn('');
 | 
				
			||||||
 | 
							return;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						fs.writeFileSync(outname, JSON.stringify(json, null, 2), null);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					if ('json' === extname) {
 | 
				
			||||||
 | 
						return fs.readFileAsync(filename, null).then(testJsonAsync);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					if ('bin' === extname) {
 | 
				
			||||||
 | 
						return fs.readFileAsync(filename, null).then(testBinAsync);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										8
									
								
								bin/mdns-capture.js
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							
							
						
						
									
										8
									
								
								bin/mdns-capture.js
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							@ -1,11 +1,13 @@
 | 
				
			|||||||
 | 
					#!/usr/bin/env node
 | 
				
			||||||
'use strict';
 | 
					'use strict';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// pass a terminal arg
 | 
					// pass a terminal arg
 | 
				
			||||||
var type = process.argv[2];
 | 
					var type = process.argv[2];
 | 
				
			||||||
var count = parseInt(process.argv[3]) || 0;
 | 
					var count = parseInt(process.argv[3]) || 0;
 | 
				
			||||||
if (!type) {
 | 
					if (!type) {
 | 
				
			||||||
  console.error("Usage: node aj-listener.js <type> [count]");
 | 
					  console.error("Usage: mdns-capture.js <filename-prefix> [start-number]");
 | 
				
			||||||
  console.error("Example: node aj-listener.js _service 0");
 | 
					  console.error("Example: mdns-capture.js _service 0");
 | 
				
			||||||
 | 
					  console.error("Output: _service-0.mdns.bin");
 | 
				
			||||||
  process.exit(1);
 | 
					  process.exit(1);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -41,6 +43,8 @@ handlers.onListening = function () {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  server.setBroadcast(true);
 | 
					  server.setBroadcast(true);
 | 
				
			||||||
  server.addMembership('224.0.0.251');
 | 
					  server.addMembership('224.0.0.251');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  console.log('CTRL+C to quit');
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										27
									
								
								dns.js
									
									
									
									
									
								
							
							
						
						
									
										27
									
								
								dns.js
									
									
									
									
									
								
							@ -1,17 +1,20 @@
 | 
				
			|||||||
;(function (exports) {
 | 
					;(function (exports) {
 | 
				
			||||||
'use strict';
 | 
					'use strict';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Value: IP Address
 | 
					 | 
				
			||||||
// Meaning:Use: 16 octets represting the IP address
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
var Parser = (exports.DNS_PARSER || require('./dns.parser.js').DNS_PARSER);
 | 
					var Parser = (exports.DNS_PARSER || require('./dns.parser.js').DNS_PARSER);
 | 
				
			||||||
var Packer = (exports.DNS_PACKER || require('./dns.packer.js').DNS_PACKER);
 | 
					var Packer = (exports.DNS_PACKER || require('./dns.packer.js').DNS_PACKER);
 | 
				
			||||||
var classes = exports.DNS_CLASSES || require('./dns.classes.js').DNS_CLASSES;
 | 
					//var classes = exports.DNS_CLASSES || require('./dns.classes.js').DNS_CLASSES;
 | 
				
			||||||
var types = exports.DNS_TYPES || require('./dns.types.js').DNS_TYPES;
 | 
					//var types = exports.DNS_TYPES || require('./dns.types.js').DNS_TYPES;
 | 
				
			||||||
 | 
					var logged = {};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
exports.DNSPacket = {
 | 
					exports.DNSPacket = {
 | 
				
			||||||
  parse: function (nb) {
 | 
					  parse: function (nb) {
 | 
				
			||||||
    // backwards compat with node buffer
 | 
					    // backwards compat with node buffer
 | 
				
			||||||
    var ab = nb.buffer || nb;
 | 
					    var ab = nb;
 | 
				
			||||||
 | 
					    if (nb.buffer) {
 | 
				
			||||||
 | 
					      // TODO pass byteOffsets to unpacker
 | 
				
			||||||
 | 
					      ab = nb.buffer.slice(nb.byteOffset, nb.byteOffset + nb.byteLength);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
    var packet = Parser.unpack(ab);
 | 
					    var packet = Parser.unpack(ab);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    function tryParseRdata(record) {
 | 
					    function tryParseRdata(record) {
 | 
				
			||||||
@ -20,8 +23,14 @@ exports.DNSPacket = {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        record = Parser.unpackRdata(ab, packet, record);
 | 
					        record = Parser.unpackRdata(ab, packet, record);
 | 
				
			||||||
      } catch (e) {
 | 
					      } catch (e) {
 | 
				
			||||||
        console.error('[Error] unpackRdata: ' + e.message);
 | 
					 | 
				
			||||||
        record.error = e;
 | 
					        record.error = e;
 | 
				
			||||||
 | 
					        if (!/^support for dns/i.test(e.message)) {
 | 
				
			||||||
 | 
					          console.error('[Error] unpackRdata: ' + e.message);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        else if (!logged[e.message]) {
 | 
				
			||||||
 | 
					          console.error('[Error] unpackRdata: ' + e.message);
 | 
				
			||||||
 | 
					          logged[e.message] = true;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -31,7 +40,11 @@ exports.DNSPacket = {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    return packet;
 | 
					    return packet;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					  // Backwards compat
 | 
				
			||||||
, write: function (json) {
 | 
					, write: function (json) {
 | 
				
			||||||
 | 
					    return Buffer.from(Packer.pack(json));
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					, pack: function (json) {
 | 
				
			||||||
    return Packer.pack(json);
 | 
					    return Packer.pack(json);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										13
									
								
								dns.opcodes.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								dns.opcodes.js
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,13 @@
 | 
				
			|||||||
 | 
					(function (exports) {
 | 
				
			||||||
 | 
					'use strict';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					var opcodes = exports.DNS_OPCODES = {
 | 
				
			||||||
 | 
					  QUERY:  0x00  //  0
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// and in reverse
 | 
				
			||||||
 | 
					Object.keys(opcodes).forEach(function (key) {
 | 
				
			||||||
 | 
					  opcodes[opcodes[key]] = key;
 | 
				
			||||||
 | 
					});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}('undefined' !== typeof window ? window : exports));
 | 
				
			||||||
@ -29,7 +29,7 @@ var dnspack = exports.DNS_PACKER = {
 | 
				
			|||||||
    dv.setUint16(10, (packet.additional||[]).length + (packet.payload ? 1 : 0), false);
 | 
					    dv.setUint16(10, (packet.additional||[]).length + (packet.payload ? 1 : 0), false);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    function lint(r) {
 | 
					    function lint(r) {
 | 
				
			||||||
      if (!r.name) {
 | 
					      if (!r.name && 'string' !== typeof r.name) {
 | 
				
			||||||
        throw new Error("missing name");
 | 
					        throw new Error("missing name");
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -37,6 +37,11 @@ var dnspack = exports.DNS_PACKER = {
 | 
				
			|||||||
        if (!r.className) {
 | 
					        if (!r.className) {
 | 
				
			||||||
          throw new Error("no className");
 | 
					          throw new Error("no className");
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					        if (!classes[r.className]) {
 | 
				
			||||||
 | 
					          console.warn("ignoring invalid class '" + r.className + "' for '" + r.name);
 | 
				
			||||||
 | 
					        } else {
 | 
				
			||||||
 | 
					          r.class = classes[r.className];
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      if (!r.type) {
 | 
					      if (!r.type) {
 | 
				
			||||||
@ -44,7 +49,9 @@ var dnspack = exports.DNS_PACKER = {
 | 
				
			|||||||
          throw new Error("no typeName");
 | 
					          throw new Error("no typeName");
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        if (!types[r.typeName]) {
 | 
					        if (!types[r.typeName]) {
 | 
				
			||||||
          console.warn("ignoring invalid type '" + r.type + "' for '" + r.name + "', ignoring");
 | 
					          console.warn("ignoring invalid type '" + r.typeName + "' for '" + r.name);
 | 
				
			||||||
 | 
					        } else {
 | 
				
			||||||
 | 
					          r.type = types[r.typeName];
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@ -63,7 +70,8 @@ var dnspack = exports.DNS_PACKER = {
 | 
				
			|||||||
        labelsMap[total] = { total: total, name: sequence };
 | 
					        labelsMap[total] = { total: total, name: sequence };
 | 
				
			||||||
        labelsMap[sequence] = labelsMap[total];
 | 
					        labelsMap[sequence] = labelsMap[total];
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
      sequence.split('.').forEach(function (label) {
 | 
					      // allow 0-length string for TLD root NS queries
 | 
				
			||||||
 | 
					      (sequence && sequence.split('.') || []).forEach(function (label) {
 | 
				
			||||||
        dv.setUint8(total, label.length, false);
 | 
					        dv.setUint8(total, label.length, false);
 | 
				
			||||||
        total += 1;
 | 
					        total += 1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -31,13 +31,17 @@ pdns.unpackHeader = function (i) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
pdns._unpackLabels = exports.DNS_UNPACK_LABELS || require('./dns.unpack-labels.js').DNS_UNPACK_LABELS;
 | 
					pdns._unpackLabels = exports.DNS_UNPACK_LABELS || require('./dns.unpack-labels.js').DNS_UNPACK_LABELS;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					var optWarned = false;
 | 
				
			||||||
pdns.unpackOpt = function (ab, packet, rec) {
 | 
					pdns.unpackOpt = function (ab, packet, rec) {
 | 
				
			||||||
  var dv;
 | 
					  var dv;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // https://tools.ietf.org/html/rfc6891#section-6
 | 
					  // https://tools.ietf.org/html/rfc6891#section-6
 | 
				
			||||||
  console.log('OPT is not yet supported');
 | 
					  if (!optWarned) {
 | 
				
			||||||
 | 
					    console.warn('OPT is not yet supported');
 | 
				
			||||||
 | 
					    optWarned = true;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
  if ('undefined' !== typeof packet.edns_version) {
 | 
					  if ('undefined' !== typeof packet.edns_version) {
 | 
				
			||||||
    console.warn("More that one OPT, should respond with FORMERR, but not implmentede");
 | 
					    console.warn("More that one OPT, should respond with FORMERR, but not implemented");
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  if (packet.name) {
 | 
					  if (packet.name) {
 | 
				
			||||||
    console.warn("name '" + packet.name + "' should not exist for type OPT 0x29 41");
 | 
					    console.warn("name '" + packet.name + "' should not exist for type OPT 0x29 41");
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										15
									
								
								dns.rcodes.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								dns.rcodes.js
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,15 @@
 | 
				
			|||||||
 | 
					(function (exports) {
 | 
				
			||||||
 | 
					'use strict';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					var rcodes = exports.DNS_RCODES = {
 | 
				
			||||||
 | 
					  SUCCESS:  0x00  //   0
 | 
				
			||||||
 | 
					, NXDOMAIN: 0x03  //   3
 | 
				
			||||||
 | 
					, REFUSED:  0x05  //   5
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// and in reverse
 | 
				
			||||||
 | 
					Object.keys(rcodes).forEach(function (key) {
 | 
				
			||||||
 | 
					  rcodes[rcodes[key]] = key;
 | 
				
			||||||
 | 
					});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}('undefined' !== typeof window ? window : exports));
 | 
				
			||||||
							
								
								
									
										45
									
								
								dns.types.js
									
									
									
									
									
								
							
							
						
						
									
										45
									
								
								dns.types.js
									
									
									
									
									
								
							@ -2,17 +2,50 @@
 | 
				
			|||||||
'use strict';
 | 
					'use strict';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
var types = exports.DNS_TYPES = {
 | 
					var types = exports.DNS_TYPES = {
 | 
				
			||||||
  A: 			0x01	//   1
 | 
					  A:           0x1 // 1
 | 
				
			||||||
, NS: 		0x02  //   2
 | 
					, NS:          0x2 // 2
 | 
				
			||||||
, CNAME: 	0x05  //   5
 | 
					, CNAME:       0x5 // 5
 | 
				
			||||||
, SOA: 		0x06  //   6
 | 
					, SOA:         0x6 // 6
 | 
				
			||||||
, PTR: 		0x0c  //  12
 | 
					, NULL:        0xa // 10
 | 
				
			||||||
, MX: 		0x0f  //  15
 | 
					, PTR:         0xc // 12
 | 
				
			||||||
 | 
					, HINFO:       0xd // 13
 | 
				
			||||||
 | 
					, MX:          0xf // 15
 | 
				
			||||||
, TXT:        0x10 // 16
 | 
					, TXT:        0x10 // 16
 | 
				
			||||||
 | 
					, RP:         0x11 // 17
 | 
				
			||||||
 | 
					, AFSDB:      0x12 // 18
 | 
				
			||||||
 | 
					, SIG:        0x18 // 24
 | 
				
			||||||
 | 
					, KEY:        0x19 // 25
 | 
				
			||||||
, AAAA:       0x1c // 28
 | 
					, AAAA:       0x1c // 28
 | 
				
			||||||
 | 
					, LOC:        0x1d // 29
 | 
				
			||||||
, SRV:        0x21 // 33
 | 
					, SRV:        0x21 // 33
 | 
				
			||||||
 | 
					, NAPTR:      0x23 // 35
 | 
				
			||||||
 | 
					, KX:         0x24 // 36
 | 
				
			||||||
 | 
					, CERT:       0x25 // 37
 | 
				
			||||||
 | 
					, DNAME:      0x27 // 39
 | 
				
			||||||
, OPT:        0x29 // 41
 | 
					, OPT:        0x29 // 41
 | 
				
			||||||
 | 
					, APL:        0x2a // 42
 | 
				
			||||||
 | 
					, DS:         0x2b // 43
 | 
				
			||||||
 | 
					, SSHFP:      0x2c // 44
 | 
				
			||||||
 | 
					, IPSECKEY:   0x2d // 45
 | 
				
			||||||
 | 
					, RRSIG:      0x2e // 46
 | 
				
			||||||
 | 
					, NSEC:       0x2f // 47
 | 
				
			||||||
 | 
					, DNSKEY:     0x30 // 48
 | 
				
			||||||
 | 
					, DHCID:      0x31 // 49
 | 
				
			||||||
 | 
					, NSEC3:      0x32 // 50
 | 
				
			||||||
 | 
					, NSEC3PARAM: 0x33 // 51
 | 
				
			||||||
 | 
					, TLSA:       0x34 // 52
 | 
				
			||||||
 | 
					, HIP:        0x37 // 55
 | 
				
			||||||
 | 
					, CDS:        0x3b // 59
 | 
				
			||||||
 | 
					, CDNSKEY:    0x3c // 60
 | 
				
			||||||
 | 
					, SPF:        0x63 // 99
 | 
				
			||||||
 | 
					, TKEY:       0xf9 // 249
 | 
				
			||||||
 | 
					, TSIG:       0xfa // 250
 | 
				
			||||||
 | 
					, IXFR:       0xfb // 251
 | 
				
			||||||
 | 
					, AXFR:       0xfc // 252
 | 
				
			||||||
, ANY:        0xff // 255
 | 
					, ANY:        0xff // 255
 | 
				
			||||||
 | 
					, CAA:       0x101 // 257
 | 
				
			||||||
 | 
					, TA:       0x8000 // 32768
 | 
				
			||||||
 | 
					, DLV:      0x8001 // 32769
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// and in reverse
 | 
					// and in reverse
 | 
				
			||||||
 | 
				
			|||||||
@ -9,7 +9,7 @@
 | 
				
			|||||||
//
 | 
					//
 | 
				
			||||||
// NOTE:
 | 
					// NOTE:
 | 
				
			||||||
// "NAME"s are terminated with 0x00
 | 
					// "NAME"s are terminated with 0x00
 | 
				
			||||||
// "RDATA" is terminated by its length
 | 
					// "RDATA" is terminated by its length, but its labels may null-terminated
 | 
				
			||||||
exports.DNS_UNPACK_LABELS = function (ui8, ptr, q) {
 | 
					exports.DNS_UNPACK_LABELS = function (ui8, ptr, q) {
 | 
				
			||||||
  if (q.cpcount > 25) {
 | 
					  if (q.cpcount > 25) {
 | 
				
			||||||
    throw new Error("compression pointer loop detected (over 25 pointers seems like a loop)");
 | 
					    throw new Error("compression pointer loop detected (over 25 pointers seems like a loop)");
 | 
				
			||||||
@ -26,52 +26,73 @@ exports.DNS_UNPACK_LABELS = function (ui8, ptr, q) {
 | 
				
			|||||||
    len = ui8[total];
 | 
					    len = ui8[total];
 | 
				
			||||||
    if (len === undefined){
 | 
					    if (len === undefined){
 | 
				
			||||||
      // RDATA is terminated by undefined, not len === 0
 | 
					      // RDATA is terminated by undefined, not len === 0
 | 
				
			||||||
 | 
					      q.trunc = true;
 | 
				
			||||||
      break;
 | 
					      break;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (0xc0 === len) {
 | 
					    // Handle message compression pointers. See 4.1.4 of RFC1035 for details.
 | 
				
			||||||
      var cpptr = ui8[total + 1];
 | 
					    // 0xc0 // 192 // parseInt('11000000', 2).toString(16)
 | 
				
			||||||
 | 
					    if (len >= 0xc0) {
 | 
				
			||||||
 | 
					      // Only the two highest bits are used to signify the pointer.
 | 
				
			||||||
 | 
					      // The remaining bits may be used to specify the address of the pointer
 | 
				
			||||||
 | 
					      // (it would seem that only 1 extra bit is actually used since the message size is 512 bytes)
 | 
				
			||||||
 | 
					      var cpptr = ((ui8[total] & 0x3f) << 8) |  ui8[total + 1];
 | 
				
			||||||
 | 
					      if (cpptr >= total) {
 | 
				
			||||||
 | 
					        throw new Error(
 | 
				
			||||||
 | 
					          "Compression pointer at"
 | 
				
			||||||
 | 
					        + " 0x" + total.toString() + " (" + total + ")"
 | 
				
			||||||
 | 
					        + " points forward to"
 | 
				
			||||||
 | 
					        + " 0x" + cpptr.toString(16) + " (" + cpptr + ")"
 | 
				
			||||||
 | 
					        );
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      // we're not coming back!
 | 
					      // We're not coming back, so if this is the first time we're following one of
 | 
				
			||||||
      ptr = cpptr;
 | 
					      // these pointers we up the byteLength to mark the pointer as part of the label
 | 
				
			||||||
      if (!q.cpcount) {
 | 
					      if (!q.cpcount) {
 | 
				
			||||||
        q.byteLength += 2; // cp and len
 | 
					        q.byteLength += 2; // cp and len
 | 
				
			||||||
 | 
					        //q.cps = [];
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
      q.cpcount += 1;
 | 
					      q.cpcount += 1;
 | 
				
			||||||
 | 
					      //q.cps.push(cpptr);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      // recursion
 | 
					      // recursion
 | 
				
			||||||
      return exports.DNS_UNPACK_LABELS(ui8, ptr, q);
 | 
					      return exports.DNS_UNPACK_LABELS(ui8, cpptr, q);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    //str.length = 0; // fast empty array
 | 
					    //str.length = 0; // fast empty array
 | 
				
			||||||
    if (ui8.byteLength - total < len) {
 | 
					    if (ui8.byteLength - total < len) {
 | 
				
			||||||
 | 
					      //console.error('-1', ui8[total - 1]);
 | 
				
			||||||
 | 
					      //console.error(' 0', ui8[total]);
 | 
				
			||||||
 | 
					      //console.error(' 1', ui8[total + 1]);
 | 
				
			||||||
 | 
					      //console.error(' 1', ui8[total + 2]);
 | 
				
			||||||
      throw new Error(
 | 
					      throw new Error(
 | 
				
			||||||
        "Expected a string of length " + len
 | 
					        "Expected a string of length " + len
 | 
				
			||||||
          + " but packet itself has " + (ui8.byteLength - total) + " bytes remaining"
 | 
					          + " but packet itself has " + (ui8.byteLength - total) + " bytes remaining"
 | 
				
			||||||
      );
 | 
					      );
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    for (i = 0; i < len; i += 1) {
 | 
					    // Advance the pointer to after the length indicator, then read the string in.
 | 
				
			||||||
    total += 1;
 | 
					    total += 1;
 | 
				
			||||||
 | 
					    for (i = 0; i < len; i += 1) {
 | 
				
			||||||
      // TODO check url-allowable characters
 | 
					      // TODO check url-allowable characters
 | 
				
			||||||
      label.push(String.fromCharCode(ui8[total]));
 | 
					      label.push(String.fromCharCode(ui8[total]));
 | 
				
			||||||
 | 
					      total += 1;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (label.length) {
 | 
					    if (label.length) {
 | 
				
			||||||
      q.labels.push(label.join(''));
 | 
					      q.labels.push(label.join(''));
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    total += 1;
 | 
					    // It is important this be done every time, so that if we run into a message compression
 | 
				
			||||||
 | 
					    // pointer later we still have a record of what was consumed before that.
 | 
				
			||||||
 | 
					    if (0 === q.cpcount) {
 | 
				
			||||||
 | 
					      q.byteLength = total - ptr;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
  } while (0 !== len && undefined !== len);
 | 
					  } while (0 !== len && undefined !== len);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  //str.pop(); // remove trailing '.'
 | 
					  //str.pop(); // remove trailing '.'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  q.name = q.labels.join('.');
 | 
					  q.name = q.labels.join('.');
 | 
				
			||||||
  if (0 === q.cpcount) {
 | 
					 | 
				
			||||||
    q.byteLength = total - ptr;
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  return q;
 | 
					  return q;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -1,23 +1,57 @@
 | 
				
			|||||||
'use strict';
 | 
					'use strict';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
module.exports.respond = function (socket, packets, rinfo) {
 | 
					module.exports.respond = function (socket, packets, rinfo) {
 | 
				
			||||||
  var dns = require('dns-js');
 | 
					  var dns = require('../');
 | 
				
			||||||
  var os = require('os');
 | 
					  var os = require('os');
 | 
				
			||||||
  var queryname = '_cloud._tcp.local';
 | 
					  var queryname = '_cloud._tcp.local';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  console.log(packets);
 | 
					  console.log(packets);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  packets.forEach(function (packet) {
 | 
					  packets.forEach(function (packet) {
 | 
				
			||||||
 | 
					    // Only respond to queries, otherwise we'll end up responding to ourselves forever.
 | 
				
			||||||
 | 
					    if (packet.header.qr !== 0) {
 | 
				
			||||||
 | 
					      return;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    packet.question.forEach(function (q) {
 | 
					    packet.question.forEach(function (q) {
 | 
				
			||||||
      if (queryname !== q.name) {
 | 
					      if (queryname !== q.name) {
 | 
				
			||||||
        return;
 | 
					        return;
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      console.log('question', q.name, q.typeName, q.className, q.flag, q);
 | 
					      console.log('question', q.name, q.typeName, q.className, q.flag, q);
 | 
				
			||||||
      var rpacket = new dns.DNSPacket();
 | 
					      var rpacket = {
 | 
				
			||||||
 | 
					        header: {
 | 
				
			||||||
 | 
					          id: packet.header.id
 | 
				
			||||||
 | 
					        , qr: 1
 | 
				
			||||||
 | 
					        , opcode: 0
 | 
				
			||||||
 | 
					        , aa: 1
 | 
				
			||||||
 | 
					        , tc: 0
 | 
				
			||||||
 | 
					        , rd: 0
 | 
				
			||||||
 | 
					        , ra: 0
 | 
				
			||||||
 | 
					        , res1:  0
 | 
				
			||||||
 | 
					        , res2:  0
 | 
				
			||||||
 | 
					        , res3:  0
 | 
				
			||||||
 | 
					        , rcode: 0
 | 
				
			||||||
 | 
					      , }
 | 
				
			||||||
 | 
					      , question: [q]
 | 
				
			||||||
 | 
					      , answer: []
 | 
				
			||||||
 | 
					      , authority: []
 | 
				
			||||||
 | 
					      , additional: []
 | 
				
			||||||
 | 
					      , edns_options: []
 | 
				
			||||||
 | 
					      };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      var myRndId = 'be1af7a';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      rpacket.answer.push({
 | 
				
			||||||
 | 
					        name: q.name
 | 
				
			||||||
 | 
					      , typeName: 'PTR'
 | 
				
			||||||
 | 
					      , ttl: 10
 | 
				
			||||||
 | 
					      , className: 'IN'
 | 
				
			||||||
 | 
					      , data: myRndId + '.' + queryname
 | 
				
			||||||
 | 
					      });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      var ifaces = os.networkInterfaces();
 | 
					      var ifaces = os.networkInterfaces();
 | 
				
			||||||
      //var llRe = /^(fe80|169)/i; // link-local
 | 
					      //var llRe = /^(fe80|169)/i; // link-local
 | 
				
			||||||
 | 
					 | 
				
			||||||
      Object.keys(ifaces).forEach(function (iname) {
 | 
					      Object.keys(ifaces).forEach(function (iname) {
 | 
				
			||||||
        var iface = ifaces[iname];
 | 
					        var iface = ifaces[iname];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -28,55 +62,37 @@ module.exports.respond = function (socket, packets, rinfo) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        iface.forEach(function (pface) {
 | 
					        iface.forEach(function (pface) {
 | 
				
			||||||
          rpacket.additional.push({
 | 
					          rpacket.additional.push({
 | 
				
			||||||
            name: q.name
 | 
					            name: myRndId + '.' + q.name
 | 
				
			||||||
          , type: ('IPv4' === pface.family ? dns.DNSRecord.Type.A : dns.DNSRecord.Type.AAAA)
 | 
					          , typeName: ('IPv4' === pface.family ? 'A' : 'AAAA')
 | 
				
			||||||
          , ttl: 10
 | 
					          , ttl: 10
 | 
				
			||||||
          , class: dns.DNSRecord.Class.IN
 | 
					          , className: 'IN'
 | 
				
			||||||
          , address: pface.address // '_workstation._tcp.local'
 | 
					          , address: pface.address // '_workstation._tcp.local'
 | 
				
			||||||
          });
 | 
					          });
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
      });
 | 
					      });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      var myRndId = 'be1af7a';
 | 
					 | 
				
			||||||
      rpacket.answer.push({
 | 
					 | 
				
			||||||
        name: q.name
 | 
					 | 
				
			||||||
      , type: dns.DNSRecord.Type.PTR
 | 
					 | 
				
			||||||
      , ttl: 10
 | 
					 | 
				
			||||||
      , class: dns.DNSRecord.Class.IN
 | 
					 | 
				
			||||||
      , data: myRndId + '.' + queryname
 | 
					 | 
				
			||||||
      });
 | 
					 | 
				
			||||||
      rpacket.question.push(new dns.DNSRecord(
 | 
					 | 
				
			||||||
        queryname                           // Name
 | 
					 | 
				
			||||||
      , dns.DNSRecord.Type.PTR              // Type
 | 
					 | 
				
			||||||
      , dns.DNSRecord.Class.IN              // Class
 | 
					 | 
				
			||||||
      //, null                                // TTL
 | 
					 | 
				
			||||||
      ));
 | 
					 | 
				
			||||||
      rpacket.additional.push({
 | 
					      rpacket.additional.push({
 | 
				
			||||||
        name: myRndId + '.' + queryname
 | 
					        name: myRndId + '.' + queryname
 | 
				
			||||||
      , type: dns.DNSRecord.Type.SRV
 | 
					      , typeName: 'SRV'
 | 
				
			||||||
      , ttl: 10
 | 
					      , ttl: 10
 | 
				
			||||||
      , class: dns.DNSRecord.Class.IN
 | 
					      , className: 'IN'
 | 
				
			||||||
      , priority: 0
 | 
					      , priority: 1
 | 
				
			||||||
      , weight: 0
 | 
					      , weight: 0
 | 
				
			||||||
      , port: 443
 | 
					      , port: 443
 | 
				
			||||||
      , target: myRndId + ".local"
 | 
					      , target: myRndId + ".local"
 | 
				
			||||||
      });
 | 
					      });
 | 
				
			||||||
      rpacket.additional.push({
 | 
					      rpacket.additional.push({
 | 
				
			||||||
        name: myRndId + '.' + '_device-info._tcp.local'
 | 
					        name: myRndId + '.' + '_device-info._tcp.local'
 | 
				
			||||||
      , type: dns.DNSRecord.Type.TXT
 | 
					      , typeName: 'TXT'
 | 
				
			||||||
      , ttl: 10
 | 
					      , ttl: 10
 | 
				
			||||||
      , class: dns.DNSRecord.Class.IN
 | 
					      , className: 'IN'
 | 
				
			||||||
      , data: ["model=CloudHome1,1", "dappsvers=1"]
 | 
					      , data: ["model=CloudHome1,1", "dappsvers=1"]
 | 
				
			||||||
      });
 | 
					      });
 | 
				
			||||||
      rpacket.header.id = packet.header.id;
 | 
					 | 
				
			||||||
      rpacket.header.aa = 1;
 | 
					 | 
				
			||||||
      rpacket.header.qr = 1;
 | 
					 | 
				
			||||||
      rpacket.header.rd = 0;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
      console.log('');
 | 
					      console.log('');
 | 
				
			||||||
      console.log('START JSON PACKET');
 | 
					      console.log('START JSON PACKET');
 | 
				
			||||||
      console.log(rpacket);
 | 
					      console.log(rpacket);
 | 
				
			||||||
      var buf = dns.DNSPacket.toBuffer(rpacket);
 | 
					      var buf = dns.DNSPacket.write(rpacket);
 | 
				
			||||||
      console.log(buf.toString('hex'));
 | 
					      console.log(buf.toString('hex'));
 | 
				
			||||||
      console.log('END JSON PACKET');
 | 
					      console.log('END JSON PACKET');
 | 
				
			||||||
      console.log('');
 | 
					      console.log('');
 | 
				
			||||||
@ -89,8 +105,7 @@ module.exports.respond = function (socket, packets, rinfo) {
 | 
				
			|||||||
      console.log('');
 | 
					      console.log('');
 | 
				
			||||||
      socket.send(buf, rinfo.port, rinfo.address);
 | 
					      socket.send(buf, rinfo.port, rinfo.address);
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
    /*
 | 
					
 | 
				
			||||||
    */
 | 
					 | 
				
			||||||
    packet.answer.forEach(function (a) {
 | 
					    packet.answer.forEach(function (a) {
 | 
				
			||||||
      console.log('answer', a.name, a.typeName, a.className, a.flag, a);
 | 
					      console.log('answer', a.name, a.typeName, a.className, a.flag, a);
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										27
									
								
								examples/dns-pack.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								examples/dns-pack.js
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,27 @@
 | 
				
			|||||||
 | 
					'use strict';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					var DNSPacket = require('../').DNSPacket;
 | 
				
			||||||
 | 
					var rnd = Math.floor(Math.random() * 65536);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					var query = {
 | 
				
			||||||
 | 
						header: {
 | 
				
			||||||
 | 
							id: rnd,
 | 
				
			||||||
 | 
							qr: 0,
 | 
				
			||||||
 | 
							opcode: 0,
 | 
				
			||||||
 | 
							aa: 0,
 | 
				
			||||||
 | 
							rd: 1,
 | 
				
			||||||
 | 
							ra: 0,
 | 
				
			||||||
 | 
							rcode: 0
 | 
				
			||||||
 | 
						},
 | 
				
			||||||
 | 
						question: [
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								name: 'google.com',
 | 
				
			||||||
 | 
								typeName: 'A',
 | 
				
			||||||
 | 
								className: 'IN'
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						]
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					var buffer = DNSPacket.pack(query);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					console.info(Buffer.from(buffer));
 | 
				
			||||||
@ -1,7 +1,6 @@
 | 
				
			|||||||
'use strict';
 | 
					'use strict';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
var dgram = require('dgram');
 | 
					var dgram = require('dgram');
 | 
				
			||||||
var dnsjs = require('dns-js');
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
// SO_REUSEADDR and SO_REUSEPORT are set because
 | 
					// SO_REUSEADDR and SO_REUSEPORT are set because
 | 
				
			||||||
// the system mDNS Responder may already be listening on this port
 | 
					// the system mDNS Responder may already be listening on this port
 | 
				
			||||||
 | 
				
			|||||||
@ -5,7 +5,7 @@ var socket = dgram.createSocket({
 | 
				
			|||||||
  type: 'udp4'
 | 
					  type: 'udp4'
 | 
				
			||||||
, reuseAddr: true
 | 
					, reuseAddr: true
 | 
				
			||||||
});
 | 
					});
 | 
				
			||||||
var dns = require('dns-js');
 | 
					var dns = require('../');
 | 
				
			||||||
//var DNSPacket = dns.DNSPacket;
 | 
					//var DNSPacket = dns.DNSPacket;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
var broadcast = '224.0.0.251'; // mdns
 | 
					var broadcast = '224.0.0.251'; // mdns
 | 
				
			||||||
@ -31,14 +31,11 @@ return binString;
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
socket.on('message', function (message, rinfo) {
 | 
					socket.on('message', function (message, rinfo) {
 | 
				
			||||||
  console.log('Received %d bytes from %s:%d\n',
 | 
					  console.log('Received %d bytes from %s:%d', message.length, rinfo.address, rinfo.port);
 | 
				
			||||||
    message.length, rinfo.address, rinfo.port);
 | 
					 | 
				
			||||||
  //console.log(msg.toString('utf8'));
 | 
					  //console.log(msg.toString('utf8'));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  message.forEach(function(byte){
 | 
					  message.forEach(function(byte){
 | 
				
			||||||
 | 
					 | 
				
			||||||
    console.log(pad(byte.toString(2), 8, '0'));
 | 
					    console.log(pad(byte.toString(2), 8, '0'));
 | 
				
			||||||
 | 
					 | 
				
			||||||
  });
 | 
					  });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										114
									
								
								examples/test-output
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										114
									
								
								examples/test-output
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,114 @@
 | 
				
			|||||||
 | 
					I created a subdomain for `daplie.pe` named `delegated.daplie.pe`.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Below are the results of the `whois`, `dig`, and `dig.js` commands.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					============================
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Users-MBP:~ jim$ whois daplie.pe
 | 
				
			||||||
 | 
					Domain Name: daplie.pe
 | 
				
			||||||
 | 
					WHOIS Server: NIC .PE
 | 
				
			||||||
 | 
					Sponsoring Registrar: 1API GmbH
 | 
				
			||||||
 | 
					Domain Status: clientTransferProhibited
 | 
				
			||||||
 | 
					Domain Status: clientUpdateProhibited
 | 
				
			||||||
 | 
					Domain Status: clientDeleteProhibited
 | 
				
			||||||
 | 
					Domain Status: clientRenewProhibited
 | 
				
			||||||
 | 
					Registrant Name: Daplie Labs
 | 
				
			||||||
 | 
					Admin Name: Daplie Labs
 | 
				
			||||||
 | 
					Admin Email: domains@daplie.com
 | 
				
			||||||
 | 
					Name Server: ns27.domaincontrol.com
 | 
				
			||||||
 | 
					Name Server: ns28.domaincontrol.com
 | 
				
			||||||
 | 
					DNSSEC: unsigned
 | 
				
			||||||
 | 
					>>> Last update of WHOIS database: 2017-08-15T19:49:36.243Z <<<
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					================================
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Users-MBP:~ jim$ dig delegated.daplie.pe @ns27.domaincontrol.com
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					; <<>> DiG 9.8.3-P1 <<>> delegated.daplie.pe @ns27.domaincontrol.com
 | 
				
			||||||
 | 
					;; global options: +cmd
 | 
				
			||||||
 | 
					;; Got answer:
 | 
				
			||||||
 | 
					;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 37275
 | 
				
			||||||
 | 
					;; flags: qr aa rd; QUERY: 1, ANSWER: 1, AUTHORITY: 2, ADDITIONAL: 0
 | 
				
			||||||
 | 
					;; WARNING: recursion requested but not available
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					;; QUESTION SECTION:
 | 
				
			||||||
 | 
					;delegated.daplie.pe.		IN	A
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					;; ANSWER SECTION:
 | 
				
			||||||
 | 
					delegated.daplie.pe.	600	IN	A	50.63.202.28
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					;; AUTHORITY SECTION:
 | 
				
			||||||
 | 
					daplie.pe.		3600	IN	NS	ns28.domaincontrol.com.
 | 
				
			||||||
 | 
					daplie.pe.		3600	IN	NS	ns27.domaincontrol.com.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					;; Query time: 29 msec
 | 
				
			||||||
 | 
					;; SERVER: 216.69.185.14#53(216.69.185.14)
 | 
				
			||||||
 | 
					;; WHEN: Tue Aug 15 13:54:23 2017
 | 
				
			||||||
 | 
					;; MSG SIZE  rcvd: 108
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					===================================
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Finding JSON information through dig -- used website `dig.jsondns.org` with the query format (URL) 
 | 
				
			||||||
 | 
					`dig.jsondns.org/IN/delegated.daplie.pe/A` :
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  "header": {
 | 
				
			||||||
 | 
					    "id": 59404,
 | 
				
			||||||
 | 
					    "qr": true,
 | 
				
			||||||
 | 
					    "opcode": "Query",
 | 
				
			||||||
 | 
					    "aa": false,
 | 
				
			||||||
 | 
					    "ad": false,
 | 
				
			||||||
 | 
					    "tc": false,
 | 
				
			||||||
 | 
					    "rd": true,
 | 
				
			||||||
 | 
					    "ra": true,
 | 
				
			||||||
 | 
					    "cd": true,
 | 
				
			||||||
 | 
					    "rcode": "NOERROR",
 | 
				
			||||||
 | 
					    "qdcount": 1,
 | 
				
			||||||
 | 
					    "nscount": 0,
 | 
				
			||||||
 | 
					    "ancount": 1,
 | 
				
			||||||
 | 
					    "arcount": 0
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  "question": [
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					      "qname": "delegated.daplie.pe",
 | 
				
			||||||
 | 
					      "qtype": "A",
 | 
				
			||||||
 | 
					      "qclass": "IN"
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  ],
 | 
				
			||||||
 | 
					  "answer": [
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					      "name": "delegated.daplie.pe",
 | 
				
			||||||
 | 
					      "type": "A",
 | 
				
			||||||
 | 
					      "class": "IN",
 | 
				
			||||||
 | 
					      "ttl": 600,
 | 
				
			||||||
 | 
					      "rdata": "184.168.221.5"
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  ],
 | 
				
			||||||
 | 
					  "authority": [
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  ],
 | 
				
			||||||
 | 
					  "additional": [
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  ]
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					==================================================
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Output from `dig.js delegated.daplie.pe`:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Users-MBP:dig.js jim$ dig.js delegated.daplie.pe
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					; <<>> dig.js v0.0.0 <<>> delegated.daplie.pe
 | 
				
			||||||
 | 
					;; Got answer:
 | 
				
			||||||
 | 
					;; ->>HEADER<<-
 | 
				
			||||||
 | 
					{"id":24943,"qr":1,"opcode":0,"aa":0,"tc":0,"rd":1,"ra":1,"res1":0,"res2":0,"res3":0,"rcode":0}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					;; QUESTION SECTION:
 | 
				
			||||||
 | 
					;delegated.daplie.pe.   IN ANY
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					;; ANSWER SECTION:
 | 
				
			||||||
 | 
					;delegated.daplie.pe. 599 IN A 50.63.202.18
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					;; MSG SIZE  rcvd: 53
 | 
				
			||||||
							
								
								
									
										13
									
								
								package-lock.json
									
									
									
										generated
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								package-lock.json
									
									
									
										generated
									
									
									
										Normal file
									
								
							@ -0,0 +1,13 @@
 | 
				
			|||||||
 | 
					{
 | 
				
			||||||
 | 
						"name": "dns-suite",
 | 
				
			||||||
 | 
						"version": "1.2.13",
 | 
				
			||||||
 | 
						"lockfileVersion": 1,
 | 
				
			||||||
 | 
						"requires": true,
 | 
				
			||||||
 | 
						"dependencies": {
 | 
				
			||||||
 | 
							"@root/hexdump": {
 | 
				
			||||||
 | 
								"version": "1.1.1",
 | 
				
			||||||
 | 
								"resolved": "https://registry.npmjs.org/@root/hexdump/-/hexdump-1.1.1.tgz",
 | 
				
			||||||
 | 
								"integrity": "sha512-AmrmLOutlzctR599ittO06lINOco1TIqb0c1wu83fP2Eoi5iSvx7kVWC4mDufze8rxPewC+aQOx4e6Pw7izV4A=="
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										18
									
								
								package.json
									
									
									
									
									
								
							
							
						
						
									
										18
									
								
								package.json
									
									
									
									
									
								
							@ -1,15 +1,25 @@
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
	"name": "dns-suite",
 | 
						"name": "dns-suite",
 | 
				
			||||||
  "version": "1.0.0",
 | 
						"version": "1.2.13",
 | 
				
			||||||
  "description": "testing dns",
 | 
						"description": "DNS implemented in Vanilla JS for Node.js and Browsers",
 | 
				
			||||||
	"main": "dns.js",
 | 
						"main": "dns.js",
 | 
				
			||||||
 | 
						"homepage": "https://git.coolaj86.com/coolaj86/dns-suite.js",
 | 
				
			||||||
 | 
						"bin": {
 | 
				
			||||||
 | 
							"dns-pack.js": "bin/dns-pack.js",
 | 
				
			||||||
 | 
							"dns-parse.js": "bin/dns-parse.js",
 | 
				
			||||||
 | 
							"dns-test.js": "bin/dns-test.js",
 | 
				
			||||||
 | 
							"mdns-capture.js": "bin/mdns-capture.js"
 | 
				
			||||||
 | 
						},
 | 
				
			||||||
	"scripts": {
 | 
						"scripts": {
 | 
				
			||||||
		"test": "node test/parser.js && node test/packer.js"
 | 
							"test": "node test/parser.js && node test/packer.js"
 | 
				
			||||||
	},
 | 
						},
 | 
				
			||||||
	"repository": {
 | 
						"repository": {
 | 
				
			||||||
		"type": "git",
 | 
							"type": "git",
 | 
				
			||||||
    "url": "git@git.daplie.com:Daplie/dns-suite.git"
 | 
							"url": "https://git.coolaj86.com:coolaj86/dns-suite.js.git"
 | 
				
			||||||
	},
 | 
						},
 | 
				
			||||||
	"author": "",
 | 
						"author": "",
 | 
				
			||||||
  "license": "(MIT or Apache2)"
 | 
						"license": "MPL-2.0",
 | 
				
			||||||
 | 
						"dependencies": {
 | 
				
			||||||
 | 
							"@root/hexdump": "^1.1.1"
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										69
									
								
								packer/type.caa.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										69
									
								
								packer/type.caa.js
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,69 @@
 | 
				
			|||||||
 | 
					(function (exports) {
 | 
				
			||||||
 | 
					'use strict';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// RFC 6844
 | 
				
			||||||
 | 
					// Explanation: https://tools.ietf.org/html/rfc6844#section-3
 | 
				
			||||||
 | 
					// Binary Format: https://tools.ietf.org/html/rfc6844#section-5
 | 
				
			||||||
 | 
					// Real-world Usage: https://support.dnsimple.com/articles/caa-record/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// A Certification Authority Authorization (CAA) record is used to specify which
 | 
				
			||||||
 | 
					// certificate authorities (CAs) are allowed to issue certificates for a domain.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Value    Meaning/Use
 | 
				
			||||||
 | 
					//
 | 
				
			||||||
 | 
					// Flag     An unsigned integer between 0-255.
 | 
				
			||||||
 | 
					//          It is currently used to represent the critical flag, that has a
 | 
				
			||||||
 | 
					//          specific meaning per RFC 6844
 | 
				
			||||||
 | 
					// Tag      An ASCII string that represents the identifier of the property
 | 
				
			||||||
 | 
					//          represented by the record.
 | 
				
			||||||
 | 
					// Value    The value associated with the tag.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// The RFC currently defines 3 available tags:
 | 
				
			||||||
 | 
					//
 | 
				
			||||||
 | 
					// - issue:     explicity authorizes a single certificate authority to issue a
 | 
				
			||||||
 | 
					//              certificate (any type) for the hostname.
 | 
				
			||||||
 | 
					// - issuewild: explicity authorizes a single certificate authority to issue a
 | 
				
			||||||
 | 
					//              wildcard certificate (and only wildcard) for the hostname.
 | 
				
			||||||
 | 
					// - iodef:     specifies an URL to which a certificate authority may report
 | 
				
			||||||
 | 
					//              policy violations.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					exports.DNS_PACKER_TYPE_CAA = function (ab, dv, total, record) {
 | 
				
			||||||
 | 
					  if ('number' !== typeof record.flag || isNaN(record.flag) || record.flag < 0 || record.flag > 255) {
 | 
				
			||||||
 | 
					    console.log(record);
 | 
				
			||||||
 | 
					    throw new Error("bad CAA flag:", record.flag);
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  if ('string' !== typeof record.tag || !record.tag || record.tag.length > 255) {
 | 
				
			||||||
 | 
					    throw new Error("bad CAA tag:", record.tag);
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  if ('string' !== typeof record.value || !record.value) {
 | 
				
			||||||
 | 
					    throw new Error("bad CAA value:", record.value);
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // RDLEN = flag (1 byte) + taglen (1 byte) + tagstr (taglen bytes) + valuestr (valuelen bytes)
 | 
				
			||||||
 | 
					  dv.setUint16(total, 1 + 1 + record.tag.length + record.value.length, false);
 | 
				
			||||||
 | 
					  total += 2;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // FLAG
 | 
				
			||||||
 | 
					  dv.setUint8(total, record.flag, false);
 | 
				
			||||||
 | 
					  total += 1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // TAG LENGTH
 | 
				
			||||||
 | 
					  dv.setUint8(total, record.tag.length, false);
 | 
				
			||||||
 | 
					  total += 1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // TAG
 | 
				
			||||||
 | 
					  record.tag.split('').forEach(function (ch) {
 | 
				
			||||||
 | 
					    dv.setUint8(total, ch.charCodeAt(0), false);
 | 
				
			||||||
 | 
					    total += 1;
 | 
				
			||||||
 | 
					  });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // VALUE
 | 
				
			||||||
 | 
					  record.value.split('').forEach(function (ch) {
 | 
				
			||||||
 | 
					    dv.setUint8(total, ch.charCodeAt(0), false);
 | 
				
			||||||
 | 
					    total += 1;
 | 
				
			||||||
 | 
					  });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  return total;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}('undefined' !== typeof window ? window : exports));
 | 
				
			||||||
@ -25,9 +25,11 @@ exports.DNS_PACKER_TYPE_CNAME = function (ab, dv, total, record) {
 | 
				
			|||||||
      total += 1;
 | 
					      total += 1;
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
  });
 | 
					  });
 | 
				
			||||||
 | 
					  dv.setUint8(total, 0x00, false);
 | 
				
			||||||
 | 
					  total += 1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // RDLENGTH
 | 
					  // RDLENGTH
 | 
				
			||||||
  dv.setUint16(rdLenIndex, record.data.length + 1, false);
 | 
					  dv.setUint16(rdLenIndex, record.data.length + 2, false);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  return total;
 | 
					  return total;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
				
			|||||||
@ -31,6 +31,9 @@ exports.DNS_PACKER_TYPE_MX = function (ab, dv, total, record) {
 | 
				
			|||||||
      total += 1;
 | 
					      total += 1;
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
  });
 | 
					  });
 | 
				
			||||||
 | 
					  dv.setUint8(total, 0x00, false);
 | 
				
			||||||
 | 
					  total += 1;
 | 
				
			||||||
 | 
					  mxLen += 1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // RDLENGTH
 | 
					  // RDLENGTH
 | 
				
			||||||
  dv.setUint16(rdLenIndex, mxLen, false);
 | 
					  dv.setUint16(rdLenIndex, mxLen, false);
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										36
									
								
								packer/type.ns.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										36
									
								
								packer/type.ns.js
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,36 @@
 | 
				
			|||||||
 | 
					// NOTE: this should be EXACTLY the same as PTR
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					(function (exports) {
 | 
				
			||||||
 | 
					'use strict';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// NS name for the supplied domain. May be label, pointer or any combination
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					exports.DNS_PACKER_TYPE_NS = function (ab, dv, total, record) {
 | 
				
			||||||
 | 
					  if (!record.data) {
 | 
				
			||||||
 | 
					      throw new Error("no data on NS record");
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // RDLENGTH
 | 
				
			||||||
 | 
					  // leading len and length of string and trailing null (all dots become lengths)
 | 
				
			||||||
 | 
					  dv.setUint16(total, record.data.length + 2, false);
 | 
				
			||||||
 | 
					  total += 2;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // RDATA
 | 
				
			||||||
 | 
					  // a sequence of labels
 | 
				
			||||||
 | 
					  record.data.split('.').forEach(function (label) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      dv.setUint8(total, label.length, false);
 | 
				
			||||||
 | 
					      total += 1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      label.split('').forEach(function (ch) {
 | 
				
			||||||
 | 
					          dv.setUint8(total, ch.charCodeAt(0), false);
 | 
				
			||||||
 | 
					          total += 1;
 | 
				
			||||||
 | 
					      });
 | 
				
			||||||
 | 
					  });
 | 
				
			||||||
 | 
					  dv.setUint8(total, 0x00, false);
 | 
				
			||||||
 | 
					  total += 1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  return total;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}('undefined' !== typeof window ? window : exports));
 | 
				
			||||||
							
								
								
									
										37
									
								
								packer/type.ptr.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										37
									
								
								packer/type.ptr.js
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,37 @@
 | 
				
			|||||||
 | 
					// NOTE: this should be EXACTLY the same as NS
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					(function (exports) {
 | 
				
			||||||
 | 
					'use strict';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// The host name that represents the supplied UP address
 | 
				
			||||||
 | 
					// May be a label, pointer or any combination
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					exports.DNS_PACKER_TYPE_PTR = function (ab, dv, total, record) {
 | 
				
			||||||
 | 
					  if (!record.data) {
 | 
				
			||||||
 | 
					    throw new Error("no data for PTR record");
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // RDLENGTH
 | 
				
			||||||
 | 
					  // leading len and length of string and trailing null (all dots become lengths)
 | 
				
			||||||
 | 
					  dv.setUint16(total, record.data.length + 2, false);
 | 
				
			||||||
 | 
					  total += 2;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // RDATA
 | 
				
			||||||
 | 
					  // a sequence of labels
 | 
				
			||||||
 | 
					  record.data.split('.').forEach(function (label) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      dv.setUint8(total, label.length, false);
 | 
				
			||||||
 | 
					      total += 1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      label.split('').forEach(function (ch) {
 | 
				
			||||||
 | 
					          dv.setUint8(total, ch.charCodeAt(0), false);
 | 
				
			||||||
 | 
					          total += 1;
 | 
				
			||||||
 | 
					      });
 | 
				
			||||||
 | 
					  });
 | 
				
			||||||
 | 
					  dv.setUint8(total, 0x00, false);
 | 
				
			||||||
 | 
					  total += 1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  return total;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}('undefined' !== typeof window ? window : exports));
 | 
				
			||||||
							
								
								
									
										104
									
								
								packer/type.soa.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										104
									
								
								packer/type.soa.js
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,104 @@
 | 
				
			|||||||
 | 
					(function (exports) {
 | 
				
			||||||
 | 
					'use strict';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// http://www.zytrax.com/books/dns/ch8/soa.html
 | 
				
			||||||
 | 
					// https://github.com/tjfontaine/node-dns#resourcerecord
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Value              Meaning/Use
 | 
				
			||||||
 | 
					// Primary NS         Variable length. The name of the Primary Master for the domain. May be a label, pointer, or any combination
 | 
				
			||||||
 | 
					// Admin MB           Variable length. The administrator's mailbox. May be a label, pointer, or any combination
 | 
				
			||||||
 | 
					// Serial Number      Unsigned 32-bit integer
 | 
				
			||||||
 | 
					// Refresh Interval   Unsigned 32-bit integer
 | 
				
			||||||
 | 
					// Retry Interval     Unsigned 32-bit integer
 | 
				
			||||||
 | 
					// Expiration Limit   Unsigned 32-bit integer
 | 
				
			||||||
 | 
					// Minimum TTL        Unsigned 32-bit integer
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					exports.DNS_PACKER_TYPE_SOA = function (ab, dv, total, record) {
 | 
				
			||||||
 | 
					  function notNumber(n) {
 | 
				
			||||||
 | 
					    return 'number' !== typeof n || isNaN(n);
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  if (!record.primary && !record.name_server) {
 | 
				
			||||||
 | 
					    throw new Error("no name server for SOA record");
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  if (!record.admin && !record.email_addr) {
 | 
				
			||||||
 | 
					    throw new Error("ne email address for SOA record");
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  if (notNumber(record.serial) && notNumber(record.sn)) {
 | 
				
			||||||
 | 
					    throw new Error("no serial number for SOA record");
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  if (notNumber(record.refresh) && notNumber(record.ref)) {
 | 
				
			||||||
 | 
					    throw new Error("no refresh for SOA record");
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  if (notNumber(record.retry) && notNumber(record.ret)) {
 | 
				
			||||||
 | 
					    throw new Error("no update retry for SOA record");
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  if (notNumber(record.expiration) && notNumber(record.ex)) {
 | 
				
			||||||
 | 
					    throw new Error("no expiry for SOA record");
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  if (notNumber(record.minimum) && notNumber(record.nx)) {
 | 
				
			||||||
 | 
					    throw new Error("no nxdomain for SOA record");
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  var soaLen = 20; // take into account sn, ref, ret, ex, and nx
 | 
				
			||||||
 | 
					                  //  (32-bits each. 4Bytes * 5 = 20)
 | 
				
			||||||
 | 
					  var rdLenIndex = total;
 | 
				
			||||||
 | 
					  total += 2; // Save space for RDLENGTH
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  //console.log('record.name_server', 1 + record.name_server.length, record.name_server);
 | 
				
			||||||
 | 
					  // pack name_server which is a sequence of labels
 | 
				
			||||||
 | 
					  (record.primary || record.name_server).split('.').forEach(function (label) {
 | 
				
			||||||
 | 
					    soaLen += (1 + label.length);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    dv.setUint8(total, label.length, false);
 | 
				
			||||||
 | 
					    total += 1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    label.split('').forEach(function(ch) {
 | 
				
			||||||
 | 
					      dv.setUint8(total, ch.charCodeAt(0), false);
 | 
				
			||||||
 | 
					      total += 1;
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					  });
 | 
				
			||||||
 | 
					  // must be terminated by null when not using write null
 | 
				
			||||||
 | 
					  dv.setUint8(total, 0, false);
 | 
				
			||||||
 | 
					  total += 1;
 | 
				
			||||||
 | 
					  soaLen += 1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  //console.log('record.email_addr', 1 + record.email_addr.length, record.email_addr);
 | 
				
			||||||
 | 
					  // pack email address which is a sequence of labels
 | 
				
			||||||
 | 
					  (record.admin || record.email_addr).split('.').forEach(function (label) {
 | 
				
			||||||
 | 
					    soaLen += 1 + label.length;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    dv.setUint8(total, label.length, false);
 | 
				
			||||||
 | 
					    total += 1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    label.split('').forEach(function (ch){
 | 
				
			||||||
 | 
					      dv.setUint8(total, ch.charCodeAt(0), false);
 | 
				
			||||||
 | 
					      total += 1;
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					  });
 | 
				
			||||||
 | 
					  // must be terminated by null when not using write null
 | 
				
			||||||
 | 
					  dv.setUint8(total, 0, false);
 | 
				
			||||||
 | 
					  total += 1;
 | 
				
			||||||
 | 
					  soaLen += 1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // pack all 32-bit values
 | 
				
			||||||
 | 
					  dv.setUint32(total, parseInt(record.serial || record.sn, 10), false);
 | 
				
			||||||
 | 
					  total+=4;
 | 
				
			||||||
 | 
					  dv.setUint32(total, parseInt(record.refresh || record.ref, 10), false);
 | 
				
			||||||
 | 
					  total+=4;
 | 
				
			||||||
 | 
					  dv.setUint32(total, parseInt(record.retry || record.ret, 10), false);
 | 
				
			||||||
 | 
					  total+=4;
 | 
				
			||||||
 | 
					  dv.setUint32(total, parseInt(record.expiration || record.ex, 10), false);
 | 
				
			||||||
 | 
					  total+=4;
 | 
				
			||||||
 | 
					  dv.setUint32(total, parseInt(record.minimum || record.nx, 10), false);
 | 
				
			||||||
 | 
					  total+=4;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // RDLENGTH
 | 
				
			||||||
 | 
					  //console.log('rdAt', rdLenIndex);
 | 
				
			||||||
 | 
					  //console.log('soaLen (lables + 2 + 20)', soaLen);
 | 
				
			||||||
 | 
					  dv.setUint16(rdLenIndex, soaLen, false);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  return total;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}('undefined' !== typeof window ? window : exports));
 | 
				
			||||||
							
								
								
									
										73
									
								
								packer/type.srv.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										73
									
								
								packer/type.srv.js
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,73 @@
 | 
				
			|||||||
 | 
					(function (exports) {
 | 
				
			||||||
 | 
					'use strict';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// SRV RDATA contains:
 | 
				
			||||||
 | 
					// Priority: The relative priority of this service. 16-bit (range 0-65535)
 | 
				
			||||||
 | 
					// Weight:   Used when more than one serivice has the same priority. 16-bit
 | 
				
			||||||
 | 
					//           (range 0-65535)
 | 
				
			||||||
 | 
					// Port:     Port number assigned to the symbolic service. 16-bit (range 0-65535)
 | 
				
			||||||
 | 
					// Target:   The name of the host that will provide service.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					exports.DNS_PACKER_TYPE_SRV = function (ab, dv, total, record) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // maybe these should be changed to 'hasOwnProperty' for all of these
 | 
				
			||||||
 | 
					  // TODO: Check that number is in range 1-64k
 | 
				
			||||||
 | 
					  if (!record.priority){
 | 
				
			||||||
 | 
					    throw new Error("no priority for SRV record");
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  if (!record.hasOwnProperty('weight')){
 | 
				
			||||||
 | 
					    throw new Error("no weight for SRV record");
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  if (!record.port){
 | 
				
			||||||
 | 
					    throw new Error("no port for SRV record");
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  if (!record.target) {
 | 
				
			||||||
 | 
					    throw new Error("no target for SRV record");
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // console.log("record length, priority, weight, port, then target");
 | 
				
			||||||
 | 
					  // console.log("record priority is: " + record.priority);
 | 
				
			||||||
 | 
					  // console.log("record weight is: " + record.weight);
 | 
				
			||||||
 | 
					  // console.log("record port is: " + record.port);
 | 
				
			||||||
 | 
					  // console.log("record target is: " + record.target);
 | 
				
			||||||
 | 
					  // console.log("total length currently is: " + total);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  var srvLen = 6; // 16-bit priority, weight and port = 6 Bytes
 | 
				
			||||||
 | 
					  var rdLenIndex = total;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  total+=2; // space for RDLENGTH
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  dv.setUint16(total, parseInt(record.priority, 10), false);
 | 
				
			||||||
 | 
					  total+=2;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  dv.setUint16(total,parseInt(record.weight, 10), false);
 | 
				
			||||||
 | 
					  total+=2;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  dv.setUint16(total, parseInt(record.port, 10), false);
 | 
				
			||||||
 | 
					  total+=2;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  record.target.split('.').forEach(function (label){
 | 
				
			||||||
 | 
					    srvLen += 1 + label.length;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    dv.setUint8(total, label.length, false);
 | 
				
			||||||
 | 
					    total += 1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    label.split('').forEach(function (ch) {
 | 
				
			||||||
 | 
					      dv.setUint8(total, ch.charCodeAt(0), false);
 | 
				
			||||||
 | 
					      total += 1;
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					  });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  dv.setUint8(total, 0x00, false);
 | 
				
			||||||
 | 
					  total += 1;
 | 
				
			||||||
 | 
					  srvLen += 1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // RDLENGTH
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  dv.setUint16(rdLenIndex, srvLen, false);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  return total;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}('undefined' !== typeof window ? window : exports));
 | 
				
			||||||
							
								
								
									
										47
									
								
								packer/type.txt.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										47
									
								
								packer/type.txt.js
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,47 @@
 | 
				
			|||||||
 | 
					(function (exports) {
 | 
				
			||||||
 | 
					'use strict';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Record type is just any text.
 | 
				
			||||||
 | 
					// RFC 1035 - 3.3. Standard RRs - <character-string>
 | 
				
			||||||
 | 
					// RFC 1035 - 3.3.14. TXT RDATA format
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					exports.DNS_PACKER_TYPE_TXT = function (ab, dv, total, record) {
 | 
				
			||||||
 | 
					    if ('string' === typeof record.data) {
 | 
				
			||||||
 | 
					      console.warn("[WARN] 'data' should be an array of strings, not a single string");
 | 
				
			||||||
 | 
					      record.data = [ record.data ];
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    if (!Array.isArray(record.data) || !record.data.length){
 | 
				
			||||||
 | 
					        throw new Error("bad data or no data for TXT record");
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    var txtLen = 0;
 | 
				
			||||||
 | 
					    var rdLenIndex = total;
 | 
				
			||||||
 | 
					    total += 2; // saving space for rdata length
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // RDATA
 | 
				
			||||||
 | 
					    record.data.forEach(function(str){
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      if (str.length > 255) {
 | 
				
			||||||
 | 
					        throw new Error("bad TXT string length " + str.length + " (max 255)");
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      // size of this string
 | 
				
			||||||
 | 
					      dv.setUint8(total, str.length, false);
 | 
				
			||||||
 | 
					      total += 1;
 | 
				
			||||||
 | 
					      txtLen += 1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      str.split('').forEach(function(ch) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        dv.setUint8(total, ch.charCodeAt(0), false);
 | 
				
			||||||
 | 
					        total += 1;
 | 
				
			||||||
 | 
					        txtLen += 1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      });
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    dv.setUint16(rdLenIndex, txtLen, false);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return total;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}('undefined' !== typeof window ? window : exports));
 | 
				
			||||||
@ -27,6 +27,20 @@ exports.DNS_PARSER_TYPE_AAAA = function (ab, packet, record) {
 | 
				
			|||||||
      s += dv.getUint16(i, false).toString(16);
 | 
					      s += dv.getUint16(i, false).toString(16);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // Represent the string address as recommended on the wikipedia page
 | 
				
			||||||
 | 
					    // https://en.wikipedia.org/wiki/IPv6_address#Recommended_representation_as_text.
 | 
				
			||||||
 | 
					    // (shorten the longest section of 0's as long as it's more than one section, replacing
 | 
				
			||||||
 | 
					    // the left-most instance in the event of ties.)
 | 
				
			||||||
 | 
					    var re = /:(0:)+/g;
 | 
				
			||||||
 | 
					    var match;
 | 
				
			||||||
 | 
					    var longest = '_BAD';
 | 
				
			||||||
 | 
					    while (!!(match = re.exec(s))) {
 | 
				
			||||||
 | 
					      if (match[0].length > longest.length) {
 | 
				
			||||||
 | 
					        longest = match[0];
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    s = s.replace(longest, '::');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    record.address = s;
 | 
					    record.address = s;
 | 
				
			||||||
    return record;
 | 
					    return record;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										57
									
								
								parser/type.caa.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										57
									
								
								parser/type.caa.js
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,57 @@
 | 
				
			|||||||
 | 
					(function (exports) {
 | 
				
			||||||
 | 
					'use strict';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// RFC 6844 https://tools.ietf.org/html/rfc6844#section-3
 | 
				
			||||||
 | 
					// https://support.dnsimple.com/articles/caa-record/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// A Certification Authority Authorization (CAA) record is used to specify which
 | 
				
			||||||
 | 
					// certificate authorities (CAs) are allowed to issue certificates for a domain.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Value    Meaning/Use
 | 
				
			||||||
 | 
					//
 | 
				
			||||||
 | 
					// Flag     An unsigned integer between 0-255.
 | 
				
			||||||
 | 
					//          It is currently used to represent the critical flag, that has a
 | 
				
			||||||
 | 
					//          specific meaning per RFC 6844
 | 
				
			||||||
 | 
					// Tag      An ASCII string that represents the identifier of the property
 | 
				
			||||||
 | 
					//          represented by the record.
 | 
				
			||||||
 | 
					// Value    The value associated with the tag.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// The RFC currently defines 3 available tags:
 | 
				
			||||||
 | 
					//
 | 
				
			||||||
 | 
					// - issue:     explicity authorizes a single certificate authority to issue a
 | 
				
			||||||
 | 
					//              certificate (any type) for the hostname.
 | 
				
			||||||
 | 
					// - issuewild: explicity authorizes a single certificate authority to issue a
 | 
				
			||||||
 | 
					//              wildcard certificate (and only wildcard) for the hostname.
 | 
				
			||||||
 | 
					// - iodef:     specifies an URL to which a certificate authority may report
 | 
				
			||||||
 | 
					//              policy violations.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					exports.DNS_PARSER_TYPE_CAA = function (ab, packet, record) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  var data = new Uint8Array(ab);
 | 
				
			||||||
 | 
					  var i = record.rdstart;
 | 
				
			||||||
 | 
					  var flag = data[i];
 | 
				
			||||||
 | 
					  var mid = data[i + 1];
 | 
				
			||||||
 | 
					  i += 2;
 | 
				
			||||||
 | 
					  mid += i;
 | 
				
			||||||
 | 
					  var end = record.rdstart + record.rdlength;
 | 
				
			||||||
 | 
					  var tag = '';
 | 
				
			||||||
 | 
					  var value = '';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  while (i < mid) {
 | 
				
			||||||
 | 
					    tag += String.fromCharCode(data[i]);
 | 
				
			||||||
 | 
					    i += 1;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  while (i < end) {
 | 
				
			||||||
 | 
					    value += String.fromCharCode(data[i]);
 | 
				
			||||||
 | 
					    i += 1;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  record.flag = flag;
 | 
				
			||||||
 | 
					  record.tag = tag;
 | 
				
			||||||
 | 
					  record.value = value;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  return record;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}('undefined' !== typeof window ? window : exports));
 | 
				
			||||||
@ -1,6 +1,10 @@
 | 
				
			|||||||
(function (exports) {
 | 
					(function (exports) {
 | 
				
			||||||
'use strict';
 | 
					'use strict';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// FORMAT:
 | 
				
			||||||
 | 
					// name   ttl   class   rr     name
 | 
				
			||||||
 | 
					// foo.   15    IN      NS     www.example.com.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Comes in variable lengths. It is the name of the primary Master for the Domain.
 | 
					// Comes in variable lengths. It is the name of the primary Master for the Domain.
 | 
				
			||||||
// For example 'ns1.example.com'
 | 
					// For example 'ns1.example.com'
 | 
				
			||||||
// It may be a label, pointer or any combination
 | 
					// It may be a label, pointer or any combination
 | 
				
			||||||
@ -8,11 +12,12 @@ var unpackLabels = exports.DNS_UNPACK_LABELS || require('../dns.unpack-labels.js
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
exports.DNS_PARSER_TYPE_NS = function (ab , packet, record) {
 | 
					exports.DNS_PARSER_TYPE_NS = function (ab , packet, record) {
 | 
				
			||||||
    record.data = unpackLabels(new Uint8Array(ab), record.rdstart, { byteLength: 0, cpcount: 0, labels: [], name: '' }).name;
 | 
					  var labelInfo = unpackLabels(new Uint8Array(ab), record.rdstart, { byteLength: 0, cpcount: 0, labels: [], name: '' });
 | 
				
			||||||
 | 
					  if (record.trunc) {
 | 
				
			||||||
 | 
					    throw new Error("RDATA type NS must be `null`-terminated, not truncated by rdata length.");
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  record.data = labelInfo.name;
 | 
				
			||||||
  return record;
 | 
					  return record;
 | 
				
			||||||
 | 
					 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}('undefined' !== typeof window ? window : exports));
 | 
					}('undefined' !== typeof window ? window : exports));
 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
				
			|||||||
@ -6,12 +6,16 @@
 | 
				
			|||||||
// to a host name.
 | 
					// to a host name.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// FORMAT:
 | 
					// FORMAT:
 | 
				
			||||||
// ame ttl  class   rr     name
 | 
					// name   ttl   class   rr     name
 | 
				
			||||||
// 15         IN     PTR    www.example.com.
 | 
					// foo.   15    IN      PTR    www.example.com.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
var unpackLabels = exports.DNS_UNPACK_LABELS || require('../dns.unpack-labels.js').DNS_UNPACK_LABELS;
 | 
					var unpackLabels = exports.DNS_UNPACK_LABELS || require('../dns.unpack-labels.js').DNS_UNPACK_LABELS;
 | 
				
			||||||
exports.DNS_PARSER_TYPE_PTR = function (ab, pack, record) {
 | 
					exports.DNS_PARSER_TYPE_PTR = function (ab, pack, record) {
 | 
				
			||||||
    record.data = unpackLabels(new Uint8Array(ab), record.rdstart, { byteLength: 0, cpcount: 0, labels: [], name: '' }).name;
 | 
					  var labelInfo = unpackLabels(new Uint8Array(ab), record.rdstart, { byteLength: 0, cpcount: 0, labels: [], name: '' });
 | 
				
			||||||
    return record;
 | 
					  if (record.trunc) {
 | 
				
			||||||
 | 
					    throw new Error("RDATA type PTR must be `null`-terminated, not truncated by rdata length.");
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  record.data = labelInfo.name;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}('undefined' !== typeof window ? window : exports));
 | 
					}('undefined' !== typeof window ? window : exports));
 | 
				
			||||||
 | 
				
			|||||||
@ -1,21 +1,76 @@
 | 
				
			|||||||
(function (exports) {
 | 
					(function (exports) {
 | 
				
			||||||
'use strict';
 | 
					'use strict';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// TODO. Not yet implemented
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// Value              Meaning/Use
 | 
					// Value              Meaning/Use
 | 
				
			||||||
// Primary NS         Variable length. The name of the Primary Master for the domain. May be a label, pointer, or any combination
 | 
					// Primary NS         Variable length. The name of the Primary Master for the domain. May be a label, pointer, or any combination
 | 
				
			||||||
// Admin MB           Variable length. The administrator's mailbox. May be a label, pointer, or any combination
 | 
					// Admin MB           Variable length. The administrator's mailbox. May be a label, pointer, or any combination
 | 
				
			||||||
// Serial Number      Unsigned 32-bit integer
 | 
					// Serial Number      Unsigned 32-bit integer
 | 
				
			||||||
// Refresh Interval   Unsigned 32-bit integer
 | 
					// Refresh Interval   Unsigned 32-bit integer
 | 
				
			||||||
// Retry Interval     Unsigned 32-bit integer
 | 
					// Retry Interval     Unsigned 32-bit integer
 | 
				
			||||||
// Retry Interval     Unsigned 32-bit integer
 | 
					 | 
				
			||||||
// Expiration Limit   Unsigned 32-bit integer
 | 
					// Expiration Limit   Unsigned 32-bit integer
 | 
				
			||||||
// Minimum TTL        Unsigned 32-bit integer
 | 
					// Minimum TTL        Unsigned 32-bit integer
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					var unpackLabels = exports.DNS_UNPACK_LABELS || require('../dns.unpack-labels.js').DNS_UNPACK_LABELS;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
exports.DNS_PARSER_TYPE_SOA = function (ab, packet, record) {
 | 
					exports.DNS_PARSER_TYPE_SOA = function (ab, packet, record) {
 | 
				
			||||||
 | 
					  //
 | 
				
			||||||
 | 
					  // Look!
 | 
				
			||||||
 | 
					  // http://www.peerwisdom.org/2013/05/15/dns-understanding-the-soa-record/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  var rdataAb = ab.slice(record.rdstart, record.rdstart + record.rdlength);
 | 
				
			||||||
 | 
					  var dv = new DataView(rdataAb);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // we need this information for this parser
 | 
				
			||||||
 | 
					  var labelInfo = unpackLabels(new Uint8Array(ab), record.rdstart, { byteLength: 0, cpcount: 0, labels: [], name: '' });
 | 
				
			||||||
 | 
					  //var cpcount = labelInfo.cpcount;
 | 
				
			||||||
 | 
					  var offset = labelInfo.byteLength;
 | 
				
			||||||
 | 
					  //var labels = labelInfo.labels;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // Primary NS
 | 
				
			||||||
 | 
					  record.primary = labelInfo.name;
 | 
				
			||||||
 | 
					  record.name_server = record.primary;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // TODO delete this commented out code after some testing
 | 
				
			||||||
 | 
					  // (pretty sure it was unnecessary and it seemed to work on code with compression pointers just fine)
 | 
				
			||||||
 | 
					  /*
 | 
				
			||||||
 | 
					  // if there exists compression pointers in the rdata
 | 
				
			||||||
 | 
					  if (cpcount > 0) {
 | 
				
			||||||
 | 
					    // do something awesome with compression pointers to get the email address
 | 
				
			||||||
 | 
					    // I need the length of all the data before the email address starts.
 | 
				
			||||||
 | 
					    // if there are compression pointers then there will be a byte to indicate the length of each label, the label,
 | 
				
			||||||
 | 
					    // then there will be a compression pointer to grab the longest label.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    var start = 2; // start or email_addr. take into account compression pointer and address length
 | 
				
			||||||
 | 
					    for (var i = 0; i < labels.length; i += 1) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      // increase start by the label length. the +1 is to take into account the next label size byte
 | 
				
			||||||
 | 
					      start = start + labels[i].length + 1;
 | 
				
			||||||
 | 
					      // check for cpcount. 2 counts behind
 | 
				
			||||||
 | 
					      if (parseInt(dv.getUint8(start - 2), 10) === 192) {
 | 
				
			||||||
 | 
					        record.email_addr = unpackLabels(new Uint8Array(ab), record.rdstart + start ,{ byteLength: 0, cpcount: 0, labels: [], name: '' }).name;
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  } // if there are no compression pointers, we can get the email address directly from the offset
 | 
				
			||||||
 | 
					  else {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    record.email_addr = unpackLabels(new Uint8Array(ab), record.rdstart + offset, { byteLength: 0, cpcount: 0, labels: [], name: '' }).name;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  */
 | 
				
			||||||
 | 
					  record.admin = unpackLabels(new Uint8Array(ab), record.rdstart + offset, { byteLength: 0, cpcount: 0, labels: [], name: '' }).name;
 | 
				
			||||||
 | 
					  record.email_addr = record.admin;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // Serial Number
 | 
				
			||||||
 | 
					  record.serial = record.sn = dv.getUint32(dv.byteLength - 20, false);
 | 
				
			||||||
 | 
					  // Refresh Interval
 | 
				
			||||||
 | 
					  record.refresh = record.ref = dv.getUint32(dv.byteLength - 16, false);
 | 
				
			||||||
 | 
					  // Retry Interval
 | 
				
			||||||
 | 
					  record.retry = record.ret = dv.getUint32(dv.byteLength - 12, false);
 | 
				
			||||||
 | 
					  // Expiration Limit
 | 
				
			||||||
 | 
					  record.expiration = record.ex = dv.getUint32(dv.byteLength - 8, false);
 | 
				
			||||||
 | 
					  // Minimum TTL
 | 
				
			||||||
 | 
					  record.minimum = record.nx = dv.getUint32(dv.byteLength - 4, false);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  return record;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}('undefined' !== typeof window ? window : exports));
 | 
					}('undefined' !== typeof window ? window : exports));
 | 
				
			||||||
 | 
				
			|||||||
@ -1,6 +1,5 @@
 | 
				
			|||||||
(function (exports) {
 | 
					(function (exports) {
 | 
				
			||||||
'use strict';
 | 
					'use strict';
 | 
				
			||||||
// TODO. Not yet implemented
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
// SRV identifies the host(s) that will support a particular service. It
 | 
					// SRV identifies the host(s) that will support a particular service. It
 | 
				
			||||||
// is a general purpose RR to discover any service.
 | 
					// is a general purpose RR to discover any service.
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										
											BIN
										
									
								
								test/fixtures/canone30522.local.bin
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								test/fixtures/canone30522.local.bin
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										59
									
								
								test/fixtures/canone30522.local.js
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										59
									
								
								test/fixtures/canone30522.local.js
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@ -0,0 +1,59 @@
 | 
				
			|||||||
 | 
					module.exports = {
 | 
				
			||||||
 | 
					    "header": {
 | 
				
			||||||
 | 
					        "id": 0,
 | 
				
			||||||
 | 
					        "qr": 1,
 | 
				
			||||||
 | 
					        "opcode": 0,
 | 
				
			||||||
 | 
					        "aa": 0,
 | 
				
			||||||
 | 
					        "tc": 0,
 | 
				
			||||||
 | 
					        "rd": 0,
 | 
				
			||||||
 | 
					        "ra": 0,
 | 
				
			||||||
 | 
					        "res1": 0,
 | 
				
			||||||
 | 
					        "res2": 0,
 | 
				
			||||||
 | 
					        "res3": 0,
 | 
				
			||||||
 | 
					        "rcode": 0
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    "question": [],
 | 
				
			||||||
 | 
					    "answer": [
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            "name": "_pdl-datastream._tcp.local",
 | 
				
			||||||
 | 
					            "type": 12,
 | 
				
			||||||
 | 
					            "class": 1,
 | 
				
			||||||
 | 
					            "ttl": 255,
 | 
				
			||||||
 | 
					            "data": "Canon MF620C Series._pdl-datastream._tcp.local"
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    ],
 | 
				
			||||||
 | 
					    "additional": [
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            "name": "Canone30522.local",
 | 
				
			||||||
 | 
					            "type": 1,
 | 
				
			||||||
 | 
					            "class": 32769,
 | 
				
			||||||
 | 
					            "ttl": 255,
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            "name": "Canon MF620C Series._pdl-datastream._tcp.local",
 | 
				
			||||||
 | 
					            "type": 33,
 | 
				
			||||||
 | 
					            "class": 32769,
 | 
				
			||||||
 | 
					            "ttl": 255,
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            "name": "Canon MF620C Series._pdl-datastream._tcp.local",
 | 
				
			||||||
 | 
					            "type": 16,
 | 
				
			||||||
 | 
					            "class": 32769,
 | 
				
			||||||
 | 
					            "ttl": 255,
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            "name": "Canone30522.local",
 | 
				
			||||||
 | 
					            "type": 47,
 | 
				
			||||||
 | 
					            "class": 32769,
 | 
				
			||||||
 | 
					            "ttl": 255,
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            "name": "Canon MF620C Series._pdl-datastream._tcp.local",
 | 
				
			||||||
 | 
					            "type": 47,
 | 
				
			||||||
 | 
					            "class": 32769,
 | 
				
			||||||
 | 
					            "ttl": 255,
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    ],
 | 
				
			||||||
 | 
					    "authority": [],
 | 
				
			||||||
 | 
					    "edns_options": []
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
							
								
								
									
										
											BIN
										
									
								
								test/fixtures/google.com.soa.bin
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								test/fixtures/google.com.soa.bin
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										63
									
								
								test/fixtures/google.com.soa.json
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										63
									
								
								test/fixtures/google.com.soa.json
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@ -0,0 +1,63 @@
 | 
				
			|||||||
 | 
					{
 | 
				
			||||||
 | 
					  "header": {
 | 
				
			||||||
 | 
					    "id": 52080,
 | 
				
			||||||
 | 
					    "qr": 1,
 | 
				
			||||||
 | 
					    "opcode": 0,
 | 
				
			||||||
 | 
					    "aa": 0,
 | 
				
			||||||
 | 
					    "tc": 0,
 | 
				
			||||||
 | 
					    "rd": 1,
 | 
				
			||||||
 | 
					    "ra": 1,
 | 
				
			||||||
 | 
					    "res1": 0,
 | 
				
			||||||
 | 
					    "res2": 0,
 | 
				
			||||||
 | 
					    "res3": 0,
 | 
				
			||||||
 | 
					    "rcode": 0
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  "qdcount": 1,
 | 
				
			||||||
 | 
					  "ancount": 1,
 | 
				
			||||||
 | 
					  "nscount": 0,
 | 
				
			||||||
 | 
					  "arcount": 0,
 | 
				
			||||||
 | 
					  "question": [
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					      "name": "google.com",
 | 
				
			||||||
 | 
					      "type": 6,
 | 
				
			||||||
 | 
					      "typeName": "SOA",
 | 
				
			||||||
 | 
					      "class": 1,
 | 
				
			||||||
 | 
					      "className": "IN",
 | 
				
			||||||
 | 
					      "byteLength": 16,
 | 
				
			||||||
 | 
					      "labels": [
 | 
				
			||||||
 | 
					        "google",
 | 
				
			||||||
 | 
					        "com"
 | 
				
			||||||
 | 
					      ],
 | 
				
			||||||
 | 
					      "cpcount": 0
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  ],
 | 
				
			||||||
 | 
					  "answer": [
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					      "name": "google.com",
 | 
				
			||||||
 | 
					      "type": 6,
 | 
				
			||||||
 | 
					      "typeName": "SOA",
 | 
				
			||||||
 | 
					      "class": 1,
 | 
				
			||||||
 | 
					      "className": "IN",
 | 
				
			||||||
 | 
					      "byteLength": 50,
 | 
				
			||||||
 | 
					      "labels": [
 | 
				
			||||||
 | 
					        "google",
 | 
				
			||||||
 | 
					        "com"
 | 
				
			||||||
 | 
					      ],
 | 
				
			||||||
 | 
					      "cpcount": 1,
 | 
				
			||||||
 | 
					      "rdstart": 40,
 | 
				
			||||||
 | 
					      "rdlength": 38,
 | 
				
			||||||
 | 
					      "ttl": 59,
 | 
				
			||||||
 | 
					      "name_server": "ns3.google.com",
 | 
				
			||||||
 | 
					      "email_addr": "dns-admin.google.com",
 | 
				
			||||||
 | 
					      "sn": 150355194,
 | 
				
			||||||
 | 
					      "ref": 900,
 | 
				
			||||||
 | 
					      "ret": 900,
 | 
				
			||||||
 | 
					      "ex": 1800,
 | 
				
			||||||
 | 
					      "nx": 60
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  ],
 | 
				
			||||||
 | 
					  "authority": [],
 | 
				
			||||||
 | 
					  "edns_options": [],
 | 
				
			||||||
 | 
					  "additional": [],
 | 
				
			||||||
 | 
					  "byteLength": 78
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										33
									
								
								test/fixtures/www.linode.com.a.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										33
									
								
								test/fixtures/www.linode.com.a.js
									
									
									
									
										vendored
									
									
								
							@ -1,33 +0,0 @@
 | 
				
			|||||||
{ header: 
 | 
					 | 
				
			||||||
   { id: 46894,
 | 
					 | 
				
			||||||
     qr: 1,
 | 
					 | 
				
			||||||
     opcode: 0,
 | 
					 | 
				
			||||||
     aa: 0,
 | 
					 | 
				
			||||||
     tc: 0,
 | 
					 | 
				
			||||||
     rd: 1,
 | 
					 | 
				
			||||||
     ra: 1,
 | 
					 | 
				
			||||||
     res1: 0,
 | 
					 | 
				
			||||||
     res2: 0,
 | 
					 | 
				
			||||||
     res3: 0,
 | 
					 | 
				
			||||||
     rcode: 0 },
 | 
					 | 
				
			||||||
  question: [ { name: 'www.linode.com', type: 1, class: 1 } ],
 | 
					 | 
				
			||||||
  answer: 
 | 
					 | 
				
			||||||
   [ { name: 'www.linode.com',
 | 
					 | 
				
			||||||
       type: 1,
 | 
					 | 
				
			||||||
       class: 1,
 | 
					 | 
				
			||||||
       ttl: 291,
 | 
					 | 
				
			||||||
       address: '72.14.191.202' },
 | 
					 | 
				
			||||||
     { name: 'www.linode.com',
 | 
					 | 
				
			||||||
       type: 1,
 | 
					 | 
				
			||||||
       class: 1,
 | 
					 | 
				
			||||||
       ttl: 291,
 | 
					 | 
				
			||||||
       address: '69.164.200.202' },
 | 
					 | 
				
			||||||
     { name: 'www.linode.com',
 | 
					 | 
				
			||||||
       type: 1,
 | 
					 | 
				
			||||||
       class: 1,
 | 
					 | 
				
			||||||
       ttl: 291,
 | 
					 | 
				
			||||||
       address: '72.14.180.202' } ],
 | 
					 | 
				
			||||||
  authority: [],
 | 
					 | 
				
			||||||
  additional: [],
 | 
					 | 
				
			||||||
  edns_options: [],
 | 
					 | 
				
			||||||
  payload: undefined }
 | 
					 | 
				
			||||||
							
								
								
									
										43
									
								
								test/fixtures/www.linode.com.a.json
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										43
									
								
								test/fixtures/www.linode.com.a.json
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@ -0,0 +1,43 @@
 | 
				
			|||||||
 | 
					{
 | 
				
			||||||
 | 
						"header": {
 | 
				
			||||||
 | 
							"id": 46894,
 | 
				
			||||||
 | 
							"qr": 1,
 | 
				
			||||||
 | 
							"opcode": 0,
 | 
				
			||||||
 | 
							"aa": 0,
 | 
				
			||||||
 | 
							"tc": 0,
 | 
				
			||||||
 | 
							"rd": 1,
 | 
				
			||||||
 | 
							"ra": 1,
 | 
				
			||||||
 | 
							"res1": 0,
 | 
				
			||||||
 | 
							"res2": 0,
 | 
				
			||||||
 | 
							"res3": 0,
 | 
				
			||||||
 | 
							"rcode": 0
 | 
				
			||||||
 | 
						},
 | 
				
			||||||
 | 
						"question": [{ "name": "www.linode.com", "type": 1, "class": 1 }],
 | 
				
			||||||
 | 
						"answer": [
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								"name": "www.linode.com",
 | 
				
			||||||
 | 
								"type": 1,
 | 
				
			||||||
 | 
								"class": 1,
 | 
				
			||||||
 | 
								"ttl": 291,
 | 
				
			||||||
 | 
								"address": "72.14.191.202"
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								"name": "www.linode.com",
 | 
				
			||||||
 | 
								"type": 1,
 | 
				
			||||||
 | 
								"class": 1,
 | 
				
			||||||
 | 
								"ttl": 291,
 | 
				
			||||||
 | 
								"address": "69.164.200.202"
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								"name": "www.linode.com",
 | 
				
			||||||
 | 
								"type": 1,
 | 
				
			||||||
 | 
								"class": 1,
 | 
				
			||||||
 | 
								"ttl": 291,
 | 
				
			||||||
 | 
								"address": "72.14.180.202"
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						],
 | 
				
			||||||
 | 
						"authority": [],
 | 
				
			||||||
 | 
						"additional": [],
 | 
				
			||||||
 | 
						"edns_options": [],
 | 
				
			||||||
 | 
						"payload": undefined
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										
											BIN
										
									
								
								test/fixtures/yahoo.com.any.nxdomain.bin
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								test/fixtures/yahoo.com.any.nxdomain.bin
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										8
									
								
								test/fixtures/yahoo.com.any.nxdomain.hex
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								test/fixtures/yahoo.com.any.nxdomain.hex
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@ -0,0 +1,8 @@
 | 
				
			|||||||
 | 
					0000000 c1 0b 81 83 00 01 00 00 00 01 00 00 14 73 6e 74
 | 
				
			||||||
 | 
					0000010 68 61 6f 75 65 73 6e 74 68 61 6f 75 65 6e 73 74
 | 
				
			||||||
 | 
					0000020 68 05 79 61 68 6f 6f 03 63 6f 6d 00 00 ff 00 01
 | 
				
			||||||
 | 
					0000030 c0 21 00 06 00 01 00 00 02 57 00 31 03 6e 73 31
 | 
				
			||||||
 | 
					0000040 c0 21 0a 68 6f 73 74 6d 61 73 74 65 72 09 79 61
 | 
				
			||||||
 | 
					0000050 68 6f 6f 2d 69 6e 63 c0 27 78 3a 63 bb 00 00 0e
 | 
				
			||||||
 | 
					0000060 10 00 00 01 2c 00 1b af 80 00 00 02 58         
 | 
				
			||||||
 | 
					000006d
 | 
				
			||||||
							
								
								
									
										64
									
								
								test/fixtures/yahoo.com.any.nxdomain.json
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										64
									
								
								test/fixtures/yahoo.com.any.nxdomain.json
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@ -0,0 +1,64 @@
 | 
				
			|||||||
 | 
					{
 | 
				
			||||||
 | 
					  "header": {
 | 
				
			||||||
 | 
					    "id": 49419,
 | 
				
			||||||
 | 
					    "qr": 1,
 | 
				
			||||||
 | 
					    "opcode": 0,
 | 
				
			||||||
 | 
					    "aa": 0,
 | 
				
			||||||
 | 
					    "tc": 0,
 | 
				
			||||||
 | 
					    "rd": 1,
 | 
				
			||||||
 | 
					    "ra": 1,
 | 
				
			||||||
 | 
					    "res1": 0,
 | 
				
			||||||
 | 
					    "res2": 0,
 | 
				
			||||||
 | 
					    "res3": 0,
 | 
				
			||||||
 | 
					    "rcode": 3
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  "qdcount": 1,
 | 
				
			||||||
 | 
					  "ancount": 0,
 | 
				
			||||||
 | 
					  "nscount": 1,
 | 
				
			||||||
 | 
					  "arcount": 0,
 | 
				
			||||||
 | 
					  "question": [
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					      "name": "snthaouesnthaouensth.yahoo.com",
 | 
				
			||||||
 | 
					      "type": 255,
 | 
				
			||||||
 | 
					      "typeName": "ANY",
 | 
				
			||||||
 | 
					      "class": 1,
 | 
				
			||||||
 | 
					      "className": "IN",
 | 
				
			||||||
 | 
					      "byteLength": 36,
 | 
				
			||||||
 | 
					      "labels": [
 | 
				
			||||||
 | 
					        "snthaouesnthaouensth",
 | 
				
			||||||
 | 
					        "yahoo",
 | 
				
			||||||
 | 
					        "com"
 | 
				
			||||||
 | 
					      ],
 | 
				
			||||||
 | 
					      "cpcount": 0
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  ],
 | 
				
			||||||
 | 
					  "answer": [],
 | 
				
			||||||
 | 
					  "authority": [
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					      "name": "yahoo.com",
 | 
				
			||||||
 | 
					      "type": 6,
 | 
				
			||||||
 | 
					      "typeName": "SOA",
 | 
				
			||||||
 | 
					      "class": 1,
 | 
				
			||||||
 | 
					      "className": "IN",
 | 
				
			||||||
 | 
					      "byteLength": 61,
 | 
				
			||||||
 | 
					      "labels": [
 | 
				
			||||||
 | 
					        "yahoo",
 | 
				
			||||||
 | 
					        "com"
 | 
				
			||||||
 | 
					      ],
 | 
				
			||||||
 | 
					      "cpcount": 1,
 | 
				
			||||||
 | 
					      "rdstart": 60,
 | 
				
			||||||
 | 
					      "rdlength": 49,
 | 
				
			||||||
 | 
					      "ttl": 599,
 | 
				
			||||||
 | 
					      "name_server": "ns1.yahoo.com",
 | 
				
			||||||
 | 
					      "email_addr": "hostmaster.yahoo-inc.com",
 | 
				
			||||||
 | 
					      "sn": 2017092539,
 | 
				
			||||||
 | 
					      "ref": 3600,
 | 
				
			||||||
 | 
					      "ret": 300,
 | 
				
			||||||
 | 
					      "ex": 1814400,
 | 
				
			||||||
 | 
					      "nx": 600
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  ],
 | 
				
			||||||
 | 
					  "edns_options": [],
 | 
				
			||||||
 | 
					  "additional": [],
 | 
				
			||||||
 | 
					  "byteLength": 109
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@ -2,7 +2,7 @@
 | 
				
			|||||||
  'use strict';
 | 
					  'use strict';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  var fs = require('fs');
 | 
					  var fs = require('fs');
 | 
				
			||||||
  var path = require('path');
 | 
					  //var path = require('path');
 | 
				
			||||||
  var dnsjs = require('../').DNSPacket;
 | 
					  var dnsjs = require('../').DNSPacket;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  //var dirname = path.join(__dirname, 'fixtures');
 | 
					  //var dirname = path.join(__dirname, 'fixtures');
 | 
				
			||||||
@ -21,7 +21,7 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  var json = JSON.parse(fs.readFileSync(onefile, 'utf8'));
 | 
					  var json = JSON.parse(fs.readFileSync(onefile, 'utf8'));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  var ab = dnsjs.write(json);
 | 
					  var ab = dnsjs.write(json).buffer;
 | 
				
			||||||
  //console.log(ab);
 | 
					  //console.log(ab);
 | 
				
			||||||
  //console.log(ui8);
 | 
					  //console.log(ui8);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										
											BIN
										
									
								
								test/soa_test/google.com.soa.query.bin
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								test/soa_test/google.com.soa.query.bin
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										19
									
								
								test/soa_test/google.com.soa.query.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								test/soa_test/google.com.soa.query.json
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,19 @@
 | 
				
			|||||||
 | 
					{
 | 
				
			||||||
 | 
					  "header": {
 | 
				
			||||||
 | 
					    "id": 52080,
 | 
				
			||||||
 | 
					    "qr": 0,
 | 
				
			||||||
 | 
					    "opcode": 0,
 | 
				
			||||||
 | 
					    "aa": 0,
 | 
				
			||||||
 | 
					    "tc": 0,
 | 
				
			||||||
 | 
					    "rd": 1,
 | 
				
			||||||
 | 
					    "ra": 0,
 | 
				
			||||||
 | 
					    "rcode": 0
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  "question": [
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					      "name": "google.com",
 | 
				
			||||||
 | 
					      "typeName": "SOA",
 | 
				
			||||||
 | 
					      "className": "IN"
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  ]
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										
											BIN
										
									
								
								test/soa_test/nx.yahoo.com.any.query.bin
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								test/soa_test/nx.yahoo.com.any.query.bin
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										4
									
								
								test/soa_test/nx.yahoo.com.any.query.hex
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								test/soa_test/nx.yahoo.com.any.query.hex
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,4 @@
 | 
				
			|||||||
 | 
					0000000 c1 0b 01 00 00 01 00 00 00 00 00 00 14 73 6e 74
 | 
				
			||||||
 | 
					0000010 68 61 6f 75 65 73 6e 74 68 61 6f 75 65 6e 73 74
 | 
				
			||||||
 | 
					0000020 68 05 79 61 68 6f 6f 03 63 6f 6d 00 00 ff 00 01
 | 
				
			||||||
 | 
					0000030
 | 
				
			||||||
							
								
								
									
										21
									
								
								test/soa_test/nx.yahoo.com.any.query.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								test/soa_test/nx.yahoo.com.any.query.json
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,21 @@
 | 
				
			|||||||
 | 
					{
 | 
				
			||||||
 | 
					  "header": {
 | 
				
			||||||
 | 
					    "id": 49419,
 | 
				
			||||||
 | 
					    "qr": 0,
 | 
				
			||||||
 | 
					    "opcode": 0,
 | 
				
			||||||
 | 
					    "aa": 0,
 | 
				
			||||||
 | 
					    "tc": 0,
 | 
				
			||||||
 | 
					    "rd": 1,
 | 
				
			||||||
 | 
					    "ra": 0,
 | 
				
			||||||
 | 
					    "rcode": 0
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  "question": [
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					      "name": "snthaouesnthaouensth.yahoo.com",
 | 
				
			||||||
 | 
					      "typeName": "ANY",
 | 
				
			||||||
 | 
					      "className": "IN",
 | 
				
			||||||
 | 
					      "class": 1,
 | 
				
			||||||
 | 
					      "type": 255
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  ]
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										17
									
								
								test/soa_test/yahoo.com.nx.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								test/soa_test/yahoo.com.nx.json
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,17 @@
 | 
				
			|||||||
 | 
					{ "header":
 | 
				
			||||||
 | 
					  { "id":19900,"qr":1,"opcode":0,"aa":0,"tc":0,"rd":1,"ra":1,"res1":0,"res2":0,"res3":0,"rcode":3},
 | 
				
			||||||
 | 
					  "qdcount":1,
 | 
				
			||||||
 | 
					  "ancount":0,
 | 
				
			||||||
 | 
					  "nscount":1,
 | 
				
			||||||
 | 
					  "arcount":0,
 | 
				
			||||||
 | 
					  "question":[
 | 
				
			||||||
 | 
					    {"name":"snthaouesnthaouensth.yahoo.com","type":255,"typeName":"ANY","class":1,"className":"IN","byteLength":36,"labels":["snthaouesnthaouensth","yahoo","com"],"cpcount":0}
 | 
				
			||||||
 | 
					  ],
 | 
				
			||||||
 | 
					  "answer":[],
 | 
				
			||||||
 | 
					  "authority":[
 | 
				
			||||||
 | 
					    {"name":"yahoo.com","type":6,"typeName":"SOA","class":1,"className":"IN","byteLength":61,"labels":["yahoo","com"],"cpcount":1,"rdstart":60,"rdlength":49,"ttl":599,"name_server":"ns1.yahoo.com","email_addr":"hostmaster.yahoo-inc.com","sn":2017092539,"ref":3600,"ret":300,"ex":1814400,"nx":600}
 | 
				
			||||||
 | 
					  ],
 | 
				
			||||||
 | 
					  "edns_options":[],
 | 
				
			||||||
 | 
					  "additional":[],
 | 
				
			||||||
 | 
					  "byteLength":109
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										
											BIN
										
									
								
								test/txt_test/google.com.txt.0.bin
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								test/txt_test/google.com.txt.0.bin
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										201
									
								
								test/txt_test/google.com.txt.0.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										201
									
								
								test/txt_test/google.com.txt.0.json
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,201 @@
 | 
				
			|||||||
 | 
					{
 | 
				
			||||||
 | 
					  "header": {
 | 
				
			||||||
 | 
					    "id": 430,
 | 
				
			||||||
 | 
					    "qr": 1,
 | 
				
			||||||
 | 
					    "opcode": 0,
 | 
				
			||||||
 | 
					    "aa": 0,
 | 
				
			||||||
 | 
					    "tc": 0,
 | 
				
			||||||
 | 
					    "rd": 1,
 | 
				
			||||||
 | 
					    "ra": 1,
 | 
				
			||||||
 | 
					    "res1": 0,
 | 
				
			||||||
 | 
					    "res2": 0,
 | 
				
			||||||
 | 
					    "res3": 0,
 | 
				
			||||||
 | 
					    "rcode": 0
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  "qdcount": 1,
 | 
				
			||||||
 | 
					  "ancount": 1,
 | 
				
			||||||
 | 
					  "nscount": 4,
 | 
				
			||||||
 | 
					  "arcount": 4,
 | 
				
			||||||
 | 
					  "question": [
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					      "name": "google.com",
 | 
				
			||||||
 | 
					      "type": 16,
 | 
				
			||||||
 | 
					      "typeName": "TXT",
 | 
				
			||||||
 | 
					      "class": 1,
 | 
				
			||||||
 | 
					      "className": "IN",
 | 
				
			||||||
 | 
					      "byteLength": 16,
 | 
				
			||||||
 | 
					      "labels": [
 | 
				
			||||||
 | 
					        "google",
 | 
				
			||||||
 | 
					        "com"
 | 
				
			||||||
 | 
					      ],
 | 
				
			||||||
 | 
					      "cpcount": 0
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  ],
 | 
				
			||||||
 | 
					  "answer": [
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					      "name": "google.com",
 | 
				
			||||||
 | 
					      "type": 16,
 | 
				
			||||||
 | 
					      "typeName": "TXT",
 | 
				
			||||||
 | 
					      "class": 1,
 | 
				
			||||||
 | 
					      "className": "IN",
 | 
				
			||||||
 | 
					      "byteLength": 48,
 | 
				
			||||||
 | 
					      "labels": [
 | 
				
			||||||
 | 
					        "google",
 | 
				
			||||||
 | 
					        "com"
 | 
				
			||||||
 | 
					      ],
 | 
				
			||||||
 | 
					      "cpcount": 1,
 | 
				
			||||||
 | 
					      "rdstart": 40,
 | 
				
			||||||
 | 
					      "rdlength": 36,
 | 
				
			||||||
 | 
					      "ttl": 2930,
 | 
				
			||||||
 | 
					      "data": [
 | 
				
			||||||
 | 
					        "v=spf1 include:_spf.google.com ~all"
 | 
				
			||||||
 | 
					      ]
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  ],
 | 
				
			||||||
 | 
					  "authority": [
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					      "name": "google.com",
 | 
				
			||||||
 | 
					      "type": 2,
 | 
				
			||||||
 | 
					      "typeName": "NS",
 | 
				
			||||||
 | 
					      "class": 1,
 | 
				
			||||||
 | 
					      "className": "IN",
 | 
				
			||||||
 | 
					      "byteLength": 18,
 | 
				
			||||||
 | 
					      "labels": [
 | 
				
			||||||
 | 
					        "google",
 | 
				
			||||||
 | 
					        "com"
 | 
				
			||||||
 | 
					      ],
 | 
				
			||||||
 | 
					      "cpcount": 1,
 | 
				
			||||||
 | 
					      "rdstart": 88,
 | 
				
			||||||
 | 
					      "rdlength": 6,
 | 
				
			||||||
 | 
					      "ttl": 82790,
 | 
				
			||||||
 | 
					      "data": "ns3.google.com"
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					      "name": "google.com",
 | 
				
			||||||
 | 
					      "type": 2,
 | 
				
			||||||
 | 
					      "typeName": "NS",
 | 
				
			||||||
 | 
					      "class": 1,
 | 
				
			||||||
 | 
					      "className": "IN",
 | 
				
			||||||
 | 
					      "byteLength": 18,
 | 
				
			||||||
 | 
					      "labels": [
 | 
				
			||||||
 | 
					        "google",
 | 
				
			||||||
 | 
					        "com"
 | 
				
			||||||
 | 
					      ],
 | 
				
			||||||
 | 
					      "cpcount": 1,
 | 
				
			||||||
 | 
					      "rdstart": 106,
 | 
				
			||||||
 | 
					      "rdlength": 6,
 | 
				
			||||||
 | 
					      "ttl": 82790,
 | 
				
			||||||
 | 
					      "data": "ns4.google.com"
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					      "name": "google.com",
 | 
				
			||||||
 | 
					      "type": 2,
 | 
				
			||||||
 | 
					      "typeName": "NS",
 | 
				
			||||||
 | 
					      "class": 1,
 | 
				
			||||||
 | 
					      "className": "IN",
 | 
				
			||||||
 | 
					      "byteLength": 18,
 | 
				
			||||||
 | 
					      "labels": [
 | 
				
			||||||
 | 
					        "google",
 | 
				
			||||||
 | 
					        "com"
 | 
				
			||||||
 | 
					      ],
 | 
				
			||||||
 | 
					      "cpcount": 1,
 | 
				
			||||||
 | 
					      "rdstart": 124,
 | 
				
			||||||
 | 
					      "rdlength": 6,
 | 
				
			||||||
 | 
					      "ttl": 82790,
 | 
				
			||||||
 | 
					      "data": "ns1.google.com"
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					      "name": "google.com",
 | 
				
			||||||
 | 
					      "type": 2,
 | 
				
			||||||
 | 
					      "typeName": "NS",
 | 
				
			||||||
 | 
					      "class": 1,
 | 
				
			||||||
 | 
					      "className": "IN",
 | 
				
			||||||
 | 
					      "byteLength": 18,
 | 
				
			||||||
 | 
					      "labels": [
 | 
				
			||||||
 | 
					        "google",
 | 
				
			||||||
 | 
					        "com"
 | 
				
			||||||
 | 
					      ],
 | 
				
			||||||
 | 
					      "cpcount": 1,
 | 
				
			||||||
 | 
					      "rdstart": 142,
 | 
				
			||||||
 | 
					      "rdlength": 6,
 | 
				
			||||||
 | 
					      "ttl": 82790,
 | 
				
			||||||
 | 
					      "data": "ns2.google.com"
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  ],
 | 
				
			||||||
 | 
					  "edns_options": [],
 | 
				
			||||||
 | 
					  "additional": [
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					      "name": "ns1.google.com",
 | 
				
			||||||
 | 
					      "type": 1,
 | 
				
			||||||
 | 
					      "typeName": "A",
 | 
				
			||||||
 | 
					      "class": 1,
 | 
				
			||||||
 | 
					      "className": "IN",
 | 
				
			||||||
 | 
					      "byteLength": 16,
 | 
				
			||||||
 | 
					      "labels": [
 | 
				
			||||||
 | 
					        "ns1",
 | 
				
			||||||
 | 
					        "google",
 | 
				
			||||||
 | 
					        "com"
 | 
				
			||||||
 | 
					      ],
 | 
				
			||||||
 | 
					      "cpcount": 2,
 | 
				
			||||||
 | 
					      "rdstart": 160,
 | 
				
			||||||
 | 
					      "rdlength": 4,
 | 
				
			||||||
 | 
					      "ttl": 255588,
 | 
				
			||||||
 | 
					      "address": "216.239.32.10"
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					      "name": "ns2.google.com",
 | 
				
			||||||
 | 
					      "type": 1,
 | 
				
			||||||
 | 
					      "typeName": "A",
 | 
				
			||||||
 | 
					      "class": 1,
 | 
				
			||||||
 | 
					      "className": "IN",
 | 
				
			||||||
 | 
					      "byteLength": 16,
 | 
				
			||||||
 | 
					      "labels": [
 | 
				
			||||||
 | 
					        "ns2",
 | 
				
			||||||
 | 
					        "google",
 | 
				
			||||||
 | 
					        "com"
 | 
				
			||||||
 | 
					      ],
 | 
				
			||||||
 | 
					      "cpcount": 2,
 | 
				
			||||||
 | 
					      "rdstart": 176,
 | 
				
			||||||
 | 
					      "rdlength": 4,
 | 
				
			||||||
 | 
					      "ttl": 255577,
 | 
				
			||||||
 | 
					      "address": "216.239.34.10"
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					      "name": "ns3.google.com",
 | 
				
			||||||
 | 
					      "type": 1,
 | 
				
			||||||
 | 
					      "typeName": "A",
 | 
				
			||||||
 | 
					      "class": 1,
 | 
				
			||||||
 | 
					      "className": "IN",
 | 
				
			||||||
 | 
					      "byteLength": 16,
 | 
				
			||||||
 | 
					      "labels": [
 | 
				
			||||||
 | 
					        "ns3",
 | 
				
			||||||
 | 
					        "google",
 | 
				
			||||||
 | 
					        "com"
 | 
				
			||||||
 | 
					      ],
 | 
				
			||||||
 | 
					      "cpcount": 2,
 | 
				
			||||||
 | 
					      "rdstart": 192,
 | 
				
			||||||
 | 
					      "rdlength": 4,
 | 
				
			||||||
 | 
					      "ttl": 255599,
 | 
				
			||||||
 | 
					      "address": "216.239.36.10"
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					      "name": "ns4.google.com",
 | 
				
			||||||
 | 
					      "type": 1,
 | 
				
			||||||
 | 
					      "typeName": "A",
 | 
				
			||||||
 | 
					      "class": 1,
 | 
				
			||||||
 | 
					      "className": "IN",
 | 
				
			||||||
 | 
					      "byteLength": 16,
 | 
				
			||||||
 | 
					      "labels": [
 | 
				
			||||||
 | 
					        "ns4",
 | 
				
			||||||
 | 
					        "google",
 | 
				
			||||||
 | 
					        "com"
 | 
				
			||||||
 | 
					      ],
 | 
				
			||||||
 | 
					      "cpcount": 2,
 | 
				
			||||||
 | 
					      "rdstart": 208,
 | 
				
			||||||
 | 
					      "rdlength": 4,
 | 
				
			||||||
 | 
					      "ttl": 255595,
 | 
				
			||||||
 | 
					      "address": "216.239.38.10"
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  ],
 | 
				
			||||||
 | 
					  "byteLength": 212
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										
											BIN
										
									
								
								test/txt_test/google.com.txt.query.bin
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								test/txt_test/google.com.txt.query.bin
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										19
									
								
								test/txt_test/google.com.txt.query.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								test/txt_test/google.com.txt.query.json
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,19 @@
 | 
				
			|||||||
 | 
					{
 | 
				
			||||||
 | 
					  "header": {
 | 
				
			||||||
 | 
					    "id": 430,
 | 
				
			||||||
 | 
					    "qr": 0,
 | 
				
			||||||
 | 
					    "opcode": 0,
 | 
				
			||||||
 | 
					    "aa": 0,
 | 
				
			||||||
 | 
					    "tc": 0,
 | 
				
			||||||
 | 
					    "rd": 1,
 | 
				
			||||||
 | 
					    "ra": 0,
 | 
				
			||||||
 | 
					    "rcode": 0
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  "question": [
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					      "name": "google.com",
 | 
				
			||||||
 | 
					      "typeName": "TXT",
 | 
				
			||||||
 | 
					      "className": "IN"
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  ]
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user