summaryrefslogtreecommitdiff
path: root/ucspi-tcp-0.88/dns_domain.c
diff options
context:
space:
mode:
authorJohn Denker <jsd@av8n.com>2012-07-26 10:57:13 -0700
committerJohn Denker <jsd@av8n.com>2012-07-29 15:32:37 -0700
commit9aa998757a8736cef02fd92050eacbb2a6fb5180 (patch)
tree18ae3d172893279aecaf12df94cb468bf887aa72 /ucspi-tcp-0.88/dns_domain.c
parent6e8083ff4ffe3fd2b6d337386637a2b5c1378cf7 (diff)
patch to support IPv6 in tcpserver
Diffstat (limited to 'ucspi-tcp-0.88/dns_domain.c')
-rw-r--r--ucspi-tcp-0.88/dns_domain.c36
1 files changed, 24 insertions, 12 deletions
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 <stdlib.h>
#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;