Gisle Vanem | 10 Aug 2012 13:17
Picon
Favicon
Gravatar

adig.c calls perror()

adig.c calls perror() when select() fail. This doesn't work on
Winsock; perror() prints errno string, not WSAGetLastError().
So I suggest we add a new ares_perror() function to ares_strerror.c:

--- Git-latest\ares_strerror.c  Wed Oct 12 11:43:31 2011
+++ ares_strerror.c     Fri Aug 10 13:01:10 2012
 <at>  <at>  -54,3 +54,17  <at>  <at> 
   else
     return "unknown";
 }
+
+/* perror() doesn't show Winsock errors.
+ */
+void ares_perror (const char *str)
+{
+#ifdef USE_WINSOCK
+  if (str && *str)
+     fprintf (stderr, "%s: ", str);
+  fprintf (stderr, "Winsock error %d\n", SOCKERRNO);
+#else
+  perror (str);
+#endif
+}
+

And a prototype for it in ares.h:

--- Git-latest\ares.h   Sun Jun 24 21:37:50 2012
+++ ares.h      Fri Aug 10 12:58:25 2012
 <at>  <at>  -547,6 +547,8  <at>  <at> 

 CARES_EXTERN const char *ares_strerror(int code);

+CARES_EXTERN void ares_perror (const char *str);
+
 /* TODO:  Hold port here as well. */
 struct ares_addr_node {
   struct ares_addr_node *next;

So now adig should use this function:

diff -u3 -Hb Git-latest\adig.c .\adig.c
--- Git-latest\adig.c   Wed Oct 12 11:43:30 2011
+++ .\adig.c    Fri Aug 10 12:59:09 2012
 <at>  <at>  -392,7 +392,7  <at>  <at> 
       count = select(nfds, &read_fds, &write_fds, NULL, tvp);
       if (count < 0 && SOCKERRNO != EINVAL)
         {
-          perror("select");
+          ares_perror("select");
           return 1;
         }
       ares_process(channel, &read_fds, &write_fds);

-----------

Ideally, some error-text should be returned for Winsock
errors later. And some words in ares_strerror.3. 

--gv


Gmane