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,25 +36,33 @@
  * 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 <sys/types.h>
 #include <sys/sockio.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
 #include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <stropts.h>
 #include <arpa/nameser.h>
 #include <resolv.h>
 
 #include <netinet/in.h>
 #include <net/if.h>
 #include <netinet/if_ether.h>
 #include <arpa/inet.h>
 
+/*
+ * Undocumented external function in libnsl
+ */
+extern int
+getdomainname(char *, int);
+
 #define MAXIFS  256
 
 /*
  * Resolver state default settings
  */

@@ -85,17 +94,10 @@
 {
         register FILE *fp;
         register char *cp, **pp;
         register int n;
         char buf[BUFSIZ];
-#ifdef SYSV
-        extern char *strchr();
-#else
-        extern char *index();
-#endif
-        extern char *strcpy(), *strncpy();
-        extern char *getenv();
         int nserv = 0;    /* number of nameserver records read from file */
         int haveenv = 0;
         int havesearch = 0;
 
         _res.nsaddr.sin_addr.s_addr =  htonl(INADDR_LOOPBACK); /* INADDR_ANY */

@@ -109,11 +111,10 @@
                 register struct ifreq *ifrp;
                 struct ifreq ifr;
                 unsigned bufsize;
                 unsigned int flags;
                 char *buf;
-                extern void *malloc();
 
                 if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
                         perror("socket");
                         return (-1);
                 }

@@ -122,41 +123,41 @@
                 }
                 bufsize = numifs * sizeof (struct ifreq);
                 buf = (char *)malloc(bufsize);
                 if (buf == NULL) {
                         perror("out of memory");
-                        close(s);
+                        (void) close(s);
                         return (-1);
                 }
                 ifc.ifc_len = bufsize;
                 ifc.ifc_buf = buf;
                 if (ioctl(s, SIOCGIFCONF, (char *)&ifc) < 0) {
                         perror("ifconfig: SIOCGIFCONF");
-                        close(s);
+                        (void) close(s);
                         free(buf);
                         return (-1);
                 }
 
                 int_up = 0;
                 ifrp = ifc.ifc_req;
                 for (n = ifc.ifc_len / sizeof (struct ifreq); n > 0;
                                                                 n--, ifrp++) {
-                        memset((void *) &ifr, 0, sizeof (ifr));
+                        (void) memset((void *) &ifr, 0, sizeof (ifr));
                         strncpy(ifr.ifr_name, ifrp->ifr_name,
                                                         sizeof (ifr.ifr_name));
                         if (ioctl(s, SIOCGIFFLAGS, (char *)&ifr) < 0) {
                                 perror("SIOCGIFFLAGS");
-                                close(s);
+                                (void) close(s);
                                 free(buf);
                                 return (-1);
                         }
                         flags = ifr.ifr_flags;
                         /* we are looking for a non-loopback interface */
                         if ((flags & IFF_UP) && ((flags & IFF_LOOPBACK) == 0))
                                 int_up = 1;
                 }
-                close(s);
+                (void) close(s);
                 free(buf);
                 if (int_up == 0) /* all the non-LOOPBACK interfaces are DOWN */
                         return (-1);
         }
 #endif /* SIOCGIFNUM */

@@ -164,11 +165,11 @@
 
         /*
          * for the benefit of hidden NIS domains, we use the same procedure
          * as sendmail: convert leading + to dot, then drop to first dot
          */
-        getdomainname(buf, BUFSIZ);
+        (void) getdomainname(buf, BUFSIZ);
         if (buf[0] == '+')
         buf[0] = '.';
 #ifdef SYSV
         cp = strchr(buf, (int)'.');
 #else