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_dfd.c | |
parent | 94c58d7f8cabd9b1ff4c33c57a6ff76cdf3f955e (diff) |
as downloaded : ucspi-tcp
Diffstat (limited to 'ucspi-tcp-0.88/dns_dfd.c')
-rw-r--r-- | ucspi-tcp-0.88/dns_dfd.c | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/ucspi-tcp-0.88/dns_dfd.c b/ucspi-tcp-0.88/dns_dfd.c new file mode 100644 index 0000000..14a29d8 --- /dev/null +++ b/ucspi-tcp-0.88/dns_dfd.c @@ -0,0 +1,69 @@ +#include "error.h" +#include "alloc.h" +#include "byte.h" +#include "dns.h" + +int dns_domain_fromdot(char **out,char *buf,unsigned int n) +{ + char label[63]; + unsigned int labellen = 0; /* <= sizeof label */ + char name[255]; + unsigned int namelen = 0; /* <= sizeof name */ + char ch; + char *x; + + errno = error_proto; + + for (;;) { + if (!n) break; + ch = *buf++; --n; + if (ch == '.') { + if (labellen) { + if (namelen + labellen + 1 > sizeof name) return 0; + name[namelen++] = labellen; + byte_copy(name + namelen,labellen,label); + namelen += labellen; + labellen = 0; + } + continue; + } + if (ch == '\\') { + if (!n) break; + ch = *buf++; --n; + if ((ch >= '0') && (ch <= '7')) { + ch -= '0'; + if (n && (*buf >= '0') && (*buf <= '7')) { + ch <<= 3; + ch += *buf - '0'; + ++buf; --n; + if (n && (*buf >= '0') && (*buf <= '7')) { + ch <<= 3; + ch += *buf - '0'; + ++buf; --n; + } + } + } + } + if (labellen >= sizeof label) return 0; + label[labellen++] = ch; + } + + if (labellen) { + if (namelen + labellen + 1 > sizeof name) return 0; + name[namelen++] = labellen; + byte_copy(name + namelen,labellen,label); + namelen += labellen; + labellen = 0; + } + + if (namelen + 1 > sizeof name) return 0; + name[namelen++] = 0; + + x = alloc(namelen); + if (!x) return 0; + byte_copy(x,namelen,name); + + if (*out) alloc_free(*out); + *out = x; + return 1; +} |