DHCP options IP address byte order

I'm using nx_dhcp_user_option_retrieve(NX_DHCP *dhcp_ptr, UINT request_option, UCHAR *destination_ptr, UINT *destination_size) to get option from the DHCP server.  I'm retrieving these options:

7 - log ip server

42 - ntp server

54 - server id

150 - tftp server

Each of these options return an IP address.  Options 42 and 54 are defined in nxd_dhcp_client.h.  The other 2 are not.

I noticed with 42 and 54, the ip data is returned in host byte order (little endian) but with option 7 and 150, the ip data is returned in network byte order.  Is there a reason for this?  Is this because options 42 and 54 are recognized (defined in header file) and extra processing is done?  I'm afraid that option 7 and 150 will be recognized in the future and data bytes swapped causing issues.

  • The code in github.com/.../nxd_dhcp_client.c line 4419
    does agree with what you have observed, for some known options, datas are reversed, while the remaining are simply copied over.


    /* Check to see which option data is requested: */
    switch (option_request)
    {

    case NX_DHCP_OPTION_NTP_SVR:
    … _nx_dhcp_get_data()
    default:
    .. memcpy()
    }

    No idea why it was done. Perhaps, in their code, they need to make use of the retrieved data, for other case, they just don't care about them.
  • Bye,
    can I ask you if you can share the portion of your code in which you retrieve the parameters transmitted by the server ?
    I was looking for an example of use but I couldn't find any and I have some doubts.

    Thanks in advance,
    Simone
  • CS Yep, thanks for pointing to the source.
    Simone, to get option 54, use nx_dhcp_user_option_retrieve(&my_dhcp, NX_DHCP_OPTION_DNS_SVR, dns_ip_string, &size); The define NX_DHCP_OPTION_DNS_SVR is 54. The ip address is returned in dns_ip_string. The size is how many bytes available to fill and on return, how many bytes are filled.