Commit 433fd126 authored by Lubos Slovak's avatar Lubos Slovak

Function for replacing suffix of domain name.

refs #5
parent 85b9d4af
......@@ -426,6 +426,29 @@ int dnslib_dname_label_count(const dnslib_dname_t *dname)
/*----------------------------------------------------------------------------*/
dnslib_dname_t *dnslib_dname_replace_suffix(const dnslib_dname_t *dname,
int size,
const dnslib_dname_t *suffix)
{
dnslib_dname_t *res = dnslib_dname_new();
if (res == NULL) {
return NULL;
}
res->name = (uint8_t *)malloc(dname->size - size + suffix->size);
if (res->name == NULL) {
dnslib_dname_free(&res);
return NULL;
}
memcpy(res->name, dname->name, dname->size - size);
memcpy(res->name + dname->size - size, suffix, size);
return res;
}
/*----------------------------------------------------------------------------*/
void dnslib_dname_free(dnslib_dname_t **dname)
{
if (dname == NULL || *dname == NULL) {
......
......@@ -192,6 +192,21 @@ int dnslib_dname_matched_labels(const dnslib_dname_t *dname1,
*/
int dnslib_dname_label_count(const dnslib_dname_t *dname);
/*!
* \brief Replaces the suffix of given size in one domain name with other domain
* name.
*
* \param dname Domain name where to replace the suffix.
* \param size Size of the suffix to be replaced.
* \param suffix New suffix to be used as a replacement.
*
* \return New domain name created by replacing suffix of \a dname of size
* \a size with \a suffix.
*/
dnslib_dname_t *dnslib_dname_replace_suffix(const dnslib_dname_t *dname,
int size,
const dnslib_dname_t *suffix);
/*!
* \brief Destroys the given domain name.
*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment