fehQlibs 26
Qlibs
Loading...
Searching...
No Matches
dns_domain.c
Go to the documentation of this file.
1#include "alloc.h"
2#include "case.h"
3#include "byte.h"
4#include "dnsresolv.h"
5
13unsigned int dns_domain_length(const char *dn)
14{
15 const char *x;
16 unsigned char c;
17
18 x = dn;
19 while ((c = *x++))
20 x += (unsigned int) c;
21 return x - dn;
22}
23
24void dns_domain_free(char **out)
25{
26 if (*out) {
27 alloc_free(*out);
28 *out = 0;
29 }
30}
31
32int dns_domain_copy(char **out,const char *in)
33{
34 unsigned int len;
35 char *x;
36
37 len = dns_domain_length(in);
38 x = alloc(len);
39 if (!x) return 0;
40 byte_copy(x,len,in);
41 if (*out) alloc_free(*out);
42 *out = x;
43 return 1;
44}
45
46int dns_domain_equal(const char *dn1,const char *dn2)
47{
48 unsigned int len;
49
50 len = dns_domain_length(dn1);
51 if (len != dns_domain_length(dn2)) return 0;
52
53 if (case_diffb((char *)dn1,len,(char *)dn2)) return 0; /* safe since 63 < 'A' */
54 return 1;
55}
56
57int dns_domain_suffix(const char *big,const char *little)
58{
59 unsigned char c;
60
61 for (;;) {
62 if (dns_domain_equal(big,little)) return 1;
63 c = *big++;
64 if (!c) return 0;
65 big += c;
66 }
67}
68
69unsigned int dns_domain_suffixpos(const char *big,const char *little)
70{
71 const char *orig = big;
72 unsigned char c;
73
74 for (;;) {
75 if (dns_domain_equal(big,little)) return big - orig;
76 c = *big++;
77 if (!c) return 0;
78 big += c;
79 }
80}
int dns_domain_equal(const char *dn1, const char *dn2)
Definition: dns_domain.c:46
unsigned int dns_domain_length(const char *dn)
Definition: dns_domain.c:13
int dns_domain_copy(char **out, const char *in)
Definition: dns_domain.c:32
int dns_domain_suffix(const char *big, const char *little)
Definition: dns_domain.c:57
void dns_domain_free(char **out)
Definition: dns_domain.c:24
unsigned int dns_domain_suffixpos(const char *big, const char *little)
Definition: dns_domain.c:69
int case_diffb(char *, unsigned int, char *)
Definition: case.c:10
void alloc_free(void *)
Definition: alloc.c:45
void * alloc(unsigned int)
Definition: alloc.c:27
void byte_copy(void *, unsigned int, const void *)
Definition: byte.c:20