1 /**
2  *
3  */
4 package javax.jmdns.impl.constants;
5 
6 /**
7  * DNS operation code.
8  *
9  * @author Arthur van Hoff, Jeff Sonstein, Werner Randelshofer, Pierre Frisch, Rick Blair
10  */
11 public enum DNSOperationCode {
12     /**
13      * Query [RFC1035]
14      */
15     Query("Query", 0),
16     /**
17      * IQuery (Inverse Query, Obsolete) [RFC3425]
18      */
19     IQuery("Inverse Query", 1),
20     /**
21      * Status [RFC1035]
22      */
23     Status("Status", 2),
24     /**
25      * Unassigned
26      */
27     Unassigned("Unassigned", 3),
28     /**
29      * Notify [RFC1996]
30      */
31     Notify("Notify", 4),
32     /**
33      * Update [RFC2136]
34      */
35     Update("Update", 5);
36 
37     /**
38      * DNS RCode types are encoded on the last 4 bits
39      */
40     static final int     OpCode_MASK = 0x7800;
41 
42     private final String _externalName;
43 
44     private final int    _index;
45 
DNSOperationCode(String name, int index)46     DNSOperationCode(String name, int index) {
47         _externalName = name;
48         _index = index;
49     }
50 
51     /**
52      * Return the string representation of this type
53      *
54      * @return String
55      */
externalName()56     public String externalName() {
57         return _externalName;
58     }
59 
60     /**
61      * Return the numeric value of this type
62      *
63      * @return String
64      */
indexValue()65     public int indexValue() {
66         return _index;
67     }
68 
69     /**
70      * @param flags
71      * @return label
72      */
operationCodeForFlags(int flags)73     public static DNSOperationCode operationCodeForFlags(int flags) {
74         int maskedIndex = (flags & OpCode_MASK) >> 11;
75         for (DNSOperationCode aCode : DNSOperationCode.values()) {
76             if (aCode._index == maskedIndex) return aCode;
77         }
78         return Unassigned;
79     }
80 
81     @Override
toString()82     public String toString() {
83         return this.name() + " index " + this.indexValue();
84     }
85 
86 }
87