chiark / gitweb /
Make adns__sockaddr_ntop use a caller-supplied buffer.
[adns] / src / internal.h
index 1a9c61bb48e77bd34da791fee2bff53914eed9b4..bddb1979025d03d14b681e2c862fe194eaf8281b 100644 (file)
@@ -72,6 +72,9 @@ typedef unsigned char byte;
 #define DNS_INADDR_ARPA "in-addr", "arpa"
 #define DNS_IP6_ARPA "ip6", "arpa"
 
+#define ADDR_MAXRRTYPES 2
+#define MAX_ADDRSTRLEN 64
+
 #define STRINGIFY(x) REALLY_STRINGIFY(x)
 #define REALLY_STRINGIFY(x) #x
 
@@ -96,8 +99,7 @@ enum {
   adns__qf_senddirect = 0x00100000,/* don't call the `query_send' type hook */
   adns__qf_nosend     = 0x00200000,/* don't send the query when submitting */
   adns__qf_addr_answer= 0x01000000,/* addr query received an answer */
-  adns__qf_addr_cnhack= 0x02000000,/* addr query found cname inconsistency */
-  adns__qf_addr_cname = 0x04000000 /* addr subquery performed on cname */
+  adns__qf_addr_cname = 0x02000000 /* addr subquery performed on cname */
 };
 
 /* Shared data structures */
@@ -204,6 +206,11 @@ typedef struct typeinfo {
    * stuff.)  May be 0 to mean nothing needs to be done.
    */
 
+  int (*getrrsz)(adns_rrtype type);
+  /* Return the output resource-record element size; if this is null, then
+   * the rrsz member can be used.
+   */
+
   void (*query_send)(adns_query qu, struct timeval now);
   /* Send the query to nameservers, and hook it into the appropriate queue.
    * Normal behaviour is to call adns__query_send, but this can be overridden
@@ -294,6 +301,13 @@ struct adns__query {
   struct timeval timeout;
   time_t expires; /* Earliest expiry time of any record we used. */
 
+  union {
+    struct {
+      size_t nrrty, onrrty;
+      adns_rrtype rrty[ADDR_MAXRRTYPES];
+    } addr;
+  } t;                                 /* type-specific state */
+
   qcontext ctx;
 
   /* Possible states:
@@ -398,7 +412,9 @@ int adns__setnonblock(adns_state ads, int fd); /* => errno value */
 
 /* From general.c: */
 
-const char *adns__sockaddr_ntoa(struct sockaddr *sa, size_t n);
+const char *adns__sockaddr_ntoa(struct sockaddr *sa, size_t n, char *buf);
+/* Buffer must be at least MAX_ADDRSTRLEN bytes long. */
+
 void adns__vlprintf(adns_state ads, const char *fmt, va_list al);
 void adns__lprintf(adns_state ads, const char *fmt,
                   ...) PRINTFFORMAT(2,3);
@@ -555,8 +571,7 @@ void *adns__alloc_preserved(adns_query qu, size_t sz);
  *  answer->cname and answer->owner are _preserved.
  */
 
-void adns__transfer_interim(adns_query from, adns_query to,
-                           void *block, size_t sz);
+void adns__transfer_interim(adns_query from, adns_query to, void *block);
 /* Transfers an interim allocation from one query to another, so that
  * the `to' query will have room for the data when we get to makefinal
  * and so that the free will happen when the `to' query is freed