Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

dhcp

Package Overview
Dependencies
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dhcp - npm Package Compare versions

Comparing version 0.2.18 to 0.2.19

Dockerfile

12

examples/server.js

@@ -31,3 +31,3 @@

rebindingTime: 120,
bootFile: function (req, res) {
bootFile: function(req, res) {

@@ -44,3 +44,3 @@ // res.ip - the actual ip allocated for the client

s.on('message', function (data) {
s.on('message', function(data) {
console.log(data);

@@ -54,7 +54,7 @@ });

s.on("error", function (err, data) {
s.on("error", function(err, data) {
console.log(err, data);
});
s.on("listening", function (sock) {
s.on("listening", function(sock) {
var address = sock.address();

@@ -64,3 +64,3 @@ console.info('Server Listening: ' + address.address + ':' + address.port);

s.on("close", function () {
s.on("close", function() {
console.log('close');

@@ -72,3 +72,3 @@ });

process.on('SIGINT', () => {
s.close();
s.close();
});
/**
* @license DHCP.js v0.2.18 28/06/2017
* @license DHCP.js v0.2.19 28/06/2017
* http://www.xarg.org/2017/06/a-pure-javascript-dhcp-implementation/

@@ -75,2 +75,4 @@ *

self._req = req;
if (req.op !== BOOTREQUEST) {

@@ -111,2 +113,6 @@ self.emit('error', new Error('Malformed packet'), req);

sock.on('error', function(e) {
self.emit('error',e);
});
this._sock = sock;

@@ -128,2 +134,5 @@ this._conf = config;

// Incoming request
_req: null,
config: function(key) {

@@ -147,3 +156,12 @@

if (val instanceof Function) {
val = val.call(this);
var reqOpt = {};
for (var i in this._req.options) {
var opt = Options.opts[i];
if (opt.enum) {
reqOpt[opt.attr || i] = opt.enum[this._req.options[i]];
} else {
reqOpt[opt.attr || i] = this._req.options[i];
}
}
val = val.call(this, reqOpt);
}

@@ -305,3 +323,3 @@

// Check if all IP's are used and delete the oldest
if (lastIP - firstIP === leases) {
if (oldestMac !== null && lastIP - firstIP === leases) {
const ip = this._state[oldestMac].address;

@@ -524,2 +542,4 @@

self._req = req;
if (req.op !== BOOTREPLY) {

@@ -573,2 +593,5 @@ self.emit('error', new Error('Malformed packet'), req);

// Incoming request
_req: null,
config: function(key) {

@@ -967,2 +990,3 @@

},
addOption: Options.addOption,
DHCPDISCOVER: DHCPDISCOVER,

@@ -969,0 +993,0 @@ DHCPOFFER: DHCPOFFER,

@@ -466,2 +466,7 @@

},*/
95: {
name: 'LDAP Servers',
type: 'IPs',
config: 'ldapServer'
},
116: {// RFC 2563: https://tools.ietf.org/html/rfc2563

@@ -496,3 +501,29 @@ name: 'Auto-Configure',

},
252: { // https://en.wikipedia.org/wiki/Web_Proxy_Auto-Discovery_Protocol
208: {// https://tools.ietf.org/html/rfc5071
name: 'PXE Magic Option',
type: 'UInt32',
config: 'pxeMagicOption',
default: 0xF100747E
},
209: {// https://tools.ietf.org/html/rfc5071
name: 'PXE Config File',
type: 'ASCII',
config: 'pxeConfigFile'
},
210: {// https://tools.ietf.org/html/rfc5071
name: 'PXE Path Prefix',
type: 'ASCII',
config: 'pxePathPrefix'
},
211: {// https://tools.ietf.org/html/rfc5071
name: 'PXE Reboot Time',
type: 'UInt32',
config: 'pxeRebootTime'
},
249: {// https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-dhcpe/f9c19c79-1c7f-4746-b555-0c0fc523f3f9
name: 'Microsoft Classless Static Route Option',
type: 'ASCII',
config: 'classlessStaticRoute'
},
252: {// https://en.wikipedia.org/wiki/Web_Proxy_Auto-Discovery_Protocol
name: 'Web Proxy Auto-Discovery',

@@ -517,14 +548,22 @@ type: 'ASCII',

const attr = {};
for (let i in opts) {
if (opts[i].config) {
conf[opts[i].config] = parseInt(i, 10);
} else if (opts[i].attr) {
conf[opts[i].config] = parseInt(i, 10);
function addOption(code, opt) {
opts[code] = opt;
if (opt.config) {
conf[opt.config] = parseInt(code, 10);
} else if (opt.attr) {
conf[opt.attr] = parseInt(code, 10);
}
}
for (let i in opts) {
addOption(i, opts[i]);
}
module.exports = {
opts: opts, // id -> config
conf: conf, // conf option -> id
attr: attr // attr name -> id
attr: attr, // attr name -> id
addOption: addOption
};
/**
* @license DHCP.js v0.2.18 28/06/2017
* @license DHCP.js v0.2.19 28/06/2017
* http://www.xarg.org/2017/06/a-pure-javascript-dhcp-implementation/

@@ -4,0 +4,0 @@ *

/**
* @license DHCP.js v0.2.18 28/06/2017
* @license DHCP.js v0.2.19 28/06/2017
* http://www.xarg.org/2017/06/a-pure-javascript-dhcp-implementation/

@@ -4,0 +4,0 @@ *

{
"name": "dhcp",
"title": "dhcp",
"version": "0.2.18",
"version": "0.2.19",
"homepage": "https://github.com/infusion/node-dhcp",

@@ -6,0 +6,0 @@ "bugs": {

@@ -10,3 +10,2 @@

Motivation

@@ -27,3 +26,2 @@ ===

Usage

@@ -67,2 +65,4 @@ ===

],
forceOptions: ['hostname'], // Options that need to be sent, even if they were not requested
randomIP: true, // Get random new IP from pool instead of keeping one ip
static: {

@@ -77,4 +77,10 @@ "11:22:33:44:55:66": "192.168.3.100"

],
bootFile: function (req) {
dns: ["8.8.8.8", "8.8.4.4"],
hostname: "kacknup",
broadcast: '192.168.0.255',
server: '192.168.0.1', // This is us
bootFile: function (req, res) {
// res.ip - the actual ip allocated for the client
if (req.clientId === 'foo bar') {

@@ -140,8 +146,47 @@ return 'x86linux.0';

Docker
===
Quick test
---
```bash
# Build the image
docker build -t infusion/node-dhcp:0 .
# Start the server
docker run -d --name dhcpd infusion/node-dhcp:0
# Start a client in the container (and send process to background)
docker exec dhcpd dhcp hostname --mac 12:23:34:45:56:67 &
# Show the server logs
docker logs dhcpd
```
Configuration assuming Host broadcast
---
Assuming the dhcp server is on a broadcast network:
```bash
# Build the image
docker build -t infusion/node-dhcp:0 .
# Start the server
docker run --net=host -d --name dhcpd infusion/node-dhcp:0
```
Configuration assuming router DHCP relay
---
Assuming a router is relaying DHCP to multiple IP addresses on server host:
```bash
# Build the image
docker build -t infusion/node-dhcp:0 .
# Start the servers
docker run -p the.host.ip:67:67/udp -d --name dhcpd1 infusion/node-dhcp:0
docker run -p other.host.ip:67:67/udp -d --name dhcpd2 infusion/node-dhcp:0
```
Installation
===
Installing node-dhcp is as easy as cloning this repo or use npmjs:

@@ -169,4 +214,2 @@

Not yet implemented features

@@ -177,3 +220,2 @@ ===

Troubleshooting

@@ -187,3 +229,2 @@ ===

No data is received

@@ -196,2 +237,3 @@ ---

---
```bash

@@ -203,2 +245,3 @@ route add -host 255.255.255.255 dev eth0

---
```bash

@@ -208,5 +251,19 @@ sudo route add -host 255.255.255.255 -interface en4

DHCP Options
---
A wide range of options are already implemented. Custom options can be defined with
```js
const dhcpd = require("dhcp")
dhcpd.addOption(123, {
config: "testConfig",
type: "ASCII",
name: "Test Option"
});
```
Testing
===
If you plan to enhance the library, make sure you add test cases and all the previous tests are passing. You can test the library with

@@ -220,3 +277,4 @@

===
Copyright (c) 2017, [Robert Eisele](http://www.xarg.org/)
Dual licensed under the MIT or GPL Version 2 licenses.
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc