1

I've dealing with an ESP32 module (ESP-IDF) trying to connect via Wifi and ethernet to a dhcp server. The point is, I'm trying to get the DHCP options, but I failed...

I tried using LWIP and also ESP-NETIF. (I have also to guess whats XXXX and YYYY)

// Create an esp_netif pointer to store current interface
  esp_netif_t* ifscan = esp_netif_next(NULL);

  // Stores the unique interface descriptor, such as "PP1", etc
  char ifdesc[7];
  ifdesc[6] = 0;  // Ensure null terminated string
  uint32_t value = 0;

  while (ifscan != NULL)
  {
      esp_netif_get_netif_impl_name(ifscan, ifdesc);
      Serial.printf("IF NAME: %s\n", ifdesc);

      esp_err_t code = esp_netif_dhcpc_option(ifscan, ESP_NETIF_OP_GET, ESP_NETIF_DOMAIN_NAME_SERVER, XXXX, YYYY);
      Serial.printf("RES: %s - OPTION: %s\n", esp_err_to_name(code), XXXXX);
   


      // Get the next interface
      ifscan = esp_netif_next(ifscan);
  }
      Serial.printf("Done listing network interfaces");

Does anyone have an example of sourcecode showing how to get the options after connecting?

Thank you in advance.

1 Answer 1

1

There are only a couple of DHCP options implemented in code.
Check the source code (github) for esp_netif_dhcpc_option.
ESP_NETIF_DOMAIN_NAME_SERVER e.q. is not.

For ESP_NETIF_OP_GET there is only ESP_NETIF_IP_REQUEST_RETRY_TIME and ESP_NETIF_VENDOR_SPECIFIC_INFO implemented.
Otherwise you get ESP_ERR_ESP_NETIF_INVALID_PARAMS (20481 0x5001) as a result.

esp_err_t esp_netif_dhcpc_option(esp_netif_t *esp_netif, esp_netif_dhcp_option_mode_t opt_op, esp_netif_dhcp_option_id_t opt_id, void *opt_val,
                                 uint32_t opt_len)
{
...
    if (opt_op == ESP_NETIF_OP_GET) {
        if (esp_netif->dhcpc_status == ESP_NETIF_DHCP_STOPPED) {
            return ESP_ERR_ESP_NETIF_DHCP_ALREADY_STOPPED;
        }
        switch (opt_id) {
            case ESP_NETIF_IP_REQUEST_RETRY_TIME:
                if (opt_len == sizeof(dhcp->tries)) {
                    *(uint8_t *)opt_val = dhcp->tries;
                }
                break;
#if ESP_DHCP && !ESP_DHCP_DISABLE_VENDOR_CLASS_IDENTIFIER
            case ESP_NETIF_VENDOR_SPECIFIC_INFO:
                return dhcp_get_vendor_specific_information(opt_len, opt_val);
#endif
            default:
                return ESP_ERR_ESP_NETIF_INVALID_PARAMS;
        }
...
}

I tried with your code and option 224 on my ESP32

  Serial.println("Option >");
  esp_err_t result = 0;
  uint32_t value = 0;
  esp_netif_t * ifscan = esp_netif_next(NULL);
  char ifname[10];
  result = esp_netif_get_netif_impl_name(ifscan, ifname);
  Serial.print("esp_netif_get_netif_impl_name: ");
  Serial.println(result);
  result = esp_netif_dhcpc_option(ifscan, ESP_NETIF_OP_GET, (esp_netif_dhcp_option_id_t)224, &value, 4);
  Serial.print("esp_netif_dhcpc_option: ");
  Serial.println(result);
  Serial.print("esp_netif_dhcpc_option value: ");
  Serial.println(value);
  Serial.println("Option <");

Result:

Option >
esp_netif_get_netif_impl_name: 0
esp_netif_dhcpc_option: 20481
esp_netif_dhcpc_option value: 0
Option <
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.