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

not suppport for MacOS #59

Closed freepoi closed 5 years ago

freepoi commented 5 years ago

When i use my mac to connect to the network with wifi by DHCP, i can see the error:

Unknown option 95

I tried Android and Debian, those were OK.

freepoi commented 5 years ago

This was the message i got when messge emitted:

{
    "op": 1,
    "htype": 1,
    "hlen": 6,
    "hops": 0,
    "xid": 2189072989,
    "secs": 51,
    "flags": 0,
    "ciaddr": "0.0.0.0",
    "yiaddr": "0.0.0.0",
    "siaddr": "0.0.0.0",
    "giaddr": "0.0.0.0",
    "chaddr": "hi-de-th-is-hi-de",
    "sname": "",
    "file": "",
    "magicCookie": 1669485411,
    "options": {
        "12": "wudenggangdeMBP",
        "51": 7776000,
        "53": 1,
        "55": [
            1,
            121,
            3,
            6,
            15,
            119,
            252,
            95,
            44,
            46
        ],
        "57": 1500,
        "61": "\u0001\bi~`w:"
    }
}

my code:

    const server: DhcpServer = dhcp.createServer(options);
    server.on('message', data => {
      logger.info(data);
    });
   server.listen();
infusion commented 5 years ago

According to https://tools.ietf.org/html/rfc3679 it is an unsupported option by Apple. We can add it to dhcp.js though. What I can't figure out is if Apple uses this field as freetext or as a list of IP addresses. The latter would be cleaner. Could you please add the following to the options.js file to test if the format is correct?

  95: {
    name: 'LDAP Servers,
    type: 'IPs',
    config: 'ldapServer'
  },
freepoi commented 5 years ago

It's my mistake, I throw the error immediately in the handler for the error event, then the process of distributing the IP is interrupted by that. So my mac can't get the IP. I use

process.on('uncaughtException', () => {})

to prevent the program being crashed.

Now, I just ignore the error (Unknown option 95), and my mac get IP correctly.
Then I add the code provided by you, also works. The only thing i know is that the code won't cause issues.

infusion commented 5 years ago

Okay, that's nice to know. I'll add it to the main branch, but without a release so far. It will be on npm soon.

infusion commented 5 years ago

Okay, is added. Sorry for the error, but I want people to report such things in order to make the library more robust the more people that gets their hands on it.

freepoi commented 5 years ago

It's my mistake, I throw the error immediately in the handler for the error event, then the process of distributing the IP is interrupted by that. So my mac can't get the IP. I use

process.on('uncaughtException', () => {})

to prevent the program being crashed.

Now, I just ignore the error (Unknown option 95), and my mac get IP correctly. Then I add the code provided by you, also works. The only thing i know is that the code won't cause issues.

And what i have to point out is that: it works too , without your added code when I ignore the error instead of throwing it stupidly.