diff options
author | Ting-Yu Wang <anivia@google.com> | 2021-04-12 18:33:22 -0700 |
---|---|---|
committer | gVisor bot <gvisor-bot@google.com> | 2021-04-12 18:35:09 -0700 |
commit | e5f58e89bbd376469073c749592d0fb0e3b4c6cb (patch) | |
tree | 6015e2edf4229f85f8a8d247c791295837416b69 /test/syscalls/linux/tuntap.cc | |
parent | 90900e4f8f6760f1de34e660030a0155cfd6b40a (diff) |
Make AsSockAddr() to replace reinterpret_cast<sockaddr*>
It's a common pattern in test code to reinterpret_cast<sockaddr*> from
sockaddr_* structs. Make AsSockAddr() for them so code looks better.
Note: Why not a wrapper type for `sockaddr_storage` and etc?
It's also a common need to have a local in-out variable of socklen_t.
Creating a wrapper type may however lead to this wrong code:
Wrapper addr;
socklen_t addrlen = sizeof(addr);
where sizeof(Wrapper) may not equal to sizeof(sockaddr_storage).
PiperOrigin-RevId: 368126229
Diffstat (limited to 'test/syscalls/linux/tuntap.cc')
-rw-r--r-- | test/syscalls/linux/tuntap.cc | 5 |
1 files changed, 2 insertions, 3 deletions
diff --git a/test/syscalls/linux/tuntap.cc b/test/syscalls/linux/tuntap.cc index 13ed0d68a..93ee11870 100644 --- a/test/syscalls/linux/tuntap.cc +++ b/test/syscalls/linux/tuntap.cc @@ -397,8 +397,7 @@ TEST_F(TuntapTest, SendUdpTriggersArpResolution) { .sin_port = htons(42), .sin_addr = {.s_addr = kTapPeerIPAddr}, }; - ASSERT_THAT(sendto(sock, "hello", 5, 0, reinterpret_cast<sockaddr*>(&remote), - sizeof(remote)), + ASSERT_THAT(sendto(sock, "hello", 5, 0, AsSockAddr(&remote), sizeof(remote)), SyscallSucceeds()); struct inpkt { @@ -498,7 +497,7 @@ TEST_F(TuntapTest, WriteHangBug155928773) { .sin_addr = {.s_addr = kTapIPAddr}, }; // Return values do not matter in this test. - connect(sock, reinterpret_cast<struct sockaddr*>(&remote), sizeof(remote)); + connect(sock, AsSockAddr(&remote), sizeof(remote)); write(sock, "hello", 5); } |