Files

51 lines
1.2 KiB
C++
Raw Permalink Normal View History

2025-08-06 12:10:18 -04:00
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
2020-07-20 14:34:19 -07:00
*
2025-08-06 12:10:18 -04:00
* (c) ZeroTier, Inc.
* https://www.zerotier.com/
2020-07-20 14:34:19 -07:00
*/
#ifndef ZT_DNS_HPP
#define ZT_DNS_HPP
2025-07-03 11:26:23 -04:00
#include "../include/ZeroTierOne.h"
#include "Buffer.hpp"
#include "InetAddress.hpp"
2020-07-20 14:34:19 -07:00
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
namespace ZeroTier {
/**
2022-11-28 09:23:45 -05:00
* DNS data serialization methods
2020-07-20 14:34:19 -07:00
*/
class DNS {
2025-07-03 11:26:23 -04:00
public:
template <unsigned int C> static inline void serializeDNS(Buffer<C>& b, const ZT_VirtualNetworkDNS* dns)
{
b.append(dns->domain, 128);
for (unsigned int j = 0; j < ZT_MAX_DNS_SERVERS; ++j) {
InetAddress tmp(dns->server_addr[j]);
tmp.serialize(b);
}
}
2020-07-20 14:34:19 -07:00
2025-07-03 11:26:23 -04:00
template <unsigned int C> static inline void deserializeDNS(const Buffer<C>& b, unsigned int& p, ZT_VirtualNetworkDNS* dns)
{
char* d = (char*)b.data() + p;
memset(dns, 0, sizeof(ZT_VirtualNetworkDNS));
memcpy(dns->domain, d, 128);
dns->domain[127] = 0;
p += 128;
for (unsigned int j = 0; j < ZT_MAX_DNS_SERVERS; ++j) {
p += reinterpret_cast<InetAddress*>(&(dns->server_addr[j]))->deserialize(b, p);
}
}
2020-07-20 14:34:19 -07:00
};
2025-07-03 11:26:23 -04:00
} // namespace ZeroTier
2020-07-20 14:34:19 -07:00
2025-07-03 11:26:23 -04:00
#endif // ZT_DNS_HPP