1 |
unnilennium |
1.1 |
--- /dev/null |
2 |
|
|
+++ b/dnsnamex.c |
3 |
|
|
@@ -0,0 +1,34 @@ |
4 |
|
|
+#include "buffer.h" |
5 |
|
|
+#include "exit.h" |
6 |
|
|
+#include "strerr.h" |
7 |
|
|
+#include "ip4.h" |
8 |
|
|
+#include "dns.h" |
9 |
|
|
+ |
10 |
|
|
+#define FATAL "dnsnamex: fatal: " |
11 |
|
|
+ |
12 |
|
|
+static char seed[128]; |
13 |
|
|
+ |
14 |
|
|
+char ip[4]; |
15 |
|
|
+static stralloc out; |
16 |
|
|
+ |
17 |
|
|
+int main(int argc,char **argv) |
18 |
|
|
+{ |
19 |
|
|
+ dns_random_init(seed); |
20 |
|
|
+ |
21 |
|
|
+ if (*argv) ++argv; |
22 |
|
|
+ |
23 |
|
|
+ while (*argv) { |
24 |
|
|
+ if (!ip4_scan(*argv,ip)) |
25 |
|
|
+ strerr_die3x(111,FATAL,"unable to parse IP address ",*argv); |
26 |
|
|
+ if (dns_name4_multi(&out,ip) == -1) |
27 |
|
|
+ strerr_die4sys(111,FATAL,"unable to find host name for ",*argv,": "); |
28 |
|
|
+ |
29 |
|
|
+ buffer_put(buffer_1,out.s,out.len); |
30 |
|
|
+ buffer_puts(buffer_1,"\n"); |
31 |
|
|
+ |
32 |
|
|
+ ++argv; |
33 |
|
|
+ } |
34 |
|
|
+ |
35 |
|
|
+ buffer_flush(buffer_1); |
36 |
|
|
+ _exit(0); |
37 |
|
|
+} |
38 |
|
|
--- /dev/null |
39 |
|
|
+++ b/dns_namex.c |
40 |
|
|
@@ -0,0 +1,48 @@ |
41 |
|
|
+#include "stralloc.h" |
42 |
|
|
+#include "uint16.h" |
43 |
|
|
+#include "byte.h" |
44 |
|
|
+#include "dns.h" |
45 |
|
|
+ |
46 |
|
|
+static char *q = 0; |
47 |
|
|
+ |
48 |
|
|
+int dns_name_packet_multi(stralloc *out,const char *buf,unsigned int len) |
49 |
|
|
+{ |
50 |
|
|
+ unsigned int pos; |
51 |
|
|
+ char header[12]; |
52 |
|
|
+ uint16 numanswers; |
53 |
|
|
+ uint16 datalen; |
54 |
|
|
+ |
55 |
|
|
+ if (!stralloc_copys(out,"")) return -1; |
56 |
|
|
+ |
57 |
|
|
+ pos = dns_packet_copy(buf,len,0,header,12); if (!pos) return -1; |
58 |
|
|
+ uint16_unpack_big(header + 6,&numanswers); |
59 |
|
|
+ pos = dns_packet_skipname(buf,len,pos); if (!pos) return -1; |
60 |
|
|
+ pos += 4; |
61 |
|
|
+ |
62 |
|
|
+ while (numanswers--) { |
63 |
|
|
+ pos = dns_packet_skipname(buf,len,pos); if (!pos) return -1; |
64 |
|
|
+ pos = dns_packet_copy(buf,len,pos,header,10); if (!pos) return -1; |
65 |
|
|
+ uint16_unpack_big(header + 8,&datalen); |
66 |
|
|
+ if (byte_equal(header,2,DNS_T_PTR)) |
67 |
|
|
+ if (byte_equal(header + 2,2,DNS_C_IN)) { |
68 |
|
|
+ if (!dns_packet_getname(buf,len,pos,&q)) return -1; |
69 |
|
|
+ if (!dns_domain_todot_cat(out,q)) return -1; |
70 |
|
|
+ if (!stralloc_cats(out, " ")) return -1 ; |
71 |
|
|
+ } |
72 |
|
|
+ pos += datalen; |
73 |
|
|
+ } |
74 |
|
|
+ |
75 |
|
|
+ return 0; |
76 |
|
|
+} |
77 |
|
|
+ |
78 |
|
|
+int dns_name4_multi(stralloc *out,const char ip[4]) |
79 |
|
|
+{ |
80 |
|
|
+ char name[DNS_NAME4_DOMAIN]; |
81 |
|
|
+ |
82 |
|
|
+ dns_name4_domain(name,ip); |
83 |
|
|
+ if (dns_resolve(name,DNS_T_PTR) == -1) return -1; |
84 |
|
|
+ if (dns_name_packet_multi(out,dns_resolve_tx.packet,dns_resolve_tx.packetlen) == -1) return -1; |
85 |
|
|
+ dns_transmit_free(&dns_resolve_tx); |
86 |
|
|
+ dns_domain_free(&q); |
87 |
|
|
+ return 0; |
88 |
|
|
+} |
89 |
|
|
--- a/dns.h |
90 |
|
|
+++ b/dns.h |
91 |
|
|
@@ -70,9 +70,11 @@ extern struct dns_transmit dns_resolve_t |
92 |
|
|
extern int dns_ip4_packet(stralloc *,const char *,unsigned int); |
93 |
|
|
extern int dns_ip4(stralloc *,const stralloc *); |
94 |
|
|
extern int dns_name_packet(stralloc *,const char *,unsigned int); |
95 |
|
|
+extern int dns_name_packet_multi(stralloc *,const char *,unsigned int); |
96 |
|
|
extern void dns_name4_domain(char *,const char *); |
97 |
|
|
#define DNS_NAME4_DOMAIN 31 |
98 |
|
|
extern int dns_name4(stralloc *,const char *); |
99 |
|
|
+extern int dns_name4_multi(stralloc *,const char *); |
100 |
|
|
extern int dns_txt_packet(stralloc *,const char *,unsigned int); |
101 |
|
|
extern int dns_txt(stralloc *,const stralloc *); |
102 |
|
|
extern int dns_mx_packet(stralloc *,const char *,unsigned int); |
103 |
|
|
--- a/Makefile |
104 |
|
|
+++ b/Makefile |
105 |
|
|
@@ -219,10 +219,10 @@ uint64.h taia.h dd.h |
106 |
|
|
|
107 |
|
|
dns.a: \ |
108 |
|
|
makelib dns_dfd.o dns_domain.o dns_dtda.o dns_ip.o dns_ipq.o dns_mx.o \ |
109 |
|
|
-dns_name.o dns_nd.o dns_packet.o dns_random.o dns_rcip.o dns_rcrw.o \ |
110 |
|
|
+dns_name.o dns_namex.o dns_nd.o dns_packet.o dns_random.o dns_rcip.o dns_rcrw.o \ |
111 |
|
|
dns_resolve.o dns_sortip.o dns_transmit.o dns_txt.o |
112 |
|
|
./makelib dns.a dns_dfd.o dns_domain.o dns_dtda.o dns_ip.o \ |
113 |
|
|
- dns_ipq.o dns_mx.o dns_name.o dns_nd.o dns_packet.o \ |
114 |
|
|
+ dns_ipq.o dns_mx.o dns_name.o dns_namex.o dns_nd.o dns_packet.o \ |
115 |
|
|
dns_random.o dns_rcip.o dns_rcrw.o dns_resolve.o \ |
116 |
|
|
dns_sortip.o dns_transmit.o dns_txt.o |
117 |
|
|
|
118 |
|
|
@@ -261,6 +261,11 @@ compile dns_name.c stralloc.h gen_alloc. |
119 |
|
|
stralloc.h iopause.h taia.h tai.h uint64.h taia.h |
120 |
|
|
./compile dns_name.c |
121 |
|
|
|
122 |
|
|
+dns_namex.o: \ |
123 |
|
|
+compile dns_namex.c stralloc.h gen_alloc.h uint16.h byte.h dns.h \ |
124 |
|
|
+stralloc.h iopause.h taia.h tai.h uint64.h taia.h |
125 |
|
|
+ ./compile dns_namex.c |
126 |
|
|
+ |
127 |
|
|
dns_nd.o: \ |
128 |
|
|
compile dns_nd.c byte.h fmt.h dns.h stralloc.h gen_alloc.h iopause.h \ |
129 |
|
|
taia.h tai.h uint64.h taia.h |
130 |
|
|
@@ -394,6 +399,17 @@ compile dnsname.c buffer.h exit.h strerr |
131 |
|
|
gen_alloc.h iopause.h taia.h tai.h uint64.h taia.h |
132 |
|
|
./compile dnsname.c |
133 |
|
|
|
134 |
|
|
+dnsnamex: \ |
135 |
|
|
+load dnsnamex.o iopause.o dns.a env.a libtai.a alloc.a buffer.a unix.a \ |
136 |
|
|
+byte.a socket.lib |
137 |
|
|
+ ./load dnsnamex iopause.o dns.a env.a libtai.a alloc.a \ |
138 |
|
|
+ buffer.a unix.a byte.a `cat socket.lib` |
139 |
|
|
+ |
140 |
|
|
+dnsnamex.o: \ |
141 |
|
|
+compile dnsnamex.c buffer.h exit.h strerr.h ip4.h dns.h stralloc.h \ |
142 |
|
|
+gen_alloc.h iopause.h taia.h tai.h uint64.h taia.h |
143 |
|
|
+ ./compile dnsnamex.c |
144 |
|
|
+ |
145 |
|
|
dnsq: \ |
146 |
|
|
load dnsq.o iopause.o printrecord.o printpacket.o parsetype.o dns.a \ |
147 |
|
|
env.a libtai.a buffer.a alloc.a unix.a byte.a socket.lib |
148 |
|
|
@@ -658,7 +674,7 @@ prog: \ |
149 |
|
|
dnscache-conf dnscache walldns-conf walldns rbldns-conf rbldns \ |
150 |
|
|
rbldns-data pickdns-conf pickdns pickdns-data tinydns-conf tinydns \ |
151 |
|
|
tinydns-data tinydns-get tinydns-edit axfr-get axfrdns-conf axfrdns \ |
152 |
|
|
-dnsip dnsipq dnsname dnstxt dnsmx dnsfilter random-ip dnsqr dnsq \ |
153 |
|
|
+dnsip dnsipq dnsname dnsnamex dnstxt dnsmx dnsfilter random-ip dnsqr dnsq \ |
154 |
|
|
dnstrace dnstracesort cachetest utime rts |
155 |
|
|
|
156 |
|
|
prot.o: \ |