-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: add tr_address::fromSockaddr() (#3964)
* refactor: remove TR_DISCARD_ALIGN * refactor: add tr_address::fromSockaddr()
- Loading branch information
Showing
8 changed files
with
79 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// This file Copyright (C) 2013-2022 Mnemosyne LLC. | ||
// It may be used under GPLv2 (SPDX: GPL-2.0-only), GPLv3 (SPDX: GPL-3.0-only), | ||
// or any future license endorsed by Mnemosyne LLC. | ||
// License text can be found in the licenses/ folder. | ||
|
||
#include "transmission.h" | ||
|
||
#include "net.h" | ||
|
||
#include "test-fixtures.h" | ||
|
||
using NetTest = ::testing::Test; | ||
using namespace std::literals; | ||
|
||
TEST_F(NetTest, conversionsIPv4) | ||
{ | ||
auto constexpr port = tr_port::fromHost(80); | ||
auto constexpr addrstr = "127.0.0.1"sv; | ||
|
||
auto addr = tr_address::fromString(addrstr); | ||
EXPECT_TRUE(addr); | ||
EXPECT_EQ(addrstr, addr->readable()); | ||
|
||
auto [ss, sslen] = addr->toSockaddr(port); | ||
EXPECT_EQ(AF_INET, ss.ss_family); | ||
EXPECT_EQ(port.network(), reinterpret_cast<sockaddr_in const*>(&ss)->sin_port); | ||
|
||
auto addrport = tr_address::fromSockaddr(reinterpret_cast<sockaddr const*>(&ss)); | ||
EXPECT_TRUE(addrport); | ||
EXPECT_EQ(addr, addrport->first); | ||
EXPECT_EQ(port, addrport->second); | ||
} |