File: dns_dnreverse.c

package info (click to toggle)
rbldnsd 0.998b~pre1-1
  • links: PTS, VCS
  • area: main
  • in suites: buster, stretch
  • size: 744 kB
  • ctags: 1,132
  • sloc: ansic: 8,212; python: 549; sh: 502; makefile: 249; awk: 33
file content (29 lines) | stat: -rw-r--r-- 735 bytes parent folder | download | duplicates (3)
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
/* dns_dnreverse() produces reverse of a domain name
 */

#include <string.h>
#include "dns.h"

/* reverse labels of the dn, return dns_dnlen() */

unsigned
dns_dnreverse(register const unsigned char *dn,
              register unsigned char *rdn,
              register unsigned len) {
  register unsigned c;	/* length of a current label */

  if (!len)		/* if no length given, compute it */
    len = dns_dnlen(dn);

  rdn += len;		/* start from the very end */
  *--rdn = '\0';	/* and null-terminate the dn */

  while((c = *dn) != 0) {	/* process each label */
    ++c;		/* include length byte */
    rdn -= c; /* this is where this label will be in rdn - back it's len */
    memcpy(rdn, dn, c);
    dn += c;
  }

  return len;
}