diff options
| author | Jim Mussared <jim.mussared@gmail.com> | 2023-10-03 13:32:48 +1100 |
|---|---|---|
| committer | Damien George <damien@micropython.org> | 2023-10-04 12:39:51 +1100 |
| commit | 65a3ce39a31e5ed7e5634c6905ca981039f42cb3 (patch) | |
| tree | 73dea6741bfc01a7d99936ac9b5b2f8748b7a932 /extmod/modnetwork.h | |
| parent | b329fdcb7394f7a30cb81c48e04ba3d557d29396 (diff) | |
extmod/modnetwork: Forward if.config(hostname) to network.hostname.
This removes the duplicate code in cyw43, esp32, esp8266 that implements
the same logic as network.hostname.
Renames the `mod_network_hostname` (where we store the hostname value in
`.data`) to `mod_network_hostname_data` to make way for calling the shared
function `mod_network_hostname`.
And uses memcpy for mod_network_hostname_data, because the length of source
is already known and removes reliance on string data being null-terminated.
This work was funded through GitHub Sponsors.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
Diffstat (limited to 'extmod/modnetwork.h')
| -rw-r--r-- | extmod/modnetwork.h | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/extmod/modnetwork.h b/extmod/modnetwork.h index e9769e309..e3239c2a0 100644 --- a/extmod/modnetwork.h +++ b/extmod/modnetwork.h @@ -61,7 +61,12 @@ extern char mod_network_country_code[2]; #endif // This is a null-terminated string. -extern char mod_network_hostname[MICROPY_PY_NETWORK_HOSTNAME_MAX_LEN + 1]; +extern char mod_network_hostname_data[MICROPY_PY_NETWORK_HOSTNAME_MAX_LEN + 1]; + +// To support backwards-compatible (esp32, esp8266, cyw43) +// `if.config(hostname=...)` to forward directly to the implementation of +// `network.hostname(...)`. +mp_obj_t mod_network_hostname(size_t n_args, const mp_obj_t *args); #if MICROPY_PY_LWIP struct netif; |
