38 lines
997 B
JavaScript
38 lines
997 B
JavaScript
'use strict';
|
|
|
|
exports = module.exports = {
|
|
getServerIPv4,
|
|
getServerIPv6,
|
|
testConfig
|
|
};
|
|
|
|
const assert = require('assert'),
|
|
BoxError = require('../boxerror.js'),
|
|
net = require('net');
|
|
|
|
async function getServerIPv4(config) {
|
|
assert.strictEqual(typeof config, 'object');
|
|
|
|
return config.ip;
|
|
}
|
|
|
|
async function getServerIPv6(config) {
|
|
assert.strictEqual(typeof config, 'object');
|
|
|
|
return config.ipv6;
|
|
}
|
|
|
|
async function testConfig(config) {
|
|
assert.strictEqual(typeof config, 'object');
|
|
|
|
if (typeof config.ip !== 'string') return new BoxError(BoxError.BAD_FIELD, 'ipv4 must be a string');
|
|
if (!net.isIPv4(config.ip)) return new BoxError(BoxError.BAD_FIELD, 'ip is not a valid ipv4');
|
|
|
|
if ('ipv6' in config) {
|
|
if (typeof config.ipv6 !== 'string') return new BoxError(BoxError.BAD_FIELD, 'ipv6 must be a string');
|
|
if (!net.isIPv6(config.ipv6)) return new BoxError(BoxError.BAD_FIELD, 'ipv6 is not a valid ipv6');
|
|
}
|
|
|
|
return null;
|
|
}
|