Commit generated files
This commit is contained in:
34
dist/classes/IPAddress.js
vendored
Normal file
34
dist/classes/IPAddress.js
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const ipaddr = require('ipaddr.js');
|
||||
class IPAddress {
|
||||
constructor(buf, pos) {
|
||||
this.ip = null;
|
||||
this.toString = () => {
|
||||
return this.ip.toString();
|
||||
};
|
||||
if (buf !== undefined && buf instanceof Buffer) {
|
||||
if (pos !== undefined) {
|
||||
const bytes = buf.slice(pos, 4);
|
||||
this.ip = ipaddr.fromByteArray(bytes);
|
||||
}
|
||||
else {
|
||||
if (ipaddr.isValid(buf)) {
|
||||
this.ip = ipaddr.parse(buf);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
static zero() {
|
||||
return new IPAddress('0.0.0.0');
|
||||
}
|
||||
writeToBuffer(buf, pos) {
|
||||
const bytes = this.ip.toByteArray();
|
||||
buf.writeUInt8(bytes[0], pos++);
|
||||
buf.writeUInt8(bytes[1], pos++);
|
||||
buf.writeUInt8(bytes[2], pos++);
|
||||
buf.writeUInt8(bytes[3], pos);
|
||||
}
|
||||
}
|
||||
exports.IPAddress = IPAddress;
|
||||
//# sourceMappingURL=IPAddress.js.map
|
||||
Reference in New Issue
Block a user