1// Copyright (c) 1999-2004 Brian Wellington (bwelling@xbill.org) 2 3package org.xbill.DNS; 4 5/** 6 * Constants and functions relating to flags in the DNS header. 7 * 8 * @author Brian Wellington 9 */ 10 11public final class Flags { 12 13private static Mnemonic flags = new Mnemonic("DNS Header Flag", 14 Mnemonic.CASE_LOWER); 15 16/** query/response */ 17public static final byte QR = 0; 18 19/** authoritative answer */ 20public static final byte AA = 5; 21 22/** truncated */ 23public static final byte TC = 6; 24 25/** recursion desired */ 26public static final byte RD = 7; 27 28/** recursion available */ 29public static final byte RA = 8; 30 31/** authenticated data */ 32public static final byte AD = 10; 33 34/** (security) checking disabled */ 35public static final byte CD = 11; 36 37/** dnssec ok (extended) */ 38public static final int DO = ExtendedFlags.DO; 39 40static { 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 54private 55Flags() {} 56 57/** Converts a numeric Flag into a String */ 58public static String 59string(int i) { 60 return flags.getText(i); 61} 62 63/** Converts a String representation of an Flag into its numeric value */ 64public static int 65value(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 */ 73public static boolean 74isFlag(int index) { 75 flags.check(index); 76 if ((index >= 1 && index <= 4) || (index >= 12)) 77 return false; 78 return true; 79} 80 81} 82