summaryrefslogtreecommitdiff
path: root/src/javax/jmdns/impl/constants/DNSOperationCode.java
blob: 86af38fa77b0dee73abab0b4d84b29bf9c675b0e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/**
 *
 */
package javax.jmdns.impl.constants;

/**
 * DNS operation code.
 * 
 * @author Arthur van Hoff, Jeff Sonstein, Werner Randelshofer, Pierre Frisch, Rick Blair
 */
public enum DNSOperationCode {
    /**
     * Query [RFC1035]
     */
    Query("Query", 0),
    /**
     * IQuery (Inverse Query, Obsolete) [RFC3425]
     */
    IQuery("Inverse Query", 1),
    /**
     * Status [RFC1035]
     */
    Status("Status", 2),
    /**
     * Unassigned
     */
    Unassigned("Unassigned", 3),
    /**
     * Notify [RFC1996]
     */
    Notify("Notify", 4),
    /**
     * Update [RFC2136]
     */
    Update("Update", 5);

    /**
     * DNS RCode types are encoded on the last 4 bits
     */
    static final int     OpCode_MASK = 0x7800;

    private final String _externalName;

    private final int    _index;

    DNSOperationCode(String name, int index) {
        _externalName = name;
        _index = index;
    }

    /**
     * Return the string representation of this type
     * 
     * @return String
     */
    public String externalName() {
        return _externalName;
    }

    /**
     * Return the numeric value of this type
     * 
     * @return String
     */
    public int indexValue() {
        return _index;
    }

    /**
     * @param flags
     * @return label
     */
    public static DNSOperationCode operationCodeForFlags(int flags) {
        int maskedIndex = (flags & OpCode_MASK) >> 11;
        for (DNSOperationCode aCode : DNSOperationCode.values()) {
            if (aCode._index == maskedIndex) return aCode;
        }
        return Unassigned;
    }

    @Override
    public String toString() {
        return this.name() + " index " + this.indexValue();
    }

}