Home | History | Annotate | Download | only in DNS
      1 // Copyright (c) 1999-2004 Brian Wellington (bwelling (at) xbill.org)
      2 
      3 package org.xbill.DNS;
      4 
      5 /**
      6  * Constants and functions relating to flags in the DNS header.
      7  *
      8  * @author Brian Wellington
      9  */
     10 
     11 public final class Flags {
     12 
     13 private static Mnemonic flags = new Mnemonic("DNS Header Flag",
     14 					     Mnemonic.CASE_LOWER);
     15 
     16 /** query/response */
     17 public static final byte QR		= 0;
     18 
     19 /** authoritative answer */
     20 public static final byte AA		= 5;
     21 
     22 /** truncated */
     23 public static final byte TC		= 6;
     24 
     25 /** recursion desired */
     26 public static final byte RD		= 7;
     27 
     28 /** recursion available */
     29 public static final byte RA		= 8;
     30 
     31 /** authenticated data */
     32 public static final byte AD		= 10;
     33 
     34 /** (security) checking disabled */
     35 public static final byte CD		= 11;
     36 
     37 /** dnssec ok (extended) */
     38 public static final int DO		= ExtendedFlags.DO;
     39 
     40 static {
     41 	flags.setMaximum(0xF);
     42 	flags.setPrefix("FLAG");
     43 	flags.setNumericAllowed(true);
     44 
     45 	flags.add(QR, "qr");
     46 	flags.add(AA, "aa");
     47 	flags.add(TC, "tc");
     48 	flags.add(RD, "rd");
     49 	flags.add(RA, "ra");
     50 	flags.add(AD, "ad");
     51 	flags.add(CD, "cd");
     52 }
     53 
     54 private
     55 Flags() {}
     56 
     57 /** Converts a numeric Flag into a String */
     58 public static String
     59 string(int i) {
     60 	return flags.getText(i);
     61 }
     62 
     63 /** Converts a String representation of an Flag into its numeric value */
     64 public static int
     65 value(String s) {
     66 	return flags.getValue(s);
     67 }
     68 
     69 /**
     70  * Indicates if a bit in the flags field is a flag or not.  If it's part of
     71  * the rcode or opcode, it's not.
     72  */
     73 public static boolean
     74 isFlag(int index) {
     75 	flags.check(index);
     76 	if ((index >= 1 && index <= 4) || (index >= 12))
     77 		return false;
     78 	return true;
     79 }
     80 
     81 }
     82