Example of setting a DHCP option in ESP8266 using the Arduino libraries

324 Views Asked by At

I want to set some DHCP options on an ESP8266 but I can't seem to figure out the syntax.

I can get the DHCP Server object:

   DhcpServer dhcp = WiFi.softAPDhcpServer();

The DhcpServer class is defined in LwipDhcpServer.h and shows an OptionsBuffer struct and various add methods, but nothing I try gets past the compiler.

From a pseudo code perspective, I'm after something like:

WiFi.softAPDhcpServer().OptionsBuffer.add (option, payload, size);

The relevant portion of the header is:

class DhcpServer
{
public:
    static constexpr int    DefaultLeaseTime = 720;         // minutes
    static constexpr uint32 MagicCookie      = 0x63538263;  // https://tools.ietf.org/html/rfc1497
                                                            //
    struct OptionsBuffer
    {
        OptionsBuffer(uint8_t* begin, uint8_t* end) : _it(begin), _begin(begin), _end(end) { }

        OptionsBuffer& add(uint8_t code, const uint8_t* data, size_t size);

        OptionsBuffer& add(uint8_t code, const char* data, size_t size)
        {
            return add(code, reinterpret_cast<const uint8_t*>(data), size);
        }
        ...
0

There are 0 best solutions below