ZeroTierOne/node/DNS.hpp

57 lines
1.4 KiB
C++
Raw Normal View History

2020-07-20 21:34:19 +00:00
/*
* Copyright (c)2020 ZeroTier, Inc.
*
* Use of this software is governed by the Business Source License included
* in the LICENSE.TXT file in the project's root directory.
*
2020-08-20 19:51:39 +00:00
* Change Date: 2025-01-01
2020-07-20 21:34:19 +00:00
*
* On the date above, in accordance with the Business Source License, use
* of this software will be governed by version 2.0 of the Apache License.
*/
/****/
#ifndef ZT_DNS_HPP
#define ZT_DNS_HPP
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "Buffer.hpp"
#include "InetAddress.hpp"
#include "../include/ZeroTierOne.h"
namespace ZeroTier {
/**
* DNS data serealization methods
*/
class DNS {
public:
template<unsigned int C>
2020-08-12 20:08:47 +00:00
static inline void serializeDNS(Buffer<C> &b, const ZT_VirtualNetworkDNS *dns)
2020-07-20 21:34:19 +00:00
{
2020-08-12 20:08:47 +00:00
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 21:34:19 +00:00
}
}
template<unsigned int C>
2020-08-12 20:08:47 +00:00
static inline void deserializeDNS(const Buffer<C> &b, unsigned int &p, ZT_VirtualNetworkDNS *dns)
2020-07-20 21:34:19 +00:00
{
2020-08-12 20:08:47 +00:00
char *d = (char*)b.data()+p;
memset(dns, 0, sizeof(ZT_VirtualNetworkDNS));
memcpy(dns->domain, d, 128);
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 21:34:19 +00:00
}
}
};
}
#endif // ZT_DNS_HPP