summaryrefslogtreecommitdiffhomepage
path: root/test/syscalls/linux/raw_socket_icmp.cc
diff options
context:
space:
mode:
authorNayana Bidari <nybidari@google.com>2020-09-17 19:58:27 -0700
committergVisor bot <gvisor-bot@google.com>2020-09-17 20:00:33 -0700
commitd34bda027309695e3e6fb6f92a5839cd1f21173e (patch)
tree529a895b38281bba659ffed2d269d683f0784544 /test/syscalls/linux/raw_socket_icmp.cc
parentc0b74be54c336f53ff3596acad2c57330a63c6b1 (diff)
{Set,Get} SO_LINGER on all endpoints.
SO_LINGER is a socket level option and should be stored on all endpoints even though it is used to linger only for TCP endpoints. PiperOrigin-RevId: 332369252
Diffstat (limited to 'test/syscalls/linux/raw_socket_icmp.cc')
-rw-r--r--test/syscalls/linux/raw_socket_icmp.cc22
1 files changed, 22 insertions, 0 deletions
diff --git a/test/syscalls/linux/raw_socket_icmp.cc b/test/syscalls/linux/raw_socket_icmp.cc
index 3de898df7..1b9dbc584 100644
--- a/test/syscalls/linux/raw_socket_icmp.cc
+++ b/test/syscalls/linux/raw_socket_icmp.cc
@@ -416,6 +416,28 @@ TEST_F(RawSocketICMPTest, BindConnectSendAndReceive) {
ASSERT_NO_FATAL_FAILURE(ExpectICMPSuccess(icmp));
}
+// Set and get SO_LINGER.
+TEST_F(RawSocketICMPTest, SetAndGetSocketLinger) {
+ SKIP_IF(!ASSERT_NO_ERRNO_AND_VALUE(HaveCapability(CAP_NET_RAW)));
+
+ int level = SOL_SOCKET;
+ int type = SO_LINGER;
+
+ struct linger sl;
+ sl.l_onoff = 1;
+ sl.l_linger = 5;
+ ASSERT_THAT(setsockopt(s_, level, type, &sl, sizeof(sl)),
+ SyscallSucceedsWithValue(0));
+
+ struct linger got_linger = {};
+ socklen_t length = sizeof(sl);
+ ASSERT_THAT(getsockopt(s_, level, type, &got_linger, &length),
+ SyscallSucceedsWithValue(0));
+
+ ASSERT_EQ(length, sizeof(got_linger));
+ EXPECT_EQ(0, memcmp(&sl, &got_linger, length));
+}
+
void RawSocketICMPTest::ExpectICMPSuccess(const struct icmphdr& icmp) {
// We're going to receive both the echo request and reply, but the order is
// indeterminate.