diff -Naurp libowfat-0.21/dns/dns_ip6.c libowfat-0.21-eike/dns/dns_ip6.c --- libowfat-0.21/dns/dns_ip6.c 2002-09-17 02:56:56.000000000 +0200 +++ libowfat-0.21-eike/dns/dns_ip6.c 2005-03-10 23:14:42.000000000 +0100 @@ -4,6 +4,7 @@ #include "dns.h" #include "ip4.h" #include "ip6.h" +#include "str.h" static int dns_ip6_packet_add(stralloc *out,const char *buf,unsigned int len) { @@ -48,25 +49,22 @@ int dns_ip6_packet(stralloc *out,const c static char *q = 0; -int dns_ip6(stralloc *out,stralloc *fqdn) +static int dns_ip6q(stralloc *out, const char *fqdn, const unsigned int len) { unsigned int i; char code; char ch; char ip[16]; - if (!stralloc_copys(out,"")) return -1; - if (!stralloc_readyplus(fqdn,1)) return -1; - fqdn->s[fqdn->len]=0; - if ((i=scan_ip6(fqdn->s,ip))) { - if (fqdn->s[i]) return -1; + if ((i=scan_ip6(fqdn,ip))) { + if (fqdn[i]) return -1; stralloc_copyb(out,ip,16); return 0; } code = 0; - for (i = 0;i <= fqdn->len;++i) { - if (i < fqdn->len) - ch = fqdn->s[i]; + for (i = 0;i <= len;++i) { + if (i < len) + ch = fqdn[i]; else ch = '.'; @@ -82,14 +80,14 @@ int dns_ip6(stralloc *out,stralloc *fqdn continue; } - if (!dns_domain_fromdot(&q,fqdn->s,fqdn->len)) return -1; + if (!dns_domain_fromdot(&q,fqdn,len)) return -1; if (!stralloc_copys(out,"")) return -1; if (dns_resolve(q,DNS_T_AAAA) != -1) if (dns_ip6_packet_add(out,dns_resolve_tx.packet,dns_resolve_tx.packetlen) != -1) { dns_transmit_free(&dns_resolve_tx); dns_domain_free(&q); } - if (!dns_domain_fromdot(&q,fqdn->s,fqdn->len)) return -1; + if (!dns_domain_fromdot(&q,fqdn,len)) return -1; if (dns_resolve(q,DNS_T_A) != -1) if (dns_ip6_packet_add(out,dns_resolve_tx.packet,dns_resolve_tx.packetlen) != -1) { dns_transmit_free(&dns_resolve_tx); @@ -101,3 +99,24 @@ int dns_ip6(stralloc *out,stralloc *fqdn out->len &= ~3; return 0; } + +int dns_ip6(stralloc *out,stralloc *fqdn) +{ + if (!stralloc_copys(out,"")) return -1; + if (!stralloc_readyplus(fqdn,1)) return -1; + fqdn->s[fqdn->len]=0; + + return dns_ip6q(out, fqdn->s, fqdn->len); +} + +int dnsip6(char **out, unsigned int *len, const char *fqdn) +{ + stralloc sa = {.len = 0, .a = 0, .s = 0}; + int r; + + if (!stralloc_copys(&sa,"")) return -1; + r = dns_ip6q(&sa, fqdn, str_len(fqdn)); + *out = sa.s; + *len = sa.len; + return r; +} diff -Naurp libowfat-0.21/dns/dns_ip.c libowfat-0.21-eike/dns/dns_ip.c --- libowfat-0.21/dns/dns_ip.c 2001-02-11 22:11:45.000000000 +0100 +++ libowfat-0.21-eike/dns/dns_ip.c 2005-03-10 23:14:42.000000000 +0100 @@ -2,6 +2,7 @@ #include "uint16.h" #include "byte.h" #include "dns.h" +#include "str.h" int dns_ip4_packet(stralloc *out,const char *buf,unsigned int len) { @@ -36,7 +37,7 @@ int dns_ip4_packet(stralloc *out,const c static char *q = 0; -int dns_ip4(stralloc *out,const stralloc *fqdn) +static int dns_ip4q(stralloc *out,const char *fqdn, const unsigned int len) { unsigned int i; char code; @@ -44,9 +45,9 @@ int dns_ip4(stralloc *out,const stralloc if (!stralloc_copys(out,"")) return -1; code = 0; - for (i = 0;i <= fqdn->len;++i) { - if (i < fqdn->len) - ch = fqdn->s[i]; + for (i = 0;i <= len;++i) { + if (i < len) + ch = fqdn[i]; else ch = '.'; @@ -62,7 +63,7 @@ int dns_ip4(stralloc *out,const stralloc continue; } - if (!dns_domain_fromdot(&q,fqdn->s,fqdn->len)) return -1; + if (!dns_domain_fromdot(&q,fqdn,len)) return -1; if (dns_resolve(q,DNS_T_A) == -1) return -1; if (dns_ip4_packet(out,dns_resolve_tx.packet,dns_resolve_tx.packetlen) == -1) return -1; dns_transmit_free(&dns_resolve_tx); @@ -73,3 +74,19 @@ int dns_ip4(stralloc *out,const stralloc out->len &= ~3; return 0; } + +int dns_ip4(stralloc *out,const stralloc *fqdn) +{ + return dns_ip4q(out, fqdn->s, fqdn->len); +} + +int dnsip4(char **out, unsigned int *len, const char *fqdn) +{ + stralloc sa = {.len = 0, .s = 0, .a = 0}; + int r; + + r = dns_ip4q(&sa, fqdn, str_len(fqdn)); + *out = sa.s; + *len = sa.len; + return r; +} diff -Naurp libowfat-0.21/dns/dns_mx.c libowfat-0.21-eike/dns/dns_mx.c --- libowfat-0.21/dns/dns_mx.c 2001-02-11 22:11:45.000000000 +0100 +++ libowfat-0.21-eike/dns/dns_mx.c 2005-03-10 23:14:42.000000000 +0100 @@ -2,6 +2,7 @@ #include "byte.h" #include "uint16.h" #include "dns.h" +#include "str.h" static char *q = 0; @@ -47,3 +48,17 @@ int dns_mx(stralloc *out,const stralloc dns_domain_free(&q); return 0; } + +int dnsmx(char **out,unsigned int *len,const char *fqdn) +{ + stralloc sa = {.len = 0, .a = 0, .s = 0}; + + if (!dns_domain_fromdot(&q,fqdn,str_len(fqdn))) return -1; + if (dns_resolve(q,DNS_T_MX) == -1) return -1; + if (dns_mx_packet(&sa,dns_resolve_tx.packet,dns_resolve_tx.packetlen) == -1) return -1; + dns_transmit_free(&dns_resolve_tx); + dns_domain_free(&q); + *out = sa.s; + *len = sa.len; + return 0; +} diff -Naurp libowfat-0.21/dns/dns_name.c libowfat-0.21-eike/dns/dns_name.c --- libowfat-0.21/dns/dns_name.c 2004-06-04 19:38:30.000000000 +0200 +++ libowfat-0.21-eike/dns/dns_name.c 2005-03-10 23:14:42.000000000 +0100 @@ -1,3 +1,4 @@ +#include #include "stralloc.h" #include "uint16.h" #include "byte.h" @@ -68,3 +69,27 @@ int dns_name6(stralloc *out,const char i if (!out->len) return dns_name6_inner(out,ip,DNS_IP6_INT); return 0; } + +int dnsname(char **o,const char ip[16]) +{ + stralloc out = {.len = 0, .a = 0, .s = 0}; + int r = 0; + + *o = 0; + if (ip6_isv4mapped(ip)) { + r = dns_name4(&out,ip+12); + goto result; + } + if (dns_name6_inner(&out,ip,DNS_IP6_ARPA)) return -1; + if (!out.len) + r = dns_name6_inner(&out,ip,DNS_IP6_INT); +result: + if (!r && out.len) { + if (!stralloc_0(&out)) { + free(out.s); + r = -1; + } else + *o = out.s; + } + return r; +} diff -Naurp libowfat-0.21/dns/dns_txt.c libowfat-0.21-eike/dns/dns_txt.c --- libowfat-0.21/dns/dns_txt.c 2004-09-27 21:45:07.000000000 +0200 +++ libowfat-0.21-eike/dns/dns_txt.c 2005-03-10 23:23:26.000000000 +0100 @@ -1,8 +1,10 @@ #include +#include #include "stralloc.h" #include "uint16.h" #include "byte.h" #include "dns.h" +#include "str.h" int dns_txt_packet(stralloc *out,const char *buf,unsigned int len) { @@ -58,3 +60,18 @@ int dns_txt(stralloc *out,const stralloc dns_domain_free(&q); return 0; } + +int dnstxt(char **out,const char *fqdn) +{ + stralloc sa = {.a = 0, .len = 0, .s = 0}; + + if (!dns_domain_fromdot(&q,fqdn,str_len(fqdn))) return -1; + if (dns_resolve(q,DNS_T_TXT) == -1) return -1; + if (dns_txt_packet(&sa,dns_resolve_tx.packet,dns_resolve_tx.packetlen) == -1) return -1; + dns_transmit_free(&dns_resolve_tx); + dns_domain_free(&q); + if (!sa.len) { *out = 0; return 0; } + if (!stralloc_0(&sa)) { free(sa.s); return -1; } + *out = sa.s; + return 0; +} diff -Naurp libowfat-0.21/dns.h libowfat-0.21-eike/dns.h --- libowfat-0.21/dns.h 2004-07-14 08:37:05.000000000 +0200 +++ libowfat-0.21-eike/dns.h 2005-03-10 23:14:42.000000000 +0100 @@ -70,16 +70,21 @@ extern struct dns_transmit dns_resolve_t int dns_ip4_packet(stralloc *,const char *,unsigned int); int dns_ip4(stralloc *,const stralloc *); +int dnsip4(char **, unsigned int *, const char *); int dns_ip6_packet(stralloc *,const char *,unsigned int); int dns_ip6(stralloc *,stralloc *); +int dnsip6(char **, unsigned int *, const char *); int dns_name_packet(stralloc *,const char *,unsigned int); void dns_name4_domain(char *,const char *); #define DNS_NAME4_DOMAIN 31 int dns_name4(stralloc *,const char *); +int dnsname(char **, const char *); int dns_txt_packet(stralloc *,const char *,unsigned int); int dns_txt(stralloc *,const stralloc *); +int dnstxt(char **,const char *); int dns_mx_packet(stralloc *,const char *,unsigned int); int dns_mx(stralloc *,const stralloc *); +int dnsmx(char **, unsigned int *, const char *); int dns_resolvconfrewrite(stralloc *); int dns_ip4_qualify_rules(stralloc *,stralloc *,const stralloc *,const stralloc *);