Revision: 14932
Author:   adrian.chadd
Date:     Fri Jul 22 08:25:19 2011
Log:      Begin fleshing out the IPv6 reverse IP lookup routine.


http://code.google.com/p/lusca-cache/source/detail?r=14932

Modified:
 /playpen/LUSCA_HEAD_ipv6/include/rfc1035.h
 /playpen/LUSCA_HEAD_ipv6/lib/rfc1035.c

=======================================
--- /playpen/LUSCA_HEAD_ipv6/include/rfc1035.h  Thu Jan 20 17:57:31 2011
+++ /playpen/LUSCA_HEAD_ipv6/include/rfc1035.h  Fri Jul 22 08:25:19 2011
@@ -95,6 +95,9 @@
     size_t sz,
     unsigned short qid,
     rfc1035_query * query);
+extern ssize_t rfc3596BuildPTR6Query(const struct in6_addr addr6,
+    char *buf, size_t sz, unsigned short qid, rfc1035_query * query);
+
 extern void rfc1035SetQueryID(char *, unsigned short qid);
 extern int rfc1035MessageUnpack(const char *buf,
     size_t sz,
=======================================
--- /playpen/LUSCA_HEAD_ipv6/lib/rfc1035.c      Fri Jul 22 08:10:10 2011
+++ /playpen/LUSCA_HEAD_ipv6/lib/rfc1035.c      Fri Jul 22 08:25:19 2011
@@ -641,7 +641,8 @@
  * Returns the size of the query
  */
 ssize_t
-rfc1035BuildAQuery(const char *hostname, char *buf, size_t sz, unsigned short qid, rfc1035_query * query)
+rfc1035BuildAQuery(const char *hostname, char *buf, size_t sz,
+  unsigned short qid, rfc1035_query * query)
 {
     static rfc1035_message h;
     size_t offset = 0;
@@ -704,7 +705,8 @@
  * Returns the size of the query
  */
 ssize_t
-rfc1035BuildPTRQuery(const struct in_addr addr, char *buf, size_t sz, unsigned short qid, rfc1035_query * query)
+rfc1035BuildPTRQuery(const struct in_addr addr, char *buf, size_t sz,
+  unsigned short qid, rfc1035_query * query)
 {
     static rfc1035_message h;
     size_t offset = 0;
@@ -736,6 +738,49 @@
     assert(offset <= sz);
     return offset;
 }
+
+/*
+ * XXX this doesn't belong here?
+ */
+ssize_t
+rfc3596BuildPTR6Query(const struct in6_addr addr6, char *buf, size_t sz,
+    unsigned short qid, rfc1035_query * query)
+{
+    static rfc1035_message h;
+    size_t offset = 0;
+    static char rev[RFC1035_MAXHOSTNAMESZ];
+    int i;
+    const uint8_t *r = addr6.s6_addr;
+    char *p = rev;
+
+    /* Encode the IPv6 address in reverse */
+    for (i = 15; i >= 0; i--, p+=4) {
+        snprintf(p, 5, "%1x.%1x.", ((r[i]) & 0xf), (r[i] >> 4) & 0xf);
+    }
+    snprintf(p,10,"ip6.arpa.");
+
+    memset(&h, '\0', sizeof(h));
+    h.id = qid;
+    h.qr = 0;
+    h.rd = 1;
+    h.opcode = 0;              /* QUERY */
+    h.qdcount = (unsigned int) 1;
+    offset += rfc1035HeaderPack(buf + offset, sz - offset, &h);
+    offset += rfc1035QuestionPack(buf + offset,
+        sz - offset,
+        rev,
+        RFC1035_TYPE_PTR,
+        RFC1035_CLASS_IN);
+    if (query) {
+        query->qtype = RFC1035_TYPE_PTR;
+        query->qclass = RFC1035_CLASS_IN;
+        xstrncpy(query->name, rev, sizeof(query->name));
+    }
+    assert(offset <= sz);
+    return offset;
+}
+
+

 /*
  * We're going to retry a former query, but we

--
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.

Reply via email to