infusion / node-dhcp

A DHCP server and client written in pure JavaScript
https://raw.org/article/a-pure-javascript-dhcp-implementation/
MIT License
301 stars 75 forks source link

Cannot read property 'address' of undefined #44

Closed nistorj closed 5 years ago

nistorj commented 5 years ago

Hi,

Had a weird issue happen today with the following output:

flags: 0, ciaddr: '0.0.0.0', yiaddr: '0.0.0.0', siaddr: '0.0.0.0', giaddr: '0.0.0.0', chaddr: '98-4B-E1-6D-20-51', sname: '', file: '', magicCookie: 1669485411, options: { '12': 'finnix', '53': 1, '55': [ 1, 28, 2, 3, 15, 6, 119, 12, 44, 47, 26, 121, 42 ] } } /home/nistor/node_modules/dhcp/lib/dhcp.js:302 const ip = this._state[oldestMac].address; ^ TypeError: Cannot read property 'address' of undefined at Server._selectAddress (/home/nistor/node_modules/dhcp/lib/dhcp.js:302:41) at Server.handleDiscover (/home/nistor/node_modules/dhcp/lib/dhcp.js:343:26) at Socket. (/home/nistor/node_modules/dhcp/lib/dhcp.js:91:16) at Socket.emit (events.js:182:13) at UDP.onMessage [as onmessage] (dgram.js:628:8)

What is interesting is that it doesn't happen all that often from that host. Any idea?

infusion commented 5 years ago

Thanks for the issue. What really strange is that this can actually happen. But it depends on your config. So I added a check to go into that branch only if it is save to do so.