File: dns_domain.c

package info (click to toggle)
ucspi-tcp-src 0.88-15
  • links: PTS
  • area: non-free
  • in suites: lenny, squeeze
  • size: 1,380 kB
  • ctags: 761
  • sloc: ansic: 6,758; makefile: 854; sh: 312
file content (73 lines) | stat: -rw-r--r-- 1,234 bytes parent folder | download | duplicates (10)
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include <stdlib.h>
#include "case.h"
#include "byte.h"
#include "dns.h"

unsigned int dns_domain_length(const char *dn)
{
  const 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) {
    free(*out);
    *out = 0;
  }
}

int dns_domain_copy(char **out,const char *in)
{
  unsigned int len;
  char *x;

  len = dns_domain_length(in);
  x = malloc(len);
  if (!x) return 0;
  byte_copy(x,len,in);
  if (*out) free(*out);
  *out = x;
  return 1;
}

int dns_domain_equal(const char *dn1,const 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;
}

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 - orig;
    c = *big++;
    if (!c) return 0;
    big += c;
  }
}