diff options
author | John Denker <jsd@av8n.com> | 2012-06-01 23:07:51 -0700 |
---|---|---|
committer | John Denker <jsd@av8n.com> | 2012-06-02 17:30:23 -0700 |
commit | 0d0f7a0e7c32842edff533246a1f8523306f9ab0 (patch) | |
tree | 43dbb2fffaa8d490731969f39f5d20832523bd5d /ucspi-tcp-0.88/dns_domain.c | |
parent | 94c58d7f8cabd9b1ff4c33c57a6ff76cdf3f955e (diff) |
as downloaded : ucspi-tcp
Diffstat (limited to 'ucspi-tcp-0.88/dns_domain.c')
-rw-r--r-- | ucspi-tcp-0.88/dns_domain.c | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/ucspi-tcp-0.88/dns_domain.c b/ucspi-tcp-0.88/dns_domain.c new file mode 100644 index 0000000..f898485 --- /dev/null +++ b/ucspi-tcp-0.88/dns_domain.c @@ -0,0 +1,61 @@ +#include "error.h" +#include "alloc.h" +#include "case.h" +#include "byte.h" +#include "dns.h" + +unsigned int dns_domain_length(char *dn) +{ + char *x; + unsigned char c; + + x = dn; + while (c = *x++) + x += (unsigned int) c; + return x - dn; +} + +void dns_domain_free(char **out) +{ + if (*out) { + alloc_free(*out); + *out = 0; + } +} + +int dns_domain_copy(char **out,char *in) +{ + unsigned int len; + char *x; + + len = dns_domain_length(in); + x = alloc(len); + if (!x) return 0; + byte_copy(x,len,in); + if (*out) alloc_free(*out); + *out = x; + return 1; +} + +int dns_domain_equal(char *dn1,char *dn2) +{ + unsigned int len; + + len = dns_domain_length(dn1); + if (len != dns_domain_length(dn2)) return 0; + + if (case_diffb(dn1,len,dn2)) return 0; /* safe since 63 < 'A' */ + return 1; +} + +char *dns_domain_suffix(char *big,char *little) +{ + unsigned char c; + + for (;;) { + if (dns_domain_equal(big,little)) return big; + c = *big++; + if (!c) return 0; + big += c; + } +} |