also support ip6.arpa in addition to ip6.int

master
leitner 21 years ago
parent 1e871b1c32
commit 499ca6a307

@ -2,6 +2,8 @@
add errmsg API add errmsg API
work around broken Linux sendfile API (offset 64-bit but count 32-bit) work around broken Linux sendfile API (offset 64-bit but count 32-bit)
add io_appendfile, io_readwritefile add io_appendfile, io_readwritefile
support ip6.arpa in addition to ip6.int in dns_name (adds one
parameter to dns_name6_domain and two constants in dns.h)
0.19.2: 0.19.2:
for some reason, a botched dependency slipped in the the Makefile for some reason, a botched dependency slipped in the the Makefile

@ -87,7 +87,9 @@ int dns_ip4_qualify(stralloc *,stralloc *,const stralloc *);
int dns_ip6_qualify_rules(stralloc *,stralloc *,const stralloc *,const stralloc *); int dns_ip6_qualify_rules(stralloc *,stralloc *,const stralloc *,const stralloc *);
int dns_ip6_qualify(stralloc *,stralloc *,const stralloc *); int dns_ip6_qualify(stralloc *,stralloc *,const stralloc *);
int dns_name6_domain(char *,char *); #define DNS_IP6_INT 0
#define DNS_NAME6_DOMAIN (4*16+10) #define DNS_IP6_ARPA 1
int dns_name6_domain(char *,const char *,int);
#define DNS_NAME6_DOMAIN (4*16+11)
#endif #endif

@ -48,16 +48,23 @@ int dns_name4(stralloc *out,const char ip[4])
return 0; return 0;
} }
int dns_name6(stralloc *out,char ip[16]) static int dns_name6_inner(stralloc *out,const char ip[16],int t)
{ {
char name[DNS_NAME6_DOMAIN]; char name[DNS_NAME6_DOMAIN];
if (ip6_isv4mapped(ip)) dns_name6_domain(name,ip,t);
return dns_name4(out,ip+12);
dns_name6_domain(name,ip);
if (dns_resolve(name,DNS_T_PTR) == -1) return -1; if (dns_resolve(name,DNS_T_PTR) == -1) return -1;
if (dns_name_packet(out,dns_resolve_tx.packet,dns_resolve_tx.packetlen) == -1) return -1; if (dns_name_packet(out,dns_resolve_tx.packet,dns_resolve_tx.packetlen) == -1) return -1;
dns_transmit_free(&dns_resolve_tx); dns_transmit_free(&dns_resolve_tx);
dns_domain_free(&q); dns_domain_free(&q);
return 0; return 0;
} }
int dns_name6(stralloc *out,const char ip[16])
{
if (ip6_isv4mapped(ip))
return dns_name4(out,ip+12);
if (dns_name6_inner(out,ip,DNS_IP6_ARPA)) return -1;
if (!out->len) return dns_name6_inner(out,ip,DNS_IP6_INT);
return 0;
}

@ -11,7 +11,10 @@ puts the (first) domain name into \fIout\fR and returns 0. If the relevant
ip6.int domain does not exist in DNS, or has no PTR records, \fIout\fR ip6.int domain does not exist in DNS, or has no PTR records, \fIout\fR
will be empty. will be empty.
If dns_name4 has trouble with the DNS lookup or runs out of memory, it returns dns_name6 will try both the new "ip6.arpa" reverse lookup domain and the
old (deprecated) "ip6.int" one.
If dns_name6 has trouble with the DNS lookup or runs out of memory, it returns
-1, setting errno appropriately. It may or may not change \fIout\fR. -1, setting errno appropriately. It may or may not change \fIout\fR.
.SH "SEE ALSO" .SH "SEE ALSO"
dns_name_packet(3), dns_name6_domain(3), dns_name4(3), dns_ip6(3) dns_name_packet(3), dns_name6_domain(3), dns_name4(3), dns_ip6(3)

@ -5,11 +5,15 @@ dns_name6_domain \- construct host name for reverse lookup
.B #include <dns.h> .B #include <dns.h>
int \fBdns_name6_domain\fP(char \fIq\fR[DNS_NAME6_DOMAIN], int \fBdns_name6_domain\fP(char \fIq\fR[DNS_NAME6_DOMAIN],
const char* \fIip\fR[16]); const char* \fIip\fR[16],int \fItype\fR);
.SH DESCRIPTION .SH DESCRIPTION
dns_name6_domain is a low-level component of dns_name6. It converts an dns_name6_domain is a low-level component of dns_name6. It converts an
IP address such as 4321:0:1:2:3:4:567:89ab into a domain name such as IP address such as 4321:0:1:2:3:4:567:89ab into a domain name such as
b.a.9.8.7.6.5.0.4.0.0.0.3.0.0.0.2.0.0.0.1.0.0.0.0.0.0.0.1.2.3.4.IP6.INT b.a.9.8.7.6.5.0.4.0.0.0.3.0.0.0.2.0.0.0.1.0.0.0.0.0.0.0.1.2.3.4.IP6.INT
and places the packet-encoded domain name into \fIq\fR. and places the packet-encoded domain name into \fIq\fR.
\fItype\fR can be DNS_IP6_INT or DNS_IP6_ARPA. The "ip6.int" domain for
IPv6 reverse lookups is now deprecated and "ip6.arpa" is the standard
way.
.SH "SEE ALSO" .SH "SEE ALSO"
dns_name6(3), dns_name4_domain(3) dns_name6(3), dns_name4_domain(3)

@ -7,13 +7,14 @@
* 4321:0:1:2:3:4:567:89ab * 4321:0:1:2:3:4:567:89ab
* -> * ->
* b.a.9.8.7.6.5.0.4.0.0.0.3.0.0.0.2.0.0.0.1.0.0.0.0.0.0.0.1.2.3.4.IP6.INT. * b.a.9.8.7.6.5.0.4.0.0.0.3.0.0.0.2.0.0.0.1.0.0.0.0.0.0.0.1.2.3.4.IP6.INT.
* b.a.9.8.7.6.5.0.4.0.0.0.3.0.0.0.2.0.0.0.1.0.0.0.0.0.0.0.1.2.3.4.IP6.ARPA.
*/ */
static inline char tohex(char c) { static char tohex(char c) {
return c>=10?c-10+'a':c+'0'; return c>=10?c-10+'a':c+'0';
} }
int dns_name6_domain(char name[DNS_NAME6_DOMAIN],char ip[16]) int dns_name6_domain(char name[DNS_NAME6_DOMAIN],const char ip[16],int t)
{ {
unsigned int j; unsigned int j;
@ -23,7 +24,11 @@ int dns_name6_domain(char name[DNS_NAME6_DOMAIN],char ip[16])
name[j*4+2]=1; name[j*4+2]=1;
name[j*4+3]=tohex((unsigned char)ip[15-j] >> 4); name[j*4+3]=tohex((unsigned char)ip[15-j] >> 4);
} }
if (t==DNS_IP6_INT)
byte_copy(name + 4*16,9,"\3ip6\3int\0"); byte_copy(name + 4*16,9,"\3ip6\3int\0");
return 4*16+9; else if (t==DNS_IP6_ARPA)
byte_copy(name + 4*16,10,"\3ip6\4arpa\0");
else return 0;
return 4*16+9+t;
} }

Loading…
Cancel
Save