From 9aa998757a8736cef02fd92050eacbb2a6fb5180 Mon Sep 17 00:00:00 2001 From: John Denker Date: Thu, 26 Jul 2012 10:57:13 -0700 Subject: patch to support IPv6 in tcpserver --- ucspi-tcp-0.88/dns_domain.c | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) (limited to 'ucspi-tcp-0.88/dns_domain.c') diff --git a/ucspi-tcp-0.88/dns_domain.c b/ucspi-tcp-0.88/dns_domain.c index f898485..80ac5ea 100644 --- a/ucspi-tcp-0.88/dns_domain.c +++ b/ucspi-tcp-0.88/dns_domain.c @@ -1,16 +1,15 @@ -#include "error.h" -#include "alloc.h" +#include #include "case.h" #include "byte.h" #include "dns.h" -unsigned int dns_domain_length(char *dn) +unsigned int dns_domain_length(const char *dn) { - char *x; + const char *x; unsigned char c; x = dn; - while (c = *x++) + while ((c = *x++)) x += (unsigned int) c; return x - dn; } @@ -18,26 +17,26 @@ unsigned int dns_domain_length(char *dn) void dns_domain_free(char **out) { if (*out) { - alloc_free(*out); + free(*out); *out = 0; } } -int dns_domain_copy(char **out,char *in) +int dns_domain_copy(char **out,const char *in) { unsigned int len; char *x; len = dns_domain_length(in); - x = alloc(len); + x = malloc(len); if (!x) return 0; byte_copy(x,len,in); - if (*out) alloc_free(*out); + if (*out) free(*out); *out = x; return 1; } -int dns_domain_equal(char *dn1,char *dn2) +int dns_domain_equal(const char *dn1,const char *dn2) { unsigned int len; @@ -48,12 +47,25 @@ int dns_domain_equal(char *dn1,char *dn2) return 1; } -char *dns_domain_suffix(char *big,char *little) +int dns_domain_suffix(const char *big,const char *little) +{ + unsigned char c; + + for (;;) { + if (dns_domain_equal(big,little)) return 1; + c = *big++; + if (!c) return 0; + big += c; + } +} + +unsigned int dns_domain_suffixpos(const char *big,const char *little) { + const char *orig = big; unsigned char c; for (;;) { - if (dns_domain_equal(big,little)) return big; + if (dns_domain_equal(big,little)) return big - orig; c = *big++; if (!c) return 0; big += c; -- cgit v1.2.3