chiark / gitweb /
src/, client/: Use the new adns_text2addr/addr2text functions.
[adns.git] / src / internal.h
index 7ad6daa0d8a10612e4448155e4c405be29ae7e6f..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. */
@@ -358,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 */