src/share/classes/com/sun/jndi/dns/DnsClient.java

Print this page
rev 9296 : 8035105: Detect compression loops in the JNDI DNS client
   1 /*
   2  * Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 394             int pktTimeout = (timeout * (1 << retry));
 395             try {
 396                 udpSocket.send(opkt);
 397 
 398                 // timeout remaining after successive 'receive()'
 399                 int timeoutLeft = pktTimeout;
 400                 int cnt = 0;
 401                 do {
 402                     if (debug) {
 403                        cnt++;
 404                         dprint("Trying RECEIVE(" +
 405                                 cnt + ") retry(" + (retry + 1) +
 406                                 ") for:" + xid  + "    sock-timeout:" +
 407                                 timeoutLeft + " ms.");
 408                     }
 409                     udpSocket.setSoTimeout(timeoutLeft);
 410                     long start = System.currentTimeMillis();
 411                     udpSocket.receive(ipkt);
 412                     long end = System.currentTimeMillis();
 413 
 414                     byte[] data = new byte[ipkt.getLength()];
 415                     data = ipkt.getData();
 416                     if (isMatchResponse(data, xid)) {
 417                         return data;
 418                     }
 419                     timeoutLeft = pktTimeout - ((int) (end - start));
 420                 } while (timeoutLeft > minTimeout);
 421 
 422             } finally {
 423                 udpSocket.disconnect();
 424             }
 425             return null; // no matching packet received within the timeout
 426         }
 427     }
 428 
 429     /*
 430      * Sends a TCP query, and returns the first DNS message in the response.
 431      */
 432     private byte[] doTcpQuery(Tcp tcp, Packet pkt) throws IOException {
 433 
 434         int len = pkt.length();
 435         // Send 2-byte message length, then send message.


   1 /*
   2  * Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 394             int pktTimeout = (timeout * (1 << retry));
 395             try {
 396                 udpSocket.send(opkt);
 397 
 398                 // timeout remaining after successive 'receive()'
 399                 int timeoutLeft = pktTimeout;
 400                 int cnt = 0;
 401                 do {
 402                     if (debug) {
 403                        cnt++;
 404                         dprint("Trying RECEIVE(" +
 405                                 cnt + ") retry(" + (retry + 1) +
 406                                 ") for:" + xid  + "    sock-timeout:" +
 407                                 timeoutLeft + " ms.");
 408                     }
 409                     udpSocket.setSoTimeout(timeoutLeft);
 410                     long start = System.currentTimeMillis();
 411                     udpSocket.receive(ipkt);
 412                     long end = System.currentTimeMillis();
 413 
 414                     byte[] data = ipkt.getData();

 415                     if (isMatchResponse(data, xid)) {
 416                         return data;
 417                     }
 418                     timeoutLeft = pktTimeout - ((int) (end - start));
 419                 } while (timeoutLeft > minTimeout);
 420 
 421             } finally {
 422                 udpSocket.disconnect();
 423             }
 424             return null; // no matching packet received within the timeout
 425         }
 426     }
 427 
 428     /*
 429      * Sends a TCP query, and returns the first DNS message in the response.
 430      */
 431     private byte[] doTcpQuery(Tcp tcp, Packet pkt) throws IOException {
 432 
 433         int len = pkt.length();
 434         // Send 2-byte message length, then send message.