Skip to content

Commit 4a0cbd9

Browse files
author
Andrew Boie
committed
net: add missing syscall for gethostname()
We need all the socket APIs to work from user mode. tests/net/socket/misc now runs in userspace. Fixes: #15227 Signed-off-by: Andrew Boie <[email protected]>
1 parent e8ad181 commit 4a0cbd9

File tree

4 files changed

+12
-4
lines changed

4 files changed

+12
-4
lines changed

include/net/socket.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ int zsock_setsockopt(int sock, int level, int optname,
382382
* if :option:`CONFIG_NET_SOCKETS_POSIX_NAMES` is defined.
383383
* @endrststar
384384
*/
385-
int zsock_gethostname(char *buf, size_t len);
385+
__syscall int zsock_gethostname(char *buf, size_t len);
386386

387387
/**
388388
* @brief Convert network address from internal to numeric ASCII form

subsys/net/lib/sockets/sockets_misc.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,21 @@
66

77
#include <errno.h>
88
#include <net/socket.h>
9+
#include <syscall_handler.h>
910

10-
int zsock_gethostname(char *buf, size_t len)
11+
int z_impl_zsock_gethostname(char *buf, size_t len)
1112
{
1213
const char *p = net_hostname_get();
1314

1415
strncpy(buf, p, len);
1516

1617
return 0;
1718
}
19+
20+
#ifdef CONFIG_USERSPACE
21+
Z_SYSCALL_HANDLER(zsock_gethostname, buf, len)
22+
{
23+
Z_OOPS(Z_SYSCALL_MEMORY_WRITE(buf, len));
24+
return z_impl_zsock_gethostname((char *)buf, len);
25+
}
26+
#endif

tests/net/socket/misc/prj.conf

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ CONFIG_NET_CONFIG_MY_IPV6_ADDR="2001:db8::1"
2323

2424
CONFIG_MAIN_STACK_SIZE=2048
2525
CONFIG_ZTEST=y
26-
CONFIG_TEST_USERSPACE=n
2726

2827
# User mode requirements
2928
CONFIG_HEAP_MEM_POOL_SIZE=128

tests/net/socket/misc/src/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ LOG_MODULE_REGISTER(net_test, CONFIG_NET_SOCKETS_LOG_LEVEL);
1616

1717
void test_gethostname(void)
1818
{
19-
static char buf[80];
19+
static ZTEST_BMEM char buf[80];
2020
int res;
2121

2222
res = gethostname(buf, sizeof(buf));

0 commit comments

Comments
 (0)