forked from rspamd/rbldnsd
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdns_dnreverse.c
More file actions
29 lines (22 loc) · 735 Bytes
/
dns_dnreverse.c
File metadata and controls
29 lines (22 loc) · 735 Bytes
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;
}