diff options
Diffstat (limited to 'test/syscalls/linux/proc_net_tcp.cc')
-rw-r--r-- | test/syscalls/linux/proc_net_tcp.cc | 39 |
1 files changed, 19 insertions, 20 deletions
diff --git a/test/syscalls/linux/proc_net_tcp.cc b/test/syscalls/linux/proc_net_tcp.cc index cb81b4e6e..f61795592 100644 --- a/test/syscalls/linux/proc_net_tcp.cc +++ b/test/syscalls/linux/proc_net_tcp.cc @@ -269,16 +269,14 @@ struct TCP6Entry { }; bool IPv6AddrEqual(const struct in6_addr* a1, const struct in6_addr* a2) { - if (memcmp(a1, a2, sizeof(struct in6_addr)) == 0) - return true; - return false; + return memcmp(a1, a2, sizeof(struct in6_addr)) == 0; } // Finds the first entry in 'entries' for which 'predicate' returns true. // Returns true on match, and sets 'match' to a copy of the matching entry. If // 'match' is null, it's ignored. bool FindBy6(const std::vector<TCP6Entry>& entries, TCP6Entry* match, - std::function<bool(const TCP6Entry&)> predicate) { + std::function<bool(const TCP6Entry&)> predicate) { for (const TCP6Entry& entry : entries) { if (predicate(entry)) { if (match != nullptr) { @@ -305,7 +303,7 @@ bool FindByLocalAddr6(const std::vector<TCP6Entry>& entries, TCP6Entry* match, } bool FindByRemoteAddr6(const std::vector<TCP6Entry>& entries, TCP6Entry* match, - const struct sockaddr* addr) { + const struct sockaddr* addr) { const struct in6_addr* remote = IP6FromInetSockaddr(addr); uint16_t port = PortFromInetSockaddr(addr); return FindBy6(entries, match, [remote, port](const TCP6Entry& e) { @@ -315,14 +313,14 @@ bool FindByRemoteAddr6(const std::vector<TCP6Entry>& entries, TCP6Entry* match, void ReadIPv6Address(std::string s, struct in6_addr* addr) { uint32_t a0, a1, a2, a3; - const char *fmt = "%08X%08X%08X%08X"; + const char* fmt = "%08X%08X%08X%08X"; EXPECT_EQ(sscanf(s.c_str(), fmt, &a0, &a1, &a2, &a3), 4); - uint8_t *b = addr->s6_addr; - *((uint32_t *)&b[0]) = a0; - *((uint32_t *)&b[4]) = a1; - *((uint32_t *)&b[8]) = a2; - *((uint32_t *)&b[12]) = a3; + uint8_t* b = addr->s6_addr; + *((uint32_t*)&b[0]) = a0; + *((uint32_t*)&b[4]) = a1; + *((uint32_t*)&b[8]) = a2; + *((uint32_t*)&b[12]) = a3; } // Returns a parsed representation of /proc/net/tcp6 entries. @@ -429,7 +427,8 @@ TEST(ProcNetTCP6, InodeReasonable) { TCP6Entry accepted_entry; - ASSERT_TRUE(FindByLocalAddr6(entries, &accepted_entry, sockets->first_addr())); + ASSERT_TRUE( + FindByLocalAddr6(entries, &accepted_entry, sockets->first_addr())); EXPECT_NE(accepted_entry.inode, 0); TCP6Entry client_entry; @@ -481,14 +480,14 @@ TEST(ProcNetTCP6, State) { entries = ASSERT_NO_ERRNO_AND_VALUE(ProcNetTCP6Entries()); TCP6Entry accepted_entry; - ASSERT_TRUE(FindBy6(entries, &accepted_entry, - [client_entry, local, - accepted_local_port](const TCP6Entry& e) { - return IPv6AddrEqual(&e.local_addr, local) && - e.local_port == accepted_local_port && - IPv6AddrEqual(&e.remote_addr, &client_entry.local_addr) && - e.remote_port == client_entry.local_port; - })); + ASSERT_TRUE(FindBy6( + entries, &accepted_entry, + [client_entry, local, accepted_local_port](const TCP6Entry& e) { + return IPv6AddrEqual(&e.local_addr, local) && + e.local_port == accepted_local_port && + IPv6AddrEqual(&e.remote_addr, &client_entry.local_addr) && + e.remote_port == client_entry.local_port; + })); EXPECT_EQ(accepted_entry.state, TCP_ESTABLISHED); } |