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
 #define DNS_RESOLVER_H
2
 #define DNS_RESOLVER_H
3
 
3
 
4
 #include "stdint.h"
4
 #include "stdint.h"
5
-#include "nic.h"
6
 #include "in.h"
5
 #include "in.h"
6
+#include "ip.h"
7
+#include "udp.h"
7
 
8
 
8
 /*
9
 /*
9
  * Constants
10
  * Constants
76
 struct dns_rr_info_cname {
77
 struct dns_rr_info_cname {
77
 	struct dns_rr_info;
78
 	struct dns_rr_info;
78
 	char		cname[0];
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
 #endif /* DNS_RESOLVER_H */
92
 #endif /* DNS_RESOLVER_H */

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

145
  * query.  Returns a pointer to the RR, or NULL if no answer found.
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
 	int i, cmp;
150
 	int i, cmp;
151
 	const char *p = ( ( char * ) reply ) + sizeof ( struct dns_header );
151
 	const char *p = ( ( char * ) reply ) + sizeof ( struct dns_header );
152
 
152
 
192
 	return dest;
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
  * Decompress a DNS name.
213
  * Decompress a DNS name.
197
  *
214
  *
281
 					( struct dns_rr_info_cname * ) rr_info;
298
 					( struct dns_rr_info_cname * ) rr_info;
282
 				char *cname = rr_info_cname->cname;
299
 				char *cname = rr_info_cname->cname;
283
 
300
 
284
-				DBG ( "DNS found CNAME\n" );
285
 				query_info = ( void * )
301
 				query_info = ( void * )
286
 					dns_decompress_name ( query.payload,
302
 					dns_decompress_name ( query.payload,
287
 							      cname, reply );
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
 				query_info->qtype = htons ( DNS_TYPE_A );
310
 				query_info->qtype = htons ( DNS_TYPE_A );
289
 				query_info->qclass = htons ( DNS_CLASS_IN );
311
 				query_info->qclass = htons ( DNS_CLASS_IN );
290
 
312
 

Loading…
Cancel
Save