Browse Source

Add debugging for CNAME records.

Allow routines to be called by nmb.c
tags/v0.9.3
Michael Brown 19 years ago
parent
commit
bcedad4708
2 changed files with 38 additions and 5 deletions
  1. 13
    2
      src/include/dns.h
  2. 25
    3
      src/proto/dns.c

+ 13
- 2
src/include/dns.h View File

@@ -2,8 +2,9 @@
2 2
 #define DNS_RESOLVER_H
3 3
 
4 4
 #include "stdint.h"
5
-#include "nic.h"
6 5
 #include "in.h"
6
+#include "ip.h"
7
+#include "udp.h"
7 8
 
8 9
 /*
9 10
  * Constants
@@ -76,6 +77,16 @@ struct dns_rr_info_a {
76 77
 struct dns_rr_info_cname {
77 78
 	struct dns_rr_info;
78 79
 	char		cname[0];
79
-};
80
+} __attribute__ (( packed ));
81
+
82
+/*
83
+ * Functions in dns.c (used by nmb.c)
84
+ *
85
+ */
86
+extern struct dns_header * dns_query ( struct dns_query *query,
87
+				       unsigned int query_len, 
88
+				       struct sockaddr_in *nameserver );
89
+extern struct dns_rr_info * dns_find_rr ( struct dns_query *query,
90
+					  struct dns_header *reply );
80 91
 
81 92
 #endif /* DNS_RESOLVER_H */

+ 25
- 3
src/proto/dns.c View File

@@ -145,8 +145,8 @@ static inline const char * dns_skip_name ( const char *name ) {
145 145
  * query.  Returns a pointer to the RR, or NULL if no answer found.
146 146
  *
147 147
  */
148
-static struct dns_rr_info * dns_find_rr ( struct dns_query *query,
149
-					  struct dns_header *reply ) {
148
+struct dns_rr_info * dns_find_rr ( struct dns_query *query,
149
+				   struct dns_header *reply ) {
150 150
 	int i, cmp;
151 151
 	const char *p = ( ( char * ) reply ) + sizeof ( struct dns_header );
152 152
 
@@ -192,6 +192,23 @@ static inline char * dns_make_name ( char *dest, const char *name ) {
192 192
 	return dest;
193 193
 }
194 194
 
195
+/*
196
+ * Produce a printable version of a DNS name.  Used only for debugging.
197
+ *
198
+ */
199
+static inline char * dns_unmake_name ( char *name ) {
200
+	char *p;
201
+	unsigned int len;
202
+
203
+	p = name;
204
+	while ( ( len = *p ) ) {
205
+		*(p++) = '.';
206
+		p += len;
207
+	}
208
+	
209
+	return name + 1;
210
+}
211
+
195 212
 /*
196 213
  * Decompress a DNS name.
197 214
  *
@@ -281,10 +298,15 @@ static int dns_resolv ( struct in_addr *addr, const char *name ) {
281 298
 					( struct dns_rr_info_cname * ) rr_info;
282 299
 				char *cname = rr_info_cname->cname;
283 300
 
284
-				DBG ( "DNS found CNAME\n" );
285 301
 				query_info = ( void * )
286 302
 					dns_decompress_name ( query.payload,
287 303
 							      cname, reply );
304
+				DBG ( "DNS found CNAME %s\n",
305
+				      dns_unmake_name ( query.payload ) );
306
+				DBG ( "", /* Reconstruct name */
307
+				      dns_make_name ( query.payload,
308
+						      query.payload + 1 ) );
309
+				
288 310
 				query_info->qtype = htons ( DNS_TYPE_A );
289 311
 				query_info->qclass = htons ( DNS_CLASS_IN );
290 312
 

Loading…
Cancel
Save