mirror of
https://github.com/ZeroTier/ZeroTierOne
synced 2025-08-21 13:54:15 -07:00
Rename Utils::snprintf due to it being a #define on one platform.
This commit is contained in:
parent
02d18af57d
commit
355cce3938
26 changed files with 111 additions and 524 deletions
|
@ -114,8 +114,8 @@ BSDEthernetTap::BSDEthernetTap(
|
|||
|
||||
std::vector<std::string> devFiles(OSUtils::listDirectory("/dev"));
|
||||
for(int i=9993;i<(9993+128);++i) {
|
||||
Utils::snprintf(tmpdevname,sizeof(tmpdevname),"tap%d",i);
|
||||
Utils::snprintf(devpath,sizeof(devpath),"/dev/%s",tmpdevname);
|
||||
Utils::ztsnprintf(tmpdevname,sizeof(tmpdevname),"tap%d",i);
|
||||
Utils::ztsnprintf(devpath,sizeof(devpath),"/dev/%s",tmpdevname);
|
||||
if (std::find(devFiles.begin(),devFiles.end(),std::string(tmpdevname)) == devFiles.end()) {
|
||||
long cpid = (long)vfork();
|
||||
if (cpid == 0) {
|
||||
|
@ -152,8 +152,8 @@ BSDEthernetTap::BSDEthernetTap(
|
|||
/* Other BSDs like OpenBSD only have a limited number of tap devices that cannot be renamed */
|
||||
|
||||
for(int i=0;i<64;++i) {
|
||||
Utils::snprintf(tmpdevname,sizeof(tmpdevname),"tap%d",i);
|
||||
Utils::snprintf(devpath,sizeof(devpath),"/dev/%s",tmpdevname);
|
||||
Utils::ztsnprintf(tmpdevname,sizeof(tmpdevname),"tap%d",i);
|
||||
Utils::ztsnprintf(devpath,sizeof(devpath),"/dev/%s",tmpdevname);
|
||||
_fd = ::open(devpath,O_RDWR);
|
||||
if (_fd > 0) {
|
||||
_dev = tmpdevname;
|
||||
|
@ -171,9 +171,9 @@ BSDEthernetTap::BSDEthernetTap(
|
|||
}
|
||||
|
||||
// Configure MAC address and MTU, bring interface up
|
||||
Utils::snprintf(ethaddr,sizeof(ethaddr),"%.2x:%.2x:%.2x:%.2x:%.2x:%.2x",(int)mac[0],(int)mac[1],(int)mac[2],(int)mac[3],(int)mac[4],(int)mac[5]);
|
||||
Utils::snprintf(mtustr,sizeof(mtustr),"%u",_mtu);
|
||||
Utils::snprintf(metstr,sizeof(metstr),"%u",_metric);
|
||||
Utils::ztsnprintf(ethaddr,sizeof(ethaddr),"%.2x:%.2x:%.2x:%.2x:%.2x:%.2x",(int)mac[0],(int)mac[1],(int)mac[2],(int)mac[3],(int)mac[4],(int)mac[5]);
|
||||
Utils::ztsnprintf(mtustr,sizeof(mtustr),"%u",_mtu);
|
||||
Utils::ztsnprintf(metstr,sizeof(metstr),"%u",_metric);
|
||||
long cpid = (long)vfork();
|
||||
if (cpid == 0) {
|
||||
::execl("/sbin/ifconfig","/sbin/ifconfig",_dev.c_str(),"lladdr",ethaddr,"mtu",mtustr,"metric",metstr,"up",(const char *)0);
|
||||
|
@ -385,7 +385,7 @@ void BSDEthernetTap::setMtu(unsigned int mtu)
|
|||
long cpid = (long)vfork();
|
||||
if (cpid == 0) {
|
||||
char tmp[64];
|
||||
Utils::snprintf(tmp,sizeof(tmp),"%u",mtu);
|
||||
Utils::ztsnprintf(tmp,sizeof(tmp),"%u",mtu);
|
||||
execl("/sbin/ifconfig","/sbin/ifconfig",_dev.c_str(),"mtu",tmp,(const char *)0);
|
||||
_exit(-1);
|
||||
} else if (cpid > 0) {
|
||||
|
|
|
@ -244,10 +244,10 @@ unsigned int Http::_do(
|
|||
|
||||
try {
|
||||
char tmp[1024];
|
||||
Utils::snprintf(tmp,sizeof(tmp),"%s %s HTTP/1.1\r\n",method,path);
|
||||
Utils::ztsnprintf(tmp,sizeof(tmp),"%s %s HTTP/1.1\r\n",method,path);
|
||||
handler.writeBuf.append(tmp);
|
||||
for(std::map<std::string,std::string>::const_iterator h(requestHeaders.begin());h!=requestHeaders.end();++h) {
|
||||
Utils::snprintf(tmp,sizeof(tmp),"%s: %s\r\n",h->first.c_str(),h->second.c_str());
|
||||
Utils::ztsnprintf(tmp,sizeof(tmp),"%s: %s\r\n",h->first.c_str(),h->second.c_str());
|
||||
handler.writeBuf.append(tmp);
|
||||
}
|
||||
handler.writeBuf.append("\r\n");
|
||||
|
|
|
@ -97,7 +97,7 @@ LinuxEthernetTap::LinuxEthernetTap(
|
|||
char procpath[128],nwids[32];
|
||||
struct stat sbuf;
|
||||
|
||||
Utils::snprintf(nwids,sizeof(nwids),"%.16llx",nwid);
|
||||
Utils::ztsnprintf(nwids,sizeof(nwids),"%.16llx",nwid);
|
||||
|
||||
Mutex::Lock _l(__tapCreateLock); // create only one tap at a time, globally
|
||||
|
||||
|
@ -134,7 +134,7 @@ LinuxEthernetTap::LinuxEthernetTap(
|
|||
std::map<std::string,std::string>::const_iterator gdmEntry = globalDeviceMap.find(nwids);
|
||||
if (gdmEntry != globalDeviceMap.end()) {
|
||||
Utils::scopy(ifr.ifr_name,sizeof(ifr.ifr_name),gdmEntry->second.c_str());
|
||||
Utils::snprintf(procpath,sizeof(procpath),"/proc/sys/net/ipv4/conf/%s",ifr.ifr_name);
|
||||
Utils::ztsnprintf(procpath,sizeof(procpath),"/proc/sys/net/ipv4/conf/%s",ifr.ifr_name);
|
||||
recalledDevice = (stat(procpath,&sbuf) != 0);
|
||||
}
|
||||
|
||||
|
@ -142,8 +142,8 @@ LinuxEthernetTap::LinuxEthernetTap(
|
|||
#ifdef __SYNOLOGY__
|
||||
int devno = 50;
|
||||
do {
|
||||
Utils::snprintf(ifr.ifr_name,sizeof(ifr.ifr_name),"eth%d",devno++);
|
||||
Utils::snprintf(procpath,sizeof(procpath),"/proc/sys/net/ipv4/conf/%s",ifr.ifr_name);
|
||||
Utils::ztsnprintf(ifr.ifr_name,sizeof(ifr.ifr_name),"eth%d",devno++);
|
||||
Utils::ztsnprintf(procpath,sizeof(procpath),"/proc/sys/net/ipv4/conf/%s",ifr.ifr_name);
|
||||
} while (stat(procpath,&sbuf) == 0); // try zt#++ until we find one that does not exist
|
||||
#else
|
||||
char devno = 0;
|
||||
|
@ -158,7 +158,7 @@ LinuxEthernetTap::LinuxEthernetTap(
|
|||
_base32_5_to_8(reinterpret_cast<const uint8_t *>(tmp2) + 5,tmp3 + 10);
|
||||
tmp3[15] = (char)0;
|
||||
memcpy(ifr.ifr_name,tmp3,16);
|
||||
Utils::snprintf(procpath,sizeof(procpath),"/proc/sys/net/ipv4/conf/%s",ifr.ifr_name);
|
||||
Utils::ztsnprintf(procpath,sizeof(procpath),"/proc/sys/net/ipv4/conf/%s",ifr.ifr_name);
|
||||
} while (stat(procpath,&sbuf) == 0);
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -134,7 +134,7 @@ long OSUtils::cleanDirectory(const char *path,const uint64_t olderThan)
|
|||
if (date.QuadPart > 0) {
|
||||
date.QuadPart -= adjust.QuadPart;
|
||||
if ((uint64_t)((date.QuadPart / 10000000) * 1000) < olderThan) {
|
||||
Utils::snprintf(tmp, sizeof(tmp), "%s\\%s", path, ffd.cFileName);
|
||||
Utils::ztsnprintf(tmp, sizeof(tmp), "%s\\%s", path, ffd.cFileName);
|
||||
if (DeleteFileA(tmp))
|
||||
++cleaned;
|
||||
}
|
||||
|
@ -157,7 +157,7 @@ long OSUtils::cleanDirectory(const char *path,const uint64_t olderThan)
|
|||
break;
|
||||
if (dptr) {
|
||||
if ((strcmp(dptr->d_name,"."))&&(strcmp(dptr->d_name,".."))&&(dptr->d_type == DT_REG)) {
|
||||
Utils::snprintf(tmp,sizeof(tmp),"%s/%s",path,dptr->d_name);
|
||||
Utils::ztsnprintf(tmp,sizeof(tmp),"%s/%s",path,dptr->d_name);
|
||||
if (stat(tmp,&st) == 0) {
|
||||
uint64_t mt = (uint64_t)(st.st_mtime);
|
||||
if ((mt > 0)&&((mt * 1000) < olderThan)) {
|
||||
|
@ -446,7 +446,7 @@ std::string OSUtils::jsonString(const nlohmann::json &jv,const char *dfl)
|
|||
return jv;
|
||||
} else if (jv.is_number()) {
|
||||
char tmp[64];
|
||||
Utils::snprintf(tmp,sizeof(tmp),"%llu",(uint64_t)jv);
|
||||
Utils::ztsnprintf(tmp,sizeof(tmp),"%llu",(uint64_t)jv);
|
||||
return tmp;
|
||||
} else if (jv.is_boolean()) {
|
||||
return ((bool)jv ? std::string("1") : std::string("0"));
|
||||
|
|
|
@ -336,7 +336,7 @@ OSXEthernetTap::OSXEthernetTap(
|
|||
char devpath[64],ethaddr[64],mtustr[32],metstr[32],nwids[32];
|
||||
struct stat stattmp;
|
||||
|
||||
Utils::snprintf(nwids,sizeof(nwids),"%.16llx",nwid);
|
||||
Utils::ztsnprintf(nwids,sizeof(nwids),"%.16llx",nwid);
|
||||
|
||||
Mutex::Lock _gl(globalTapCreateLock);
|
||||
|
||||
|
@ -391,13 +391,13 @@ OSXEthernetTap::OSXEthernetTap(
|
|||
// Open the first unused tap device if we didn't recall a previous one.
|
||||
if (!recalledDevice) {
|
||||
for(int i=0;i<64;++i) {
|
||||
Utils::snprintf(devpath,sizeof(devpath),"/dev/zt%d",i);
|
||||
Utils::ztsnprintf(devpath,sizeof(devpath),"/dev/zt%d",i);
|
||||
if (stat(devpath,&stattmp))
|
||||
throw std::runtime_error("no more TAP devices available");
|
||||
_fd = ::open(devpath,O_RDWR);
|
||||
if (_fd > 0) {
|
||||
char foo[16];
|
||||
Utils::snprintf(foo,sizeof(foo),"zt%d",i);
|
||||
Utils::ztsnprintf(foo,sizeof(foo),"zt%d",i);
|
||||
_dev = foo;
|
||||
break;
|
||||
}
|
||||
|
@ -413,9 +413,9 @@ OSXEthernetTap::OSXEthernetTap(
|
|||
}
|
||||
|
||||
// Configure MAC address and MTU, bring interface up
|
||||
Utils::snprintf(ethaddr,sizeof(ethaddr),"%.2x:%.2x:%.2x:%.2x:%.2x:%.2x",(int)mac[0],(int)mac[1],(int)mac[2],(int)mac[3],(int)mac[4],(int)mac[5]);
|
||||
Utils::snprintf(mtustr,sizeof(mtustr),"%u",_mtu);
|
||||
Utils::snprintf(metstr,sizeof(metstr),"%u",_metric);
|
||||
Utils::ztsnprintf(ethaddr,sizeof(ethaddr),"%.2x:%.2x:%.2x:%.2x:%.2x:%.2x",(int)mac[0],(int)mac[1],(int)mac[2],(int)mac[3],(int)mac[4],(int)mac[5]);
|
||||
Utils::ztsnprintf(mtustr,sizeof(mtustr),"%u",_mtu);
|
||||
Utils::ztsnprintf(metstr,sizeof(metstr),"%u",_metric);
|
||||
long cpid = (long)vfork();
|
||||
if (cpid == 0) {
|
||||
::execl("/sbin/ifconfig","/sbin/ifconfig",_dev.c_str(),"lladdr",ethaddr,"mtu",mtustr,"metric",metstr,"up",(const char *)0);
|
||||
|
@ -636,7 +636,7 @@ void OSXEthernetTap::setMtu(unsigned int mtu)
|
|||
long cpid = (long)vfork();
|
||||
if (cpid == 0) {
|
||||
char tmp[64];
|
||||
Utils::snprintf(tmp,sizeof(tmp),"%u",mtu);
|
||||
Utils::ztsnprintf(tmp,sizeof(tmp),"%u",mtu);
|
||||
execl("/sbin/ifconfig","/sbin/ifconfig",_dev.c_str(),"mtu",tmp,(const char *)0);
|
||||
_exit(-1);
|
||||
} else if (cpid > 0) {
|
||||
|
|
|
@ -205,7 +205,7 @@ public:
|
|||
memset(externalip,0,sizeof(externalip));
|
||||
memset(&urls,0,sizeof(urls));
|
||||
memset(&data,0,sizeof(data));
|
||||
Utils::snprintf(inport,sizeof(inport),"%d",localPort);
|
||||
Utils::ztsnprintf(inport,sizeof(inport),"%d",localPort);
|
||||
|
||||
if ((UPNP_GetValidIGD(devlist,&urls,&data,lanaddr,sizeof(lanaddr)))&&(lanaddr[0])) {
|
||||
#ifdef ZT_PORTMAPPER_TRACE
|
||||
|
@ -220,7 +220,7 @@ public:
|
|||
int tryPort = (int)localPort + tries;
|
||||
if (tryPort >= 65535)
|
||||
tryPort = (tryPort - 65535) + 1025;
|
||||
Utils::snprintf(outport,sizeof(outport),"%u",tryPort);
|
||||
Utils::ztsnprintf(outport,sizeof(outport),"%u",tryPort);
|
||||
|
||||
// First check and see if this port is already mapped to the
|
||||
// same unique name. If so, keep this mapping and don't try
|
||||
|
|
|
@ -484,7 +484,7 @@ WindowsEthernetTap::WindowsEthernetTap(
|
|||
char tag[24];
|
||||
|
||||
// We "tag" registry entries with the network ID to identify persistent devices
|
||||
Utils::snprintf(tag,sizeof(tag),"%.16llx",(unsigned long long)nwid);
|
||||
Utils::ztsnprintf(tag,sizeof(tag),"%.16llx",(unsigned long long)nwid);
|
||||
|
||||
Mutex::Lock _l(_systemTapInitLock);
|
||||
|
||||
|
@ -601,10 +601,10 @@ WindowsEthernetTap::WindowsEthernetTap(
|
|||
|
||||
if (_netCfgInstanceId.length() > 0) {
|
||||
char tmps[64];
|
||||
unsigned int tmpsl = Utils::snprintf(tmps,sizeof(tmps),"%.2X-%.2X-%.2X-%.2X-%.2X-%.2X",(unsigned int)mac[0],(unsigned int)mac[1],(unsigned int)mac[2],(unsigned int)mac[3],(unsigned int)mac[4],(unsigned int)mac[5]) + 1;
|
||||
unsigned int tmpsl = Utils::ztsnprintf(tmps,sizeof(tmps),"%.2X-%.2X-%.2X-%.2X-%.2X-%.2X",(unsigned int)mac[0],(unsigned int)mac[1],(unsigned int)mac[2],(unsigned int)mac[3],(unsigned int)mac[4],(unsigned int)mac[5]) + 1;
|
||||
RegSetKeyValueA(nwAdapters,_mySubkeyName.c_str(),"NetworkAddress",REG_SZ,tmps,tmpsl);
|
||||
RegSetKeyValueA(nwAdapters,_mySubkeyName.c_str(),"MAC",REG_SZ,tmps,tmpsl);
|
||||
tmpsl = Utils::snprintf(tmps, sizeof(tmps), "%d", mtu);
|
||||
tmpsl = Utils::ztsnprintf(tmps, sizeof(tmps), "%d", mtu);
|
||||
RegSetKeyValueA(nwAdapters,_mySubkeyName.c_str(),"MTU",REG_SZ,tmps,tmpsl);
|
||||
|
||||
DWORD tmp = 0;
|
||||
|
@ -879,7 +879,7 @@ void WindowsEthernetTap::setMtu(unsigned int mtu)
|
|||
HKEY nwAdapters;
|
||||
if (RegOpenKeyExA(HKEY_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E972-E325-11CE-BFC1-08002BE10318}", 0, KEY_READ | KEY_WRITE, &nwAdapters) == ERROR_SUCCESS) {
|
||||
char tmps[64];
|
||||
unsigned int tmpsl = Utils::snprintf(tmps, sizeof(tmps), "%d", mtu);
|
||||
unsigned int tmpsl = Utils::ztsnprintf(tmps, sizeof(tmps), "%d", mtu);
|
||||
RegSetKeyValueA(nwAdapters, _mySubkeyName.c_str(), "MTU", REG_SZ, tmps, tmpsl);
|
||||
RegCloseKey(nwAdapters);
|
||||
}
|
||||
|
@ -902,7 +902,7 @@ void WindowsEthernetTap::threadMain()
|
|||
HANDLE wait4[3];
|
||||
OVERLAPPED tapOvlRead,tapOvlWrite;
|
||||
|
||||
Utils::snprintf(tapPath,sizeof(tapPath),"\\\\.\\Global\\%s.tap",_netCfgInstanceId.c_str());
|
||||
Utils::ztsnprintf(tapPath,sizeof(tapPath),"\\\\.\\Global\\%s.tap",_netCfgInstanceId.c_str());
|
||||
|
||||
try {
|
||||
while (_run) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue