Print this page
1926 libresolv evades compiler warnings

@@ -18,10 +18,11 @@
  *
  * CDDL HEADER END
  */
 
 /*
+ * Copyright 2015 Gary Mills
  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
 /*      Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */

@@ -35,21 +36,23 @@
  * University Acknowledgment- Portions of this document are derived from
  * software developed by the University of California, Berkeley, and its
  * contributors.
  */
 
-#pragma ident   "%Z%%M% %I%     %E% SMI"
-
 #include <stdio.h>
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <sys/stat.h>
 #include <netinet/in.h>
 #include <arpa/nameser.h>
 #include <resolv.h>
+#include <string.h>
+#include <stdlib.h>
+#include <unistd.h>
 #include <errno.h>
 #include <netdb.h>
+#include "crossl.h"
 
 /*
  * Kludge to time out quickly if there is no /etc/resolv.conf
  * and a TCP connection to the local DNS server fails.
  *

@@ -95,15 +98,15 @@
                         ns = socket(AF_INET, SOCK_STREAM, 0);
                         IN_SET_LOOPBACK_ADDR(&ns_sin);
                         ns_sin.sin_port = htons(NAMESERVER_PORT);
                         if (connect(ns, (struct sockaddr *) &ns_sin,
                                     sizeof ns_sin) == -1) {
-                                close(ns);
+                                (void) close(ns);
                                 return(-1);
                         }
                         else {
-                                close(ns);
+                                (void) close(ns);
                                 return(0);
                         }
                 }
         
                 return(0);

@@ -126,13 +129,13 @@
         struct rrec *newrr;     /* new rr for modify or append */
         char *buf;              /* buffer to put query */
         int buflen;             /* size of buffer */
 {
         register HEADER *hp;
-        register char *cp;
+        register u_char *cp;
         register int n;
-        char *dnptrs[10], **dpp, **lastdnptr;
+        u_char *dnptrs[10], **dpp, **lastdnptr;
 
 #ifdef DEBUG
         if (_res.options & RES_DEBUG)
                 printf("res_mkquery(%d, %s, %d, %d)\n", op, dname, class, type);
 #endif /* DEBUG */

@@ -157,34 +160,35 @@
          * Initialize header fields.
          */
         if ((buf == NULL) || (buflen < sizeof (HEADER)))
                 return (-1);
 #ifdef SYSV
-        memset(buf, 0, sizeof (HEADER));
+        (void) memset(buf, 0, sizeof (HEADER));
 #else
         bzero(buf, sizeof (HEADER));
 #endif
         hp = (HEADER *) buf;
         hp->id = htons(++_res.id);
         hp->opcode = op;
         hp->pr = (_res.options & RES_PRIMARY) != 0;
         hp->rd = (_res.options & RES_RECURSE) != 0;
         hp->rcode = NOERROR;
-        cp = buf + sizeof (HEADER);
+        cp = (u_char *)(buf + sizeof (HEADER));
         buflen -= sizeof (HEADER);
         dpp = dnptrs;
-        *dpp++ = buf;
+        *dpp++ = (u_char *)buf;
         *dpp++ = NULL;
         lastdnptr = dnptrs + sizeof (dnptrs) / sizeof (dnptrs[0]);
         /*
          * perform opcode specific processing
          */
         switch (op) {
         case QUERY:
                 if ((buflen -= QFIXEDSZ) < 0)
                         return (-1);
-                if ((n = dn_comp(dname, cp, buflen, dnptrs, lastdnptr)) < 0)
+                if ((n = dn_comp((u_char *)dname, cp, buflen,
+                    dnptrs, lastdnptr)) < 0)
                         return (-1);
                 cp += n;
                 buflen -= n;
                 putshort(type, cp);
                 cp += sizeof (u_short);

@@ -195,11 +199,12 @@
                         break;
                 /*
                  * Make an additional record for completion domain.
                  */
                 buflen -= RRFIXEDSZ;
-                if ((n = dn_comp(data, cp, buflen, dnptrs, lastdnptr)) < 0)
+                if ((n = dn_comp((u_char *)data, cp, buflen,
+                    dnptrs, lastdnptr)) < 0)
                         return (-1);
                 cp += n;
                 buflen -= n;
                 putshort(T_NULL, cp);
                 cp += sizeof (u_short);

@@ -227,11 +232,11 @@
                 cp += sizeof (u_long);
                 putshort(datalen, cp);
                 cp += sizeof (u_short);
                 if (datalen) {
 #ifdef SYSV
-                        memcpy((void *)cp, (void *)data, datalen);
+                        (void) memcpy((void *)cp, (void *)data, datalen);
 #else
                         bcopy(data, cp, datalen);
 #endif
                         cp += datalen;
                 }

@@ -252,11 +257,12 @@
                  * calls them differently: specifies data for UPDATED; server
                  * ignores data if specified for UPDATEDA.
                  */
         case UPDATEDA:
                 buflen -= RRFIXEDSZ + datalen;
-                if ((n = dn_comp(dname, cp, buflen, dnptrs, lastdnptr)) < 0)
+                if ((n = dn_comp((u_char *)dname, cp, buflen,
+                    dnptrs, lastdnptr)) < 0)
                         return (-1);
                 cp += n;
                 putshort(type, cp);
                 cp += sizeof (u_short);
                 putshort(class, cp);

@@ -279,11 +285,12 @@
                 }
                 /* Else UPDATEM/UPDATEMA, so drop into code for UPDATEA */
 
         case UPDATEA:   /* Add new resource record */
                 buflen -= RRFIXEDSZ + datalen;
-                if ((n = dn_comp(dname, cp, buflen, dnptrs, lastdnptr)) < 0)
+                if ((n = dn_comp((u_char *)dname, cp, buflen,
+                    dnptrs, lastdnptr)) < 0)
                         return (-1);
                 cp += n;
                 putshort(newrr->r_type, cp);
                 cp += sizeof (u_short);
                 putshort(newrr->r_class, cp);

@@ -303,7 +310,7 @@
                 hp->ancount = htons(0);
                 break;
 
 #endif /* ALLOW_UPDATES */
         }
-        return (cp - buf);
+        return ((char *)cp - buf);
 }