33 #include <sys/types.h>
34 #include <sys/sysctl.h>
39 #include <boost/format.hpp>
41 #include <boost/date_time/posix_time/posix_time.hpp>
51 if (sysctlbyname(
"machdep.cpu.brand_string", &buffer, &size, 0, 0) != 0) {
52 throw std::runtime_error(boost::str(boost::format(
"sysctlbyname failed: %1%")
55 return std::string(buffer);
65 if (gethostuuid(
id, &wait) != 0) {
66 throw std::runtime_error(boost::str(boost::format(
"gethostuuid failed: %1%")
69 std::stringstream stream;
70 for (
unsigned int i = 0; i < 16; ++i) {
71 stream << std::hex << std::setw(2) << std::setfill(
'0') << (int)
id[i];
79 int mib[] = { CTL_KERN, KERN_BOOTTIME };
81 size_t len = (size_t)
sizeof(t);
82 if (sysctl(mib, 2, &t, &len, NULL, 0) != 0) {
83 throw std::runtime_error(boost::str(boost::format(
"Could not determine"
84 " computer boot time:"
88 return boost::posix_time::from_time_t(t.tv_sec) +
89 boost::posix_time::microseconds(t.tv_usec);
RSC_EXPORT std::string currentHostId()
Determine and return a unique id string of the local machine.
RSC_EXPORT boost::posix_time::ptime currentBootTime()
Return the boot time of the local machine.
RSC_EXPORT std::string currentMachineVersion()
Determine and return the version within its type, usually the CPU identification string, of the local machine.