-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moved the function for finding host's FQDN(s) into util/
Extended the contract and the implementation of the function to allow a choice to return a single result or all findings. Migrated the only client of that function that existed before the move.
- Loading branch information
1 parent
db15f28
commit 110f6ee
Showing
4 changed files
with
98 additions
and
50 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
// -*- LSST-C++ -*- | ||
/* | ||
* LSST Data Management System | ||
* Copyright 2015 LSST Corporation. | ||
* | ||
* This product includes software developed by the | ||
* LSST Project (http://www.lsst.org/). | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the LSST License Statement and | ||
* the GNU General Public License along with this program. If not, | ||
* see <http://www.lsstcorp.org/LegalNotices/>. | ||
*/ | ||
// Class header | ||
#include "util/common.h" | ||
|
||
// Standard headers | ||
#include <netdb.h> | ||
#include <stdexcept> | ||
#include <string.h> | ||
#include <sys/types.h> | ||
#include <sys/socket.h> | ||
|
||
// Third-party headers | ||
#include "boost/asio.hpp" | ||
|
||
using namespace std; | ||
|
||
namespace lsst::qserv::util { | ||
|
||
string get_current_host_fqdn(bool all) { | ||
// Get the short name of the current host first. | ||
boost::system::error_code ec; | ||
string const hostname = boost::asio::ip::host_name(ec); | ||
if (ec.value() != 0) { | ||
throw runtime_error("Registry::" + string(__func__) + | ||
" boost::asio::ip::host_name failed: " + ec.category().name() + string(":") + | ||
to_string(ec.value()) + "[" + ec.message() + "]"); | ||
} | ||
|
||
// Get the host's FQDN(s) | ||
struct addrinfo hints; | ||
memset(&hints, 0, sizeof hints); | ||
hints.ai_family = AF_UNSPEC; /* either IPV4 or IPV6 */ | ||
hints.ai_socktype = SOCK_STREAM; /* IP */ | ||
hints.ai_flags = AI_CANONNAME; /* canonical name */ | ||
struct addrinfo* info; | ||
while (true) { | ||
int const retCode = getaddrinfo(hostname.data(), "http", &hints, &info); | ||
if (retCode == 0) break; | ||
if (retCode == EAI_AGAIN) continue; | ||
throw runtime_error("Registry::" + string(__func__) + | ||
" getaddrinfo failed: " + gai_strerror(retCode)); | ||
} | ||
string fqdn; | ||
for (struct addrinfo* p = info; p != NULL; p = p->ai_next) { | ||
if (!fqdn.empty()) { | ||
if (!all) break; | ||
fqdn += ","; | ||
} | ||
fqdn += p->ai_canonname; | ||
} | ||
freeaddrinfo(info); | ||
return fqdn; | ||
} | ||
|
||
} // namespace lsst::qserv::util |
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