summaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
authorTing-Yu Wang <anivia@google.com>2020-04-15 14:30:20 -0700
committergVisor bot <gvisor-bot@google.com>2020-04-15 14:31:36 -0700
commitea5b8e9633cd2731bb5656dea523beaf3d643472 (patch)
treefbf514d89eb88aeb1bb0958c07dc057d1a7e55ed /test
parent1bcc2bf17f0e2ccf8e98e934cb9f9ce66711d27a (diff)
Use if_nametoindex to get interface index.
Removed the TODO to use netlink. PiperOrigin-RevId: 306721468
Diffstat (limited to 'test')
-rw-r--r--test/syscalls/linux/ip_socket_test_util.cc12
1 files changed, 5 insertions, 7 deletions
diff --git a/test/syscalls/linux/ip_socket_test_util.cc b/test/syscalls/linux/ip_socket_test_util.cc
index d28dc0db6..98d07ae85 100644
--- a/test/syscalls/linux/ip_socket_test_util.cc
+++ b/test/syscalls/linux/ip_socket_test_util.cc
@@ -16,7 +16,6 @@
#include <net/if.h>
#include <netinet/in.h>
-#include <sys/ioctl.h>
#include <sys/socket.h>
#include <cstring>
@@ -35,12 +34,11 @@ uint16_t PortFromInetSockaddr(const struct sockaddr* addr) {
}
PosixErrorOr<int> InterfaceIndex(std::string name) {
- // TODO(igudger): Consider using netlink.
- ifreq req = {};
- memcpy(req.ifr_name, name.c_str(), name.size());
- ASSIGN_OR_RETURN_ERRNO(auto sock, Socket(AF_INET, SOCK_DGRAM, 0));
- RETURN_ERROR_IF_SYSCALL_FAIL(ioctl(sock.get(), SIOCGIFINDEX, &req));
- return req.ifr_ifindex;
+ int index = if_nametoindex(name.c_str());
+ if (index) {
+ return index;
+ }
+ return PosixError(errno);
}
namespace {