Skip to content

Commit

Permalink
Merge pull request #9214 from OatmealDome/macos-bind
Browse files Browse the repository at this point in the history
Top: Set port when connecting a socket to find the default interface
  • Loading branch information
leoetlino committed Nov 2, 2020
2 parents 5b9cd83 + dd688f4 commit cbaf8f8
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion Source/Core/Core/IOS/Network/IP/Top.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,10 @@ static std::optional<DefaultInterface> GetSystemDefaultInterface()
sockaddr_in addr{};
socklen_t length = sizeof(addr);
addr.sin_family = AF_INET;
// The address is irrelevant -- no packet is actually sent. This just needs to be a public IP.
// The address and port are irrelevant -- no packet is actually sent. These just need to be set
// to a valid IP and port.
addr.sin_addr.s_addr = inet_addr(8, 8, 8, 8);
addr.sin_port = htons(53);
if (connect(sock, reinterpret_cast<const sockaddr*>(&addr), sizeof(addr)) == -1)
return {};
if (getsockname(sock, reinterpret_cast<sockaddr*>(&addr), &length) == -1)
Expand Down

0 comments on commit cbaf8f8

Please sign in to comment.