cleanups on handling SIGHUP; other nits
[unix-history] / usr / src / lib / libc / net / res_send.c
index 194e289..2118794 100644 (file)
@@ -2,21 +2,11 @@
  * Copyright (c) 1985, 1989 Regents of the University of California.
  * All rights reserved.
  *
  * Copyright (c) 1985, 1989 Regents of the University of California.
  * All rights reserved.
  *
- * Redistribution and use in source and binary forms are permitted
- * provided that the above copyright notice and this paragraph are
- * duplicated in all such forms and that any documentation,
- * advertising materials, and other materials related to such
- * distribution and use acknowledge that the software was developed
- * by the University of California, Berkeley.  The name of the
- * University may not be used to endorse or promote products derived
- * from this software without specific prior written permission.
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
- * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ * %sccs.include.redist.c%
  */
 
 #if defined(LIBC_SCCS) && !defined(lint)
  */
 
 #if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)res_send.c 6.23 (Berkeley) %G%";
+static char sccsid[] = "@(#)res_send.c 6.27 (Berkeley) %G%";
 #endif /* LIBC_SCCS and not lint */
 
 /*
 #endif /* LIBC_SCCS and not lint */
 
 /*
@@ -28,16 +18,15 @@ static char sccsid[] = "@(#)res_send.c      6.23 (Berkeley) %G%";
 #include <sys/socket.h>
 #include <sys/uio.h>
 #include <netinet/in.h>
 #include <sys/socket.h>
 #include <sys/uio.h>
 #include <netinet/in.h>
+#include <arpa/nameser.h>
 #include <stdio.h>
 #include <errno.h>
 #include <stdio.h>
 #include <errno.h>
-#include <arpa/nameser.h>
 #include <resolv.h>
 #include <resolv.h>
-
-extern int errno;
+#include <unistd.h>
+#include <string.h>
 
 static int s = -1;     /* socket used for communications */
 static struct sockaddr no_addr;
 
 static int s = -1;     /* socket used for communications */
 static struct sockaddr no_addr;
-  
 
 #ifndef FD_SET
 #define        NFDBITS         32
 
 #ifndef FD_SET
 #define        NFDBITS         32
@@ -49,7 +38,7 @@ static struct sockaddr no_addr;
 #endif
 
 res_send(buf, buflen, answer, anslen)
 #endif
 
 res_send(buf, buflen, answer, anslen)
-       char *buf;
+       const char *buf;
        int buflen;
        char *answer;
        int anslen;
        int buflen;
        char *answer;
        int anslen;
@@ -71,7 +60,7 @@ res_send(buf, buflen, answer, anslen)
 #ifdef DEBUG
        if (_res.options & RES_DEBUG) {
                printf("res_send()\n");
 #ifdef DEBUG
        if (_res.options & RES_DEBUG) {
                printf("res_send()\n");
-               p_query(buf);
+               __p_query(buf);
        }
 #endif DEBUG
        if (!(_res.options & RES_INIT))
        }
 #endif DEBUG
        if (!(_res.options & RES_INIT))
@@ -105,12 +94,13 @@ res_send(buf, buflen, answer, anslen)
                                        terrno = errno;
 #ifdef DEBUG
                                        if (_res.options & RES_DEBUG)
                                        terrno = errno;
 #ifdef DEBUG
                                        if (_res.options & RES_DEBUG)
-                                           perror("socket failed");
+                                           perror("socket (vc) failed");
 #endif DEBUG
                                        continue;
                                }
 #endif DEBUG
                                        continue;
                                }
