From 39470428dd3c5fef966cee138ae00ab8b9059983 Mon Sep 17 00:00:00 2001 From: Ghanan Gowripalan Date: Tue, 14 Sep 2021 17:17:17 -0700 Subject: Use a shared method to get loopback index Code to get the loopback interface's index is scattered throughout the syscall tests. Implement the code once and use that in tests (where applicable). While I am here, trim the dependencies/includes for network namespace tests. PiperOrigin-RevId: 396718124 --- test/syscalls/linux/packet_socket.cc | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'test/syscalls/linux/packet_socket.cc') diff --git a/test/syscalls/linux/packet_socket.cc b/test/syscalls/linux/packet_socket.cc index bfa5d179a..9515a48f2 100644 --- a/test/syscalls/linux/packet_socket.cc +++ b/test/syscalls/linux/packet_socket.cc @@ -29,6 +29,7 @@ #include "gtest/gtest.h" #include "absl/base/internal/endian.h" +#include "test/syscalls/linux/ip_socket_test_util.h" #include "test/syscalls/linux/unix_domain_socket_test_util.h" #include "test/util/capability_util.h" #include "test/util/cleanup.h" @@ -156,11 +157,9 @@ void CookedPacketTest::TearDown() { } int CookedPacketTest::GetLoopbackIndex() { - struct ifreq ifr; - snprintf(ifr.ifr_name, IFNAMSIZ, "lo"); - EXPECT_THAT(ioctl(socket_, SIOCGIFINDEX, &ifr), SyscallSucceeds()); - EXPECT_NE(ifr.ifr_ifindex, 0); - return ifr.ifr_ifindex; + int v = EXPECT_NO_ERRNO_AND_VALUE(gvisor::testing::GetLoopbackIndex()); + EXPECT_NE(v, 0); + return v; } // Receive and verify the message via packet socket on interface. -- cgit v1.2.3