| 
									
										
										
										
											2017-03-04 17:10:25 -07:00
										 |  |  | (function (exports) { | 
					
						
							|  |  |  | 'use strict'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-16 18:48:08 -06:00
										 |  |  | // 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
 | 
					
						
							| 
									
										
										
										
											2017-03-04 17:10:25 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-09 19:34:27 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-04 17:10:25 -07:00
										 |  |  | exports.DNS_PACKER_TYPE_SOA = function (ab, dv, total, record) { | 
					
						
							| 
									
										
										
										
											2017-03-16 18:48:08 -06:00
										 |  |  |   if(!record.name_server){ | 
					
						
							|  |  |  |     throw new Error("no name server for SOA record"); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   if(!record.email_addr){ | 
					
						
							|  |  |  |     throw new Error("ne email address for SOA record"); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2017-03-09 19:34:27 -07:00
										 |  |  |   if(!record.sn){ | 
					
						
							|  |  |  |     throw new Error("no serial number for SOA record"); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   if(!record.ref){ | 
					
						
							|  |  |  |     throw new Error("no serial number for SOA record"); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   if(!record.ret){ | 
					
						
							|  |  |  |     throw new Error("no serial number for SOA record"); | 
					
						
							| 
									
										
										
										
											2017-03-18 11:38:43 -06:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2017-03-09 19:34:27 -07:00
										 |  |  |   if(!record.ex){ | 
					
						
							|  |  |  |     throw new Error("no serial number for SOA record"); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   if(!record.nx){ | 
					
						
							|  |  |  |     throw new Error("no serial number for SOA record"); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-18 11:38:43 -06:00
										 |  |  |   var soaLen = 20; // take into account sn, ref, ret, ex, and nx
 | 
					
						
							| 
									
										
										
										
											2017-03-16 18:48:08 -06:00
										 |  |  |                   //  (32-bits each. 4Bytes * 5 = 20)
 | 
					
						
							|  |  |  |   var rdLenIndex = total; | 
					
						
							|  |  |  |   total += 2; // Save space for RDLENGTH
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // pack name_server which is a sequence of labels
 | 
					
						
							|  |  |  |   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; | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // pack email address which is a sequence of labels
 | 
					
						
							|  |  |  |   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; | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // pack all 32-bit values
 | 
					
						
							|  |  |  |   dv.setUint32(total, parseInt(record.sn, 10), false); | 
					
						
							|  |  |  |   total+=4; | 
					
						
							|  |  |  |   dv.setUint32(total, parseInt(record.ref, 10), false); | 
					
						
							|  |  |  |   total+=4; | 
					
						
							|  |  |  |   dv.setUint32(total, parseInt(record.ret, 10), false); | 
					
						
							| 
									
										
										
										
											2017-03-18 11:38:43 -06:00
										 |  |  |   total+=4; | 
					
						
							| 
									
										
										
										
											2017-03-16 18:48:08 -06:00
										 |  |  |   dv.setUint32(total, parseInt(record.ex, 10), false); | 
					
						
							|  |  |  |   total+=4; | 
					
						
							|  |  |  |   dv.setUint32(total, parseInt(record.nx, 10), false); | 
					
						
							|  |  |  |   total+=4; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // RDLENGTH
 | 
					
						
							|  |  |  |   dv.setUint16(rdLenIndex, soaLen, false); | 
					
						
							| 
									
										
										
										
											2017-03-04 17:10:25 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |   return total; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | }('undefined' !== typeof window ? window : exports)); |