Skip to content

ONME-4433 SocketAddress::operator== should also check port #12120

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ TEST_F(Test_IfaceDnsSocket, async_cancel)

TEST_F(Test_IfaceDnsSocket, add_server)
{
SocketAddress server_address("1.2.3.4", 8000);
SocketAddress server_address("1.2.3.4", 53);
EXPECT_EQ(NSAPI_ERROR_OK, nsapi_dns_add_server(server_address, NULL));
EXPECT_EQ(NSAPI_ERROR_OK, nsapi_dns_add_server(server_address, NULL)); // Duplicate add - no error.

Expand Down Expand Up @@ -533,7 +533,7 @@ TEST_F(Test_IfaceDnsSocket, attempts)
SocketAddress known_server_address[DNS_SERVER_SIZE];
for (uint8_t i = DNS_SERVER_SIZE; i > 0; i--) {
uint8_t bytes[NSAPI_IPv4_SIZE] = {i, i, i, i};
known_server_address[i - 1] = SocketAddress(bytes, NSAPI_IPv4);
known_server_address[i - 1] = SocketAddress(bytes, NSAPI_IPv4, 53);
EXPECT_EQ(NSAPI_ERROR_OK, nsapi_dns_add_server(known_server_address[i - 1], NULL));
}

Expand Down Expand Up @@ -573,7 +573,7 @@ TEST_F(Test_IfaceDnsSocket, retries_attempts)
SocketAddress known_server_address[DNS_SERVER_SIZE];
for (uint8_t i = DNS_SERVER_SIZE; i > 0; i--) {
uint8_t bytes[NSAPI_IPv4_SIZE] = {i, i, i, i};
known_server_address[i - 1] = SocketAddress(bytes, NSAPI_IPv4);
known_server_address[i - 1] = SocketAddress(bytes, NSAPI_IPv4, 53);
EXPECT_EQ(NSAPI_ERROR_OK, nsapi_dns_add_server(known_server_address[i - 1], NULL));
}

Expand Down
2 changes: 2 additions & 0 deletions features/netsocket/SocketAddress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@ bool operator==(const SocketAddress &a, const SocketAddress &b)
return true;
} else if (a._addr.version != b._addr.version) {
return false;
} else if (a._port != b._port) {
return false;
} else if (a._addr.version == NSAPI_IPv4) {
return memcmp(a._addr.bytes, b._addr.bytes, NSAPI_IPv4_BYTES) == 0;
} else if (a._addr.version == NSAPI_IPv6) {
Expand Down