87 lines
		
	
	
		
			2.3 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			87 lines
		
	
	
		
			2.3 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
| (function (exports) {
 | |
| 'use strict';
 | |
| 
 | |
| // TODO. Not yet implemented
 | |
| 
 | |
| // Value: Preference
 | |
| // Meaning/Use: Unsigned 16-bit integer
 | |
| //-------------------------------------
 | |
| // Value: Mail Exchanger
 | |
| // Meaning/Use: The name host name that provides the service.
 | |
| // May be a label, pointer or any combination
 | |
| 
 | |
| // ab is arrayBuffer, packet is Object, Record is Object
 | |
| var unpackLabels = exports.DNS_UNPACK_LABELS || require('./dns.unpack-labels.js').DNS_UNPACK_LABELS;
 | |
| exports.DNS_TYPE_MX = function (ab, packet, record) {
 | |
| 
 | |
| 
 | |
|     var rdataAb = ab.slice(record.rdstart, record.rdstart + record.rdlength)
 | |
|     var dv = new DataView(rdataAb);
 | |
|     var data = '';
 | |
| 
 | |
|     var s = {
 | |
|        priority:    ''  // also known as preference
 | |
|      , exchange:    ''  //     
 | |
|         
 | |
|     };
 | |
|     var temp = ''
 | |
|     var stuff = '';
 | |
|     console.log("dataview length: " + dv.byteLength);
 | |
|     for (var i = 0; i < dv.byteLength; i += 1) {
 | |
|         
 | |
| 
 | |
|         console.log(dv.getUint8(i, false.toString(16)));        
 | |
|         //Priority is the first two bytes
 | |
|         if (i < 2){
 | |
| 
 | |
|             s.priority += dv.getUint8(i, false).toString(10);
 | |
| 
 | |
|             // take off an padded zeros
 | |
|             if (s.priority.substr(0, 1) === '0') {
 | |
| 
 | |
|                 s.priority = s.priority.slice(1, s.priority.length);
 | |
| 
 | |
|             }
 | |
|             
 | |
|         } else {
 | |
| 
 | |
| 
 | |
|             // get data from uint8 array
 | |
|             data = dv.getUint8(i, false);
 | |
|             // get the string from the data
 | |
|             temp = String.fromCharCode(data);
 | |
|             console.log("data at index " + i + ":" + temp);
 | |
|             
 | |
|             // I need to place the '.' in the correct place. This is wrong though.
 | |
|             if ((temp.trim() === ''  && i > 2) || (!temp.match(/^[a-zA-Z0-9._-]+$/) && i > 2)) {
 | |
|                 s.exchange += ".";
 | |
|             }
 | |
| 
 | |
|             // filter out everything that isn't a valid character
 | |
|             temp = temp.match(/^[a-zA-Z0-9._-]+$/);
 | |
| 
 | |
|             // if temp is null, do nothing
 | |
|             if (temp === null){
 | |
| 
 | |
|                 // otherwise, append to s.exchange
 | |
|             }else{
 | |
| 
 | |
|                 s.exchange += temp;
 | |
| 
 | |
|             }
 | |
| 
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     // the below code returns an empty string. 
 | |
|     
 | |
|     // s.exchange = unpackLabels(new Uint8Array(ab), record.rdstart, { byteLength: 0, cpcount: 0, labels: [], name: '' }).labels;
 | |
| 
 | |
|     return s;
 | |
| 
 | |
| 
 | |
| };
 | |
| 
 | |
| }('undefined' !== typeof window ? window : exports));
 | |
| 
 |