git: 383d51d59236 - main - unix tests: Add a regression test for getpeername(2)
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Wed, 21 Jun 2023 18:41:05 UTC
The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=383d51d592369f92b836f77abf8f118ab4e44ff1 commit 383d51d592369f92b836f77abf8f118ab4e44ff1 Author: Mark Johnston <markj@FreeBSD.org> AuthorDate: 2023-06-21 18:33:52 +0000 Commit: Mark Johnston <markj@FreeBSD.org> CommitDate: 2023-06-21 18:39:36 +0000 unix tests: Add a regression test for getpeername(2) Ensure that it works as expected when applied to a self-connected socket. MFC after: 1 week Sponsored by: The FreeBSD Foundation --- tests/sys/kern/unix_dgram.c | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/tests/sys/kern/unix_dgram.c b/tests/sys/kern/unix_dgram.c index 93669a30d4c5..9df0d4ca7168 100644 --- a/tests/sys/kern/unix_dgram.c +++ b/tests/sys/kern/unix_dgram.c @@ -36,6 +36,7 @@ #include <errno.h> #include <fcntl.h> #include <signal.h> +#include <stdio.h> #include <stdlib.h> #include <atf-c.h> @@ -363,12 +364,39 @@ ATF_TC_BODY(event, tc) test42(fd[0]); } -ATF_TP_ADD_TCS(tp) +ATF_TC_WITHOUT_HEAD(selfgetpeername); +ATF_TC_BODY(selfgetpeername, tc) { + struct sockaddr_un sun; + const char *name; + socklen_t len; + int sd; + + name = "selfgetpeername"; + + sd = socket(PF_UNIX, SOCK_DGRAM, 0); + ATF_REQUIRE(sd != -1); + + memset(&sun, 0, sizeof(sun)); + sun.sun_len = sizeof(sun); + sun.sun_family = AF_UNIX; + snprintf(sun.sun_path, sizeof(sun.sun_path), "%s", name); + ATF_REQUIRE(bind(sd, (struct sockaddr *)&sun, sizeof(sun)) == 0); + ATF_REQUIRE(connect(sd, (struct sockaddr *)&sun, sizeof(sun)) == 0); + + len = sizeof(sun); + ATF_REQUIRE(getpeername(sd, (struct sockaddr *)&sun, &len) == 0); + ATF_REQUIRE(strcmp(sun.sun_path, name) == 0); + ATF_REQUIRE(close(sd) == 0); +} + +ATF_TP_ADD_TCS(tp) +{ ATF_TP_ADD_TC(tp, basic); ATF_TP_ADD_TC(tp, one2many); ATF_TP_ADD_TC(tp, event); + ATF_TP_ADD_TC(tp, selfgetpeername); return (atf_no_error()); }