rwrap: Add support for res_[n]query().
authorAndreas Schneider <asn@samba.org>
Tue, 2 Sep 2014 12:06:00 +0000 (14:06 +0200)
committerMichael Adam <obnox@samba.org>
Tue, 21 Oct 2014 11:39:28 +0000 (13:39 +0200)
Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
src/resolv_wrapper.c

index b1ee978..810498f 100644 (file)
@@ -132,6 +132,18 @@ struct rwrap_libc_fns {
        void (*libc___res_nclose)(struct __res_state *state);
        void (*libc_res_close)(void);
        void (*libc___res_close)(void);
+       int (*libc_res_nquery)(struct __res_state *state,
+                              const char *dname,
+                              int class,
+                              int type,
+                              unsigned char *answer,
+                              int anslen);
+       int (*libc___res_nquery)(struct __res_state *state,
+                                const char *dname,
+                                int class,
+                                int type,
+                                unsigned char *answer,
+                                int anslen);
 };
 
 struct rwrap {
@@ -317,6 +329,36 @@ static void libc_res_nclose(struct __res_state *state)
 #endif
 }
 
+static int libc_res_nquery(struct __res_state *state,
+                          const char *dname,
+                          int class,
+                          int type,
+                          unsigned char *answer,
+                          int anslen)
+{
+#if defined(HAVE_RES_NQUERY)
+       rwrap_load_lib_function(RWRAP_LIBRESOLV, res_nquery);
+
+       return rwrap.fns.libc_res_nquery(state,
+                                        dname,
+                                        class,
+                                        type,
+                                        answer,
+                                        anslen);
+#elif defined(HAVE___RES_NQUERY)
+       rwrap_load_lib_function(RWRAP_LIBRESOLV, __res_nquery);
+
+       return rwrap.fns.libc___res_nquery(state,
+                                          dname,
+                                          class,
+                                          type,
+                                          answer,
+                                          anslen);
+#else
+#error "No res_nquery function"
+#endif
+}
+
 
 /****************************************************************************
  *   RES_NINIT
@@ -427,3 +469,105 @@ void __res_close(void)
 {
        rwrap_res_close();
 }
+
+/****************************************************************************
+ *   RES_NQUERY
+ ***************************************************************************/
+
+static int rwrap_res_nquery(struct __res_state *state,
+                           const char *dname,
+                           int class,
+                           int type,
+                           unsigned char *answer,
+                           int anslen)
+{
+       int rc;
+#ifndef NDEBUG
+       int i;
+#endif
+
+       RWRAP_LOG(RWRAP_LOG_TRACE,
+                 "Resolve the domain name [%s] - class=%d, type=%d",
+                 dname, class, type);
+#ifndef NDEBUG
+       for (i = 0; i < state->nscount; i++) {
+               char ip[INET6_ADDRSTRLEN];
+
+               inet_ntop(AF_INET, &state->nsaddr_list[i].sin_addr, ip, sizeof(ip));
+               RWRAP_LOG(RWRAP_LOG_TRACE,
+                         "        nameserver: %s",
+                         ip);
+       }
+#endif
+
+       rc = libc_res_nquery(state, dname, class, type, answer, anslen);
+
+       RWRAP_LOG(RWRAP_LOG_TRACE,
+                 "The returned response length is: %d",
+                 rc);
+
+       return rc;
+}
+
+#if defined(HAVE_RES_NQUERY)
+int res_nquery(struct __res_state *state,
+              const char *dname,
+              int class,
+              int type,
+              unsigned char *answer,
+              int anslen)
+#elif defined(HAVE___RES_NQUERY)
+int __res_nquery(struct __res_state *state,
+                const char *dname,
+                int class,
+                int type,
+                unsigned char *answer,
+                int anslen)
+#endif
+{
+       return rwrap_res_nquery(state, dname, class, type, answer, anslen);
+}
+
+/****************************************************************************
+ *   RES_QUERY
+ ***************************************************************************/
+
+static int rwrap_res_query(const char *dname,
+                          int class,
+                          int type,
+                          unsigned char *answer,
+                          int anslen)
+{
+       int rc;
+
+       rc = rwrap_res_ninit(&rwrap_res_state);
+       if (rc != 0) {
+               return rc;
+       }
+
+       rc = rwrap_res_nquery(&rwrap_res_state,
+                             dname,
+                             class,
+                             type,
+                             answer,
+                             anslen);
+
+       return rc;
+}
+
+#if defined(HAVE_RES_QUERY)
+int res_query(const char *dname,
+             int class,
+             int type,
+             unsigned char *answer,
+             int anslen)
+#elif defined(HAVE___RES_QUERY)
+int __res_query(const char *dname,
+               int class,
+               int type,
+               unsigned char *answer,
+               int anslen)
+#endif
+{
+       return rwrap_res_query(dname, class, type, answer, anslen);
+}