File: dns_domain_todot.c

package info (click to toggle)
bglibs 2.04%2Bdfsg-8
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 3,468 kB
  • sloc: ansic: 15,821; perl: 674; sh: 63; makefile: 29
file content (34 lines) | stat: -rw-r--r-- 700 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include "dns.h"

/** Translate the domain name in \p d to a dotted text string in \p out. */
int dns_domain_todot_cat(str *out,const char *d)
{
  unsigned int len = fmt_dns_domain(0, d);
  if (!str_realloc(out, out->len + len))
    return 0;
  fmt_dns_domain(out->s + out->len, d);
  out->len += len;
  out->s[out->len] = 0;
  return 1;
}


#ifdef SELFTEST_MAIN
#include "iobuf.h"

void testit(const char* data)
{
  str result = {0};
  debugstrfn(dns_domain_todot_cat(&result, data), &result);
}

MAIN
{
  testit("\007example\003com\000");
  testit("\003joe\007example\003org\000");
}
#endif
#ifdef SELFTEST_EXP
result=1 len=11 size=16 s=example.com
result=1 len=15 size=32 s=joe.example.org
#endif