chiark / gitweb /
src/, client/: Use the new adns_text2addr/addr2text functions.
[adns.git] / src / internal.h
index 50733b5eb44515ad8f4450105491d366479ced76..6c6a77eccd196c5477039d1b63b758f1e96ee99f 100644 (file)
@@ -124,6 +124,13 @@ typedef struct {
   struct timeval now;
 } parseinfo;
 
+union gen_addr {
+  struct in_addr v4;
+  struct in6_addr v6;
+};
+
+struct af_addr { int af; union gen_addr addr; };
+
 union checklabel_state {
   struct { byte ipv[4]; } ptr;
 };
@@ -134,7 +141,7 @@ typedef struct {
 
   union {
     struct {
-      struct in_addr addr;
+      struct af_addr addr;
     } ptr;
   } tinfo; /* type-specific state for the query itself: zero-init if you
            * don't know better. */
@@ -148,7 +155,7 @@ typedef struct typeinfo {
   adns_rrtype typekey;
   const char *rrtname;
   const char *fmtname;
-  int rrsz;
+  int fixed_rrsz;
 
   void (*makefinal)(adns_query qu, void *data);
   /* Change memory management of *data.
@@ -166,7 +173,7 @@ typedef struct typeinfo {
   /* Parse one RR, in dgram of length dglen, starting at cbyte and
    * extending until at most max.
    *
-   * The RR should be stored at *store_r, of length qu->typei->rrsz.
+   * The RR should be stored at *store_r, of length qu->typei->getrrsz().
    *
    * If there is an overrun which might indicate truncation, it should set
    * *rdstart to -1; otherwise it may set it to anything else positive.
@@ -191,12 +198,17 @@ typedef struct typeinfo {
    * because lablen is zero.
    */
 
-  void (*postsort)(adns_state ads, void *array, int nrrs,
+  void (*postsort)(adns_state ads, void *array, int nrrs,int rrsz,
                   const struct typeinfo *typei);
   /* Called immediately after the RRs have been sorted, and may rearrange
    * them.  (This is really for the benefit of SRV's bizarre weighting
    * stuff.)  May be 0 to mean nothing needs to be done.
    */
+
+  int (*getrrsz)(const struct typeinfo *typei, adns_rrtype type);
+  /* Return the output resource-record element size; if this is null, then
+   * the rrsz member can be used.
+   */
 } typeinfo;
 
 adns_status adns__ckl_hostname(adns_state ads, adns_queryflags flags,
@@ -353,16 +365,79 @@ struct adns__state {
   struct sigaction stdsigpipe;
   sigset_t stdsigmask;
   struct pollfd pollfds_buf[MAX_POLLFDS];
-  struct server {
-    struct in_addr addr;
-  } servers[MAXSERVERS];
+  adns_rr_addr servers[MAXSERVERS];
   struct sortlist {
-    struct in_addr base, mask;
+    int af;
+    union gen_addr base, mask;
   } sortlist[MAXSORTLIST];
   char **searchlist;
   unsigned short rand48xsubi[3];
 };
 
+/* From addrfam.c: */
+
+extern int adns__af_supported_p(int af);
+/* Return nonzero if the address family af known to the library and supported
+ * by the other addrfam operations.  Note that the other operations will
+ * abort on an unrecognized address family rather than returning an error
+ * code.
+ */
+
+extern int adns__genaddr_equal_p(int af, const union gen_addr *a,
+                                int bf, const void *b);
+/* b should point to a `struct in_addr' or equivalent for the address family
+ * bf.  Returns nonzero if the two addresses are equal.
+ */
+
+extern int adns__sockaddr_equal_p(const struct sockaddr *sa,
+                                 const struct sockaddr *sb);
+/* Return nonzero if the two socket addresses are equal (in all significant
+ * respects).
+ */
+
+extern int adns__addr_width(int af);
+/* Return the width of addresses of family af, in bits. */
+
+extern void adns__prefix_mask(int af, int len, union gen_addr *mask_r);
+/* Store in mask_r an address mask for address family af, whose first len
+ * bits are set and the remainder are clear.  This is what you want for
+ * converting a prefix length into a netmask.
+ */
+
+extern int adns__guess_prefix_length(int af, const union gen_addr *addr);
+/* Given a network base address, guess the appropriate prefix length based on
+ * the appropriate rules for the address family (e.g., for IPv4, this uses
+ * the old address classes).
+ */
+
+extern int adns__addr_match_p(int addraf, const union gen_addr *addr,
+                             int netaf, const union gen_addr *base,
+                             const union gen_addr *mask);
+/* Given an address af (with family addraf) and a network (with family netaf,
+ * base address base, and netmask mask), return nonzero if the address lies
+ * within the network.
+ */
+
+extern void adns__sockaddr_extract(const struct sockaddr *sa,
+                                  union gen_addr *a_r, int *port_r);
+/* Extract fields from the socket address, filling in *a_r and *port_r with
+ * the address and (integer, host byte-order) port number, respectively.
+ * Either (or, pointlessly, both) of a_r and port_r may be null to mean
+ * `don't care'.
+ */
+
+extern void adns__sockaddr_inject(const union gen_addr *a, int port,
+                                 struct sockaddr *sa);
+/* Inject fields into the socket adress sa.  If a is not null, copy the
+ * address in; if port is not -1, then copy the port (converting from host
+ * byte-order).  Assumes that sa->sa_family is already set correctly.
+ */
+
+char *adns__sockaddr_ntoa(const struct sockaddr *sa, char *buf);
+/* Convert sa to a string, and write it to buf, which must be at least
+ * ADNS_ADDR2TEXT_BUFLEN bytes long (unchecked).  Return buf; can't fail.
+ */
+
 /* From setup.c: */
 
 int adns__setnonblock(adns_state ads, int fd); /* => errno value */
@@ -405,6 +480,11 @@ const char *adns__diag_domain(adns_state ads, int serv, adns_query qu,
  * vb before using the return value.
  */
 
+int adns__getrrsz_default(const typeinfo *typei, adns_rrtype type);
+/* Default function for the `getrrsz' type hook; returns the `fixed_rrsz'
+ * value from the typeinfo entry.
+ */
+
 void adns__isort(void *array, int nobjs, int sz, void *tempbuf,
                 int (*needswap)(void *context, const void *a, const void *b),
                 void *context);
@@ -459,8 +539,8 @@ void adns__query_send(adns_query qu, struct timeval now);
 /* From query.c: */
 
 adns_status adns__internal_submit(adns_state ads, adns_query *query_r,
-                                 const typeinfo *typei, vbuf *qumsg_vb,
-                                 int id,
+                                 const typeinfo *typei, adns_rrtype type,
+                                 vbuf *qumsg_vb, int id,
                                  adns_queryflags flags, struct timeval now,
                                  qcontext *ctx);
 /* Submits a query (for internal use, called during external submits).