Print this page
1926 libresolv evades compiler warnings

Split Close
Expand all
Collapse all
          --- old/usr/src/lib/libresolv/res_mkquery.c
          +++ new/usr/src/lib/libresolv/res_mkquery.c
↓ open down ↓ 12 lines elided ↑ open up ↑
  13   13   * When distributing Covered Code, include this CDDL HEADER in each
  14   14   * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15   15   * If applicable, add the following below this CDDL HEADER, with the
  16   16   * fields enclosed by brackets "[]" replaced with your own identifying
  17   17   * information: Portions Copyright [yyyy] [name of copyright owner]
  18   18   *
  19   19   * CDDL HEADER END
  20   20   */
  21   21  
  22   22  /*
       23 + * Copyright 2015 Gary Mills
  23   24   * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  24   25   * Use is subject to license terms.
  25   26   */
  26   27  
  27   28  /*      Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
  28   29  /*        All Rights Reserved   */
  29   30  
  30   31  /*
  31   32   * University Copyright- Copyright (c) 1982, 1986, 1988
  32   33   * The Regents of the University of California
  33   34   * All Rights Reserved
  34   35   *
  35   36   * University Acknowledgment- Portions of this document are derived from
  36   37   * software developed by the University of California, Berkeley, and its
  37   38   * contributors.
  38   39   */
  39   40  
  40      -#pragma ident   "%Z%%M% %I%     %E% SMI"
  41      -
  42   41  #include <stdio.h>
  43   42  #include <sys/types.h>
  44   43  #include <sys/socket.h>
  45   44  #include <sys/stat.h>
  46   45  #include <netinet/in.h>
  47   46  #include <arpa/nameser.h>
  48   47  #include <resolv.h>
       48 +#include <string.h>
       49 +#include <stdlib.h>
       50 +#include <unistd.h>
  49   51  #include <errno.h>
  50   52  #include <netdb.h>
       53 +#include "crossl.h"
  51   54  
  52   55  /*
  53   56   * Kludge to time out quickly if there is no /etc/resolv.conf
  54   57   * and a TCP connection to the local DNS server fails.
  55   58   *
  56   59   * Moved function from res_send.c to res_mkquery.c.  This
  57   60   * solves a long timeout problem with nslookup.
  58   61   *
  59   62   * __areweinnamed is needed because there is a possibility that the
  60   63   * user might do bad things to resolv.conf and cause in.named to call
↓ open down ↓ 29 lines elided ↑ open up ↑
  90   93  
  91   94                          /* Lastly, we try to connect to the TCP port of the
  92   95                           * nameserver.  If this fails, then we know that
  93   96                           * DNS is misconfigured and we can quickly exit.
  94   97                           */
  95   98                          ns = socket(AF_INET, SOCK_STREAM, 0);
  96   99                          IN_SET_LOOPBACK_ADDR(&ns_sin);
  97  100                          ns_sin.sin_port = htons(NAMESERVER_PORT);
  98  101                          if (connect(ns, (struct sockaddr *) &ns_sin,
  99  102                                      sizeof ns_sin) == -1) {
 100      -                                close(ns);
      103 +                                (void) close(ns);
 101  104                                  return(-1);
 102  105                          }
 103  106                          else {
 104      -                                close(ns);
      107 +                                (void) close(ns);
 105  108                                  return(0);
 106  109                          }
 107  110                  }
 108  111          
 109  112                  return(0);
 110  113          }
 111  114          
 112  115          return (0);
 113  116  }
 114  117  
↓ open down ↓ 6 lines elided ↑ open up ↑
 121  124          int op;                 /* opcode of query */
 122  125          char *dname;            /* domain name */
 123  126          int class, type;        /* class and type of query */
 124  127          char *data;             /* resource record data */
 125  128          int datalen;            /* length of data */
 126  129          struct rrec *newrr;     /* new rr for modify or append */
 127  130          char *buf;              /* buffer to put query */
 128  131          int buflen;             /* size of buffer */
 129  132  {
 130  133          register HEADER *hp;
 131      -        register char *cp;
      134 +        register u_char *cp;
 132  135          register int n;
 133      -        char *dnptrs[10], **dpp, **lastdnptr;
      136 +        u_char *dnptrs[10], **dpp, **lastdnptr;
 134  137  
 135  138  #ifdef DEBUG
 136  139          if (_res.options & RES_DEBUG)
 137  140                  printf("res_mkquery(%d, %s, %d, %d)\n", op, dname, class, type);
 138  141  #endif /* DEBUG */
 139  142          
 140  143          /*
 141  144           * Check to see if we can bailout quickly.
 142  145           * Also rerun res_init if we failed in the past.
 143  146           */
↓ open down ↓ 8 lines elided ↑ open up ↑
 152  155                  h_errno = NO_RECOVERY;
 153  156                  return(-1);
 154  157          }
 155  158  
 156  159          /*
 157  160           * Initialize header fields.
 158  161           */
 159  162          if ((buf == NULL) || (buflen < sizeof (HEADER)))
 160  163                  return (-1);
 161  164  #ifdef SYSV
 162      -        memset(buf, 0, sizeof (HEADER));
      165 +        (void) memset(buf, 0, sizeof (HEADER));
 163  166  #else
 164  167          bzero(buf, sizeof (HEADER));
 165  168  #endif
 166  169          hp = (HEADER *) buf;
 167  170          hp->id = htons(++_res.id);
 168  171          hp->opcode = op;
 169  172          hp->pr = (_res.options & RES_PRIMARY) != 0;
 170  173          hp->rd = (_res.options & RES_RECURSE) != 0;
 171  174          hp->rcode = NOERROR;
 172      -        cp = buf + sizeof (HEADER);
      175 +        cp = (u_char *)(buf + sizeof (HEADER));
 173  176          buflen -= sizeof (HEADER);
 174  177          dpp = dnptrs;
 175      -        *dpp++ = buf;
      178 +        *dpp++ = (u_char *)buf;
 176  179          *dpp++ = NULL;
 177  180          lastdnptr = dnptrs + sizeof (dnptrs) / sizeof (dnptrs[0]);
 178  181          /*
 179  182           * perform opcode specific processing
 180  183           */
 181  184          switch (op) {
 182  185          case QUERY:
 183  186                  if ((buflen -= QFIXEDSZ) < 0)
 184  187                          return (-1);
 185      -                if ((n = dn_comp(dname, cp, buflen, dnptrs, lastdnptr)) < 0)
      188 +                if ((n = dn_comp((u_char *)dname, cp, buflen,
      189 +                    dnptrs, lastdnptr)) < 0)
 186  190                          return (-1);
 187  191                  cp += n;
 188  192                  buflen -= n;
 189  193                  putshort(type, cp);
 190  194                  cp += sizeof (u_short);
 191  195                  putshort(class, cp);
 192  196                  cp += sizeof (u_short);
 193  197                  hp->qdcount = htons(1);
 194  198                  if (op == QUERY || data == NULL)
 195  199                          break;
 196  200                  /*
 197  201                   * Make an additional record for completion domain.
 198  202                   */
 199  203                  buflen -= RRFIXEDSZ;
 200      -                if ((n = dn_comp(data, cp, buflen, dnptrs, lastdnptr)) < 0)
      204 +                if ((n = dn_comp((u_char *)data, cp, buflen,
      205 +                    dnptrs, lastdnptr)) < 0)
 201  206                          return (-1);
 202  207                  cp += n;
 203  208                  buflen -= n;
 204  209                  putshort(T_NULL, cp);
 205  210                  cp += sizeof (u_short);
 206  211                  putshort(class, cp);
 207  212                  cp += sizeof (u_short);
 208  213                  putlong(0, cp);
 209  214                  cp += sizeof (u_long);
 210  215                  putshort(0, cp);
↓ open down ↓ 11 lines elided ↑ open up ↑
 222  227                  putshort(type, cp);
 223  228                  cp += sizeof (u_short);
 224  229                  putshort(class, cp);
 225  230                  cp += sizeof (u_short);
 226  231                  putlong(0, cp);
 227  232                  cp += sizeof (u_long);
 228  233                  putshort(datalen, cp);
 229  234                  cp += sizeof (u_short);
 230  235                  if (datalen) {
 231  236  #ifdef SYSV
 232      -                        memcpy((void *)cp, (void *)data, datalen);
      237 +                        (void) memcpy((void *)cp, (void *)data, datalen);
 233  238  #else
 234  239                          bcopy(data, cp, datalen);
 235  240  #endif
 236  241                          cp += datalen;
 237  242                  }
 238  243                  hp->ancount = htons(1);
 239  244                  break;
 240  245  
 241  246  #ifdef ALLOW_UPDATES
 242  247          /*
↓ open down ↓ 4 lines elided ↑ open up ↑
 247  252          case UPDATEMA:
 248  253  
 249  254          case UPDATED:
 250  255                  /*
 251  256                   * The res code for UPDATED and UPDATEDA is the same; user
 252  257                   * calls them differently: specifies data for UPDATED; server
 253  258                   * ignores data if specified for UPDATEDA.
 254  259                   */
 255  260          case UPDATEDA:
 256  261                  buflen -= RRFIXEDSZ + datalen;
 257      -                if ((n = dn_comp(dname, cp, buflen, dnptrs, lastdnptr)) < 0)
      262 +                if ((n = dn_comp((u_char *)dname, cp, buflen,
      263 +                    dnptrs, lastdnptr)) < 0)
 258  264                          return (-1);
 259  265                  cp += n;
 260  266                  putshort(type, cp);
 261  267                  cp += sizeof (u_short);
 262  268                  putshort(class, cp);
 263  269                  cp += sizeof (u_short);
 264  270                  putlong(0, cp);
 265  271                  cp += sizeof (u_long);
 266  272                  putshort(datalen, cp);
 267  273                  cp += sizeof (u_short);
↓ open down ↓ 6 lines elided ↑ open up ↑
 274  280                          cp += datalen;
 275  281                  }
 276  282                  if ((op == UPDATED) || (op == UPDATEDA)) {
 277  283                          hp->ancount = htons(0);
 278  284                          break;
 279  285                  }
 280  286                  /* Else UPDATEM/UPDATEMA, so drop into code for UPDATEA */
 281  287  
 282  288          case UPDATEA:   /* Add new resource record */
 283  289                  buflen -= RRFIXEDSZ + datalen;
 284      -                if ((n = dn_comp(dname, cp, buflen, dnptrs, lastdnptr)) < 0)
      290 +                if ((n = dn_comp((u_char *)dname, cp, buflen,
      291 +                    dnptrs, lastdnptr)) < 0)
 285  292                          return (-1);
 286  293                  cp += n;
 287  294                  putshort(newrr->r_type, cp);
 288  295                  cp += sizeof (u_short);
 289  296                  putshort(newrr->r_class, cp);
 290  297                  cp += sizeof (u_short);
 291  298                  putlong(0, cp);
 292  299                  cp += sizeof (u_long);
 293  300                  putshort(newrr->r_size, cp);
 294  301                  cp += sizeof (u_short);
↓ open down ↓ 3 lines elided ↑ open up ↑
 298  305  #else
 299  306                          bcopy(newrr->r_data, cp, newrr->r_size);
 300  307  #endif
 301  308                          cp += newrr->r_size;
 302  309                  }
 303  310                  hp->ancount = htons(0);
 304  311                  break;
 305  312  
 306  313  #endif /* ALLOW_UPDATES */
 307  314          }
 308      -        return (cp - buf);
      315 +        return ((char *)cp - buf);
 309  316  }
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX