Skip to content

Commit c47de21

Browse files
Andrew Kontrafabiobaltieri
authored andcommitted
net: Using const char * in net_hostname_set()
When calling net_hostname_set() from C++, you will hit compile errors if you attempt to use a const char *. Since the internals of net_hostname_set() just uses memcpy(), we should pass in the new hostname as a const char * to better support C++. Tested using samples/cpp/hello_world, with an added call to net_hostname_set(). Signed-off-by: Andrew Kontra <[email protected]>
1 parent 15dabaa commit c47de21

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

include/zephyr/net/hostname.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,9 @@ static inline const char *net_hostname_get(void)
7676
* @return 0 if ok, <0 on error
7777
*/
7878
#if defined(CONFIG_NET_HOSTNAME_DYNAMIC)
79-
int net_hostname_set(char *host, size_t len);
79+
int net_hostname_set(const char *host, size_t len);
8080
#else
81-
static inline int net_hostname_set(char *host, size_t len)
81+
static inline int net_hostname_set(const char *host, size_t len)
8282
{
8383
ARG_UNUSED(host);
8484
ARG_UNUSED(len);

subsys/net/hostname.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ const char *net_hostname_get(void)
4343
}
4444

4545
#if defined(CONFIG_NET_HOSTNAME_DYNAMIC)
46-
int net_hostname_set(char *host, size_t len)
46+
int net_hostname_set(const char *host, size_t len)
4747
{
4848
if (len > NET_HOSTNAME_MAX_LEN) {
4949
return -ENOMEM;

0 commit comments

Comments
 (0)