-                               if (connect(s, &(_res.nsaddr_list[ns]),
-                                  sizeof(struct sockaddr)) < 0) {
+                               if (connect(s,
+                                   (struct sockaddr *)&(_res.nsaddr_list[ns]),
+                                   sizeof(struct sockaddr)) < 0) {
                                        terrno = errno;
 #ifdef DEBUG
                                        if (_res.options & RES_DEBUG)
                                        terrno = errno;
 #ifdef DEBUG
                                        if (_res.options & RES_DEBUG)
@@ -127,7 +117,7 @@ res_send(buf, buflen, answer, anslen)
                        len = htons((u_short)buflen);
                        iov[0].iov_base = (caddr_t)&len;
                        iov[0].iov_len = sizeof(len);
                        len = htons((u_short)buflen);
                        iov[0].iov_base = (caddr_t)&len;
                        iov[0].iov_len = sizeof(len);
-                       iov[1].iov_base = buf;
+                       iov[1].iov_base = (char *)buf;
                        iov[1].iov_len = buflen;
                        if (writev(s, iov, 2) != sizeof(len) + buflen) {
                                terrno = errno;
                        iov[1].iov_len = buflen;
                        if (writev(s, iov, 2) != sizeof(len) + buflen) {
                                terrno = errno;
@@ -217,8 +207,17 @@ res_send(buf, buflen, answer, anslen)
                        /*
                         * Use datagrams.
                         */
                        /*
                         * Use datagrams.
                         */
-                       if (s < 0)
+                       if (s < 0) {
                                s = socket(AF_INET, SOCK_DGRAM, 0);
                                s = socket(AF_INET, SOCK_DGRAM, 0);
+                               if (s < 0) {
+                                       terrno = errno;
+#ifdef DEBUG
+                                       if (_res.options & RES_DEBUG)
+                                           perror("socket (dg) failed");
+#endif DEBUG
+                                       continue;
+                               }
+                       }
 #if    BSD >= 43
                        /*
                         * I'm tired of answering this question, so:
 #if    BSD >= 43
                        /*
                         * I'm tired of answering this question, so:
@@ -243,7 +242,7 @@ res_send(buf, buflen, answer, anslen)
                                 * from another server.
                                 */
                                if (connected == 0) {
                                 * from another server.
                                 */
                                if (connected == 0) {
-                                       if (connect(s, &_res.nsaddr_list[ns],
+                       if (connect(s, (struct sockaddr *)&_res.nsaddr_list[ns],
                                            sizeof(struct sockaddr)) < 0) {
 #ifdef DEBUG
                                                if (_res.options & RES_DEBUG)
                                            sizeof(struct sockaddr)) < 0) {
 #ifdef DEBUG
                                                if (_res.options & RES_DEBUG)
@@ -272,7 +271,7 @@ res_send(buf, buflen, answer, anslen)
                                }
 #endif BSD
                                if (sendto(s, buf, buflen, 0,
                                }
 #endif BSD
                                if (sendto(s, buf, buflen, 0,
-                                   &_res.nsaddr_list[ns],
+                                   (struct sockaddr *)&_res.nsaddr_list[ns],
                                    sizeof(struct sockaddr)) != buflen) {
 #ifdef DEBUG
                                        if (_res.options & RES_DEBUG)
                                    sizeof(struct sockaddr)) != buflen) {
 #ifdef DEBUG
                                        if (_res.options & RES_DEBUG)
@@ -333,7 +332,7 @@ wait:
 #ifdef DEBUG
                                if (_res.options & RES_DEBUG) {
                                        printf("old answer:\n");
 #ifdef DEBUG
                                if (_res.options & RES_DEBUG) {
                                        printf("old answer:\n");
-                                       p_query(answer);
+                                       __p_query(answer);
                                }
 #endif DEBUG
                                goto wait;
                                }
 #endif DEBUG
                                goto wait;
@@ -356,7 +355,7 @@ wait:
 #ifdef DEBUG
                if (_res.options & RES_DEBUG) {
                        printf("got answer:\n");
 #ifdef DEBUG
                if (_res.options & RES_DEBUG) {
                        printf("got answer:\n");
-                       p_query(answer);
+                       __p_query(answer);
                }
 #endif DEBUG
                /*
                }
 #endif DEBUG
                /*