Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (!program.args[0]) {
program.outputHelp()
process.exit(-1)
}
url = URL.parse(program.args[0])
url.method = method
url.observe = program.observe
url.confirmable = !program.nonConfirmable
if (url.protocol !== 'coap:' || !url.hostname) {
console.log('Wrong URL. Protocol is not coap or no hostname found.')
process.exit(-1)
}
coap.parameters.exchangeLifetime = program.timeout ? program.timeout : 30
if (program.block2 && (program.block2 < 1 || program.block2 > 6)) {
console.log('Invalid block2 size, valid range [1..6]')
console.log('block2 1: 32 bytes payload, block2 2: 64 bytes payload...')
process.exit(-1)
}
var startTime = new Date()
req = request(url)
if (program.block2) {
req.setOption('Block2', Buffer.from([program.block2]))
}
if (typeof program.coapOption !== 'undefined' && program.coapOption.length > 0) {
program.coapOption.forEach(function (singleOption) {
var kvPair = singleOption.split(coapOptionSeperator, 2)