WIP dns-pack
This commit is contained in:
		
							parent
							
								
									8f09c4f4d3
								
							
						
					
					
						commit
						ab533ab36c
					
				
							
								
								
									
										41
									
								
								bin/dns-pack.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										41
									
								
								bin/dns-pack.js
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,41 @@ | ||||
| 'use strict'; | ||||
| 
 | ||||
| // EXAMPLE:
 | ||||
| // node bin/dns-parse.js samples/a-0.mdns.bin
 | ||||
| 
 | ||||
| // pass a terminal arg
 | ||||
| var filename = process.argv[2]; | ||||
| if (!filename) { | ||||
|   console.error("Usage: node bin/dns-pack.js <path/to/sample.json>"); | ||||
|   console.error("Example: node bin/dns-pack.js ./samples/services-0.mdns.json"); | ||||
|   process.exit(1); | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| 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(buffer.toString('ascii'))); | ||||
| 
 | ||||
|   //console.log('[packet]', nb.byteLength, 'bytes:');
 | ||||
|   //console.log(JSON.stringify(packet, null, 2));
 | ||||
| 
 | ||||
|   //TODO hexdump packet
 | ||||
| }); | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user