Revision: 14705
Author: adrian.chadd
Date: Sat May 29 01:02:59 2010
Log: IPv6 DNS related merges.
* Merge in the ipv6 related changes from /branches/ipv6_dns r13271
* Remove the test code from lib/rfc1035.c
http://code.google.com/p/lusca-cache/source/detail?r=14705
Modified:
/branches/LUSCA_HEAD/lib/rfc1035.c
/branches/LUSCA_HEAD/test-suite/lib/rfc1035.c
=======================================
--- /branches/LUSCA_HEAD/lib/rfc1035.c Fri May 28 22:43:29 2010
+++ /branches/LUSCA_HEAD/lib/rfc1035.c Sat May 29 01:02:59 2010
@@ -743,93 +743,3 @@
memcpy(buf, &s, sizeof(s));
}
-#if DRIVER
-#include <sys/socket.h>
-#include <sys/time.h>
-int
-main(int argc, char *argv[])
-{
- char input[512];
- char buf[512];
- char rbuf[512];
- size_t sz = 512;
- unsigned short sid;
- int s;
- int rl;
- struct sockaddr_in S;
- if (3 != argc) {
- fprintf(stderr, "usage: %s ip port\n", argv[0]);
- return 1;
- }
- setbuf(stdout, NULL);
- setbuf(stderr, NULL);
- s = socket(PF_INET, SOCK_DGRAM, 0);
- if (s < 0) {
- perror("socket");
- return 1;
- }
- memset(&S, '\0', sizeof(S));
- S.sin_family = AF_INET;
- S.sin_port = htons(atoi(argv[2]));
- S.sin_addr.s_addr = inet_addr(argv[1]);
- while (fgets(input, 512, stdin)) {
- struct in_addr junk;
- strtok(input, "\r\n");
- memset(buf, '\0', 512);
- sz = 512;
- if (inet_aton(input, &junk)) {
- sid = rfc1035BuildPTRQuery(junk, buf, &sz);
- } else {
- sid = rfc1035BuildAQuery(input, buf, &sz);
- }
- sendto(s, buf, sz, 0, (struct sockaddr *) &S, sizeof(S));
- do {
- fd_set R;
- struct timeval to;
- FD_ZERO(&R);
- FD_SET(s, &R);
- to.tv_sec = 10;
- to.tv_usec = 0;
- rl = select(s + 1, &R, NULL, NULL, &to);
- } while (0);
- if (rl < 1) {
- printf("TIMEOUT\n");
- continue;
- }
- memset(rbuf, '\0', 512);
- rl = recv(s, rbuf, 512, 0);
- {
- unsigned short rid = 0;
- int i;
- int n;
- rfc1035_rr *answers = NULL;
- n = rfc1035AnswersUnpack(rbuf,
- rl,
- &answers,
- &rid);
- if (n < 0) {
- printf("ERROR %d\n", rfc1035_errno);
- } else if (rid != sid) {
- printf("ERROR, ID mismatch (%#hx, %#hx)\n", sid, rid);
- } else {
- printf("%d answers\n", n);
- for (i = 0; i < n; i++) {
- if (answers[i].type == RFC1035_TYPE_A) {
- struct in_addr a;
- memcpy(&a, answers[i].rdata, 4);
- printf("A\t%d\t%s\n", answers[i].ttl, inet_ntoa(a));
- } else if (answers[i].type == RFC1035_TYPE_PTR) {
- char ptr[128];
- strncpy(ptr, answers[i].rdata, answers[i].rdlength);
- printf("PTR\t%d\t%s\n", answers[i].ttl, ptr);
- } else {
- fprintf(stderr, "can't print answer type %d\n",
- (int) answers[i].type);
- }
- }
- }
- }
- }
- return 0;
-}
-#endif
=======================================
--- /branches/LUSCA_HEAD/test-suite/lib/rfc1035.c Tue May 4 21:26:31 2010
+++ /branches/LUSCA_HEAD/test-suite/lib/rfc1035.c Sat May 29 01:02:59 2010
@@ -31,7 +31,6 @@
#endif
#include "include/rfc1035.h"
-//#include "include/snprintf.h"
#include <sys/socket.h>
#include <sys/time.h>
@@ -47,6 +46,8 @@
int s;
int rl;
struct sockaddr_in S;
+ struct in_addr a;
+
if (5 != argc) {
fprintf(stderr, "usage: %s ip port <PTR|A|AAAA> <query>\n", argv[0]);
return 1;
@@ -66,14 +67,14 @@
qtype = argv[3];
input = argv[4];
-
do {
- struct in_addr a;
memset(buf, '\0', 512);
sz = 512;
- if (strcmp(qtype, "PTR") == 0) {
- inet_aton(input, &a);
- sz = rfc1035BuildPTRQuery(a, buf, sz, 1, NULL);
+ if (strcmp(qtype, "AAAA") == 0) {
+ sz = rfc1035BuildAAAAQuery(input, buf, sz, 1, NULL);
+ } else if (strcmp(qtype, "PTR") == 0) {
+ inet_aton(input, &a);
+ sz = rfc1035BuildPTRQuery(a, buf, sz, 1, NULL);
} else if (strcmp(qtype, "A") == 0) {
sz = rfc1035BuildAQuery(input, buf, sz, 1, NULL);
} else {
@@ -112,12 +113,7 @@
printf("%d answers\n", n);
for (i = 0; i < n; i++) {
- if (answers->answer[i].type == RFC1035_TYPE_CNAME) {
- /* XXX CNAME content isn't yet treated as a "name" and properly dot'ed?
*/
- char ptr[128];
- strncpy(ptr, answers->answer[i].rdata,
answers->answer[i].rdlength);
- printf("CNAME\t%d\t%s\n", answers->answer[i].ttl, ptr);
- } else if (answers->answer[i].type == RFC1035_TYPE_A) {
+ if (answers->answer[i].type == RFC1035_TYPE_A) {
struct in_addr a;
memcpy(&a, answers->answer[i].rdata, 4);
printf("A\t%d\t%s\n", answers->answer[i].ttl,
inet_ntoa(a));
@@ -125,21 +121,19 @@
char ptr[128];
strncpy(ptr, answers->answer[i].rdata,
answers->answer[i].rdlength);
printf("PTR\t%d\t%s\n", answers->answer[i].ttl, ptr);
-#if 0
- } else if (answers->answer[i].type == RFC1035_TYPE_AAAA) {
- /* XXX this so should be going through getnameinfo() or
something */
- struct sockaddr_in6 s;
- int j;
- bzero(&s, sizeof(s));
- memcpy(&s.sin6_addr, answers->answer[i].rdata, 16);
- for (j = 0; j < 16; j++) {
- printf("%.2x:", (unsigned char)
answers->answer[i].rdata[j]);
- }
- printf("\n");
-#endif
+ } else if (answers->answer[i].type ==
RFC1035_TYPE_AAAA) {
+ /* XXX this so should be going through
getnameinfo() or something */
+ struct sockaddr_in6 s;
+ int j;
+ bzero(&s, sizeof(s));
+ memcpy(&s.sin6_addr, answers->answer[i].rdata, 16);
+ for (j = 0; j < 16; j += 2) {
+ printf("%.2x%.2x:", (unsigned char)
answers->answer[i].rdata[j], (unsigned char) answers->answer[i].rdata[j+1]);
+ }
+ printf("\n");
} else {
- fprintf(stderr, "can't print answer type %d, length
%d\n",
- (int) answers->answer[i].type, (int)
answers->answer[i].rdlength);
+ fprintf(stderr, "can't print answer type %d\n",
+ (int) answers->answer[i].type);
}
}
}
--
You received this message because you are subscribed to the Google Groups
"lusca-commit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/lusca-commit?hl=en.