Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for hostname request in lwIP interface #347

Merged
merged 2 commits into from
Sep 19, 2024

Conversation

guilhermerc
Copy link

Summary of changes

Add support for hostname request in lwIP interface.

There is a discussion about this functionality here: How to set device network hostname on MBED OS 6?

Impact of changes

Migration actions required

Documentation


Pull request type

[] Patch update (Bug fix / Target update / Docs update / Test update / Refactor)
[X] Feature update (New feature / Functionality change / New API)
[] Major update (Breaking change E.g. Return code change / API behaviour change)

Test results

[] No Tests required for this change (E.g docs only update)
[] Covered by existing mbed-os tests (Greentea or Unittest)
[X] Tests / results supplied as part of this PR

@guilhermerc
Copy link
Author

guilhermerc commented Sep 17, 2024

Follows an usage example. It was tested on both LPC1768 and NUCLEO_H743ZI2 targets.

#include "EthernetInterface.h"
#include "mbed.h"

int main() {
    EthernetInterface net;
    char hostname[] = "example-hostname";
    nsapi_error_t nsapi_status;

    nsapi_status = net.set_hostname(hostname);
    assert(nsapi_status == NSAPI_ERROR_OK);
    debug("[main] net.get_hostname: %s\n", net.get_hostname());

    do {
        ThisThread::sleep_for(5s);
        nsapi_status = net.connect();
        debug("[main] net.connect rc: %d\n", nsapi_status);
    } while(nsapi_status != NSAPI_ERROR_OK &&
        nsapi_status != NSAPI_ERROR_IS_CONNECTED);

    while(true) {}
}

@guilhermerc
Copy link
Author

I submitted this PR to ARM's repository right before Mbed OS EOL: ARMmbed#15506. Me and @multiplemonomials already had some discussion there.

@guilhermerc guilhermerc marked this pull request as ready for review September 17, 2024 17:35
Copy link
Collaborator

@multiplemonomials multiplemonomials left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Just one comment

In the same way it is done for setting MAC address, add methods for
setting hostname. The underlying network stack can then request this
to the local DNS through DHCP.
If hostname is provided, request it to local DNS through DHCP.
@guilhermerc
Copy link
Author

Fixed CI complaints.

@multiplemonomials multiplemonomials merged commit eca8047 into mbed-ce:master Sep 19, 2024
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants