时间:2023-02-02 15:40:01 | 来源:建站知识
时间:2023-02-02 15:40:01 来源:建站知识
let utf8Encode = new TextEncoder(); function createDNSPacket(domain) { var domainUint8array = new TextEncoder("utf-8").encode(domain); var domainSize = domainUint8array.byteLength + 2; console.log(domainSize); const headerBuffer = new ArrayBuffer(12); const header = new DataView(headerBuffer); header.setUint16(0, 1) header.setUint16(2, 100) header.setUint16(4, 1) header.setUint16(6, 0) header.setUint16(8, 0) header.setUint16(10, 0) const questionBuffer = new ArrayBuffer(4); const question = new DataView(questionBuffer); question.setUint16(0, 1) question.setUint16(2, 1) var concateBuff = new Uint8Array(domainUint8array.byteLength + headerBuffer.byteLength + questionBuffer.byteLength + 2); concateBuff.set(new Uint8Array(headerBuffer), 0); concateBuff.set(new Uint16Array(1), headerBuffer.byteLength); // 仿dns-packet实现 concateBuff.set(domainUint8array, headerBuffer.byteLength + 1); concateBuff.set(new Uint16Array(1), headerBuffer.byteLength + 2); // 仿dns-packet实现 concateBuff.set(new Uint8Array(questionBuffer), headerBuffer.byteLength + domainUint8array.byteLength + 2); return concateBuff; }
关键词:协议,学习