mirror of
https://github.com/ZeroTier/ZeroTierOne
synced 2025-08-22 06:14:02 -07:00
Add a couple quick functions for converting a uint64_t network ID/node ID into std::string
This commit is contained in:
parent
54f339f0c0
commit
97e53b3cec
2 changed files with 29 additions and 0 deletions
|
@ -17,6 +17,7 @@
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <inttypes.h>
|
||||||
|
|
||||||
#include "../node/Constants.hpp"
|
#include "../node/Constants.hpp"
|
||||||
#include "../node/Utils.hpp"
|
#include "../node/Utils.hpp"
|
||||||
|
@ -66,6 +67,18 @@ unsigned int OSUtils::ztsnprintf(char *buf,unsigned int len,const char *fmt,...)
|
||||||
return (unsigned int)n;
|
return (unsigned int)n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string OSUtils::networkIDStr(const uint64_t nwid) {
|
||||||
|
char tmp[32] = {};
|
||||||
|
ztsnprintf(tmp, sizeof(tmp), "%.16" PRIx64, nwid);
|
||||||
|
return std::string(tmp);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string OSUtils::nodeIDStr(const uint64_t nid) {
|
||||||
|
char tmp[32] = {};
|
||||||
|
ztsnprintf(tmp, sizeof(tmp), "%.10" PRIx64, nid);
|
||||||
|
return std::string(tmp);
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef __UNIX_LIKE__
|
#ifdef __UNIX_LIKE__
|
||||||
bool OSUtils::redirectUnixOutputs(const char *stdoutPath,const char *stderrPath)
|
bool OSUtils::redirectUnixOutputs(const char *stdoutPath,const char *stderrPath)
|
||||||
throw()
|
throw()
|
||||||
|
|
|
@ -68,6 +68,22 @@ public:
|
||||||
*/
|
*/
|
||||||
static unsigned int ztsnprintf(char *buf,unsigned int len,const char *fmt,...);
|
static unsigned int ztsnprintf(char *buf,unsigned int len,const char *fmt,...);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts a uint64_t network ID into a string
|
||||||
|
*
|
||||||
|
* @param nwid network ID
|
||||||
|
* @throws std::length_error buf[] too short (buf[] will still be left null-terminated)
|
||||||
|
*/
|
||||||
|
static std::string networkIDStr(const uint64_t nwid);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts a uint64_t node ID into a string
|
||||||
|
*
|
||||||
|
* @param nid node ID
|
||||||
|
* @throws std::length_error buf[] too short (buf[] will still be left null-terminated)
|
||||||
|
*/
|
||||||
|
static std::string nodeIDStr(const uint64_t nid);
|
||||||
|
|
||||||
#ifdef __UNIX_LIKE__
|
#ifdef __UNIX_LIKE__
|
||||||
/**
|
/**
|
||||||
* Close STDOUT_FILENO and STDERR_FILENO and replace them with output to given path
|
* Close STDOUT_FILENO and STDERR_FILENO and replace them with output to given path
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue