boost::corosio::host_name

Return the local machine's hostname.

Synopsis

std::string
host_name();

Description

On POSIX systems this calls gethostname(2). On Windows this calls GetComputerNameExW(ComputerNameDnsHostname, ...) and converts the result from UTF‐16 to UTF‐8.

The function is synchronous and does not require an io_context. On Windows it does not require winsock to have been initialized.

Exception Safety

Strong guarantee.

Example

std::string h = boost::corosio::host_name();
std::cout << "running on " << h << "\n";

Exceptions

Name

Thrown on

std::runtime_error

If the underlying system call fails.

Return Value

The hostname as a UTF‐8 string.

Created with MrDocs