• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package android.net.util;
18 
19 /**
20  * Networking protocol constants.
21  *
22  * Includes:
23  *     - constants that describe packet layout
24  *     - various helper functions
25  *
26  * @hide
27  */
28 public final class NetworkConstants {
NetworkConstants()29     private NetworkConstants() { throw new RuntimeException("no instance permitted"); }
30 
31     public static final byte FF = asByte(0xff);
32     public static final byte[] ETHER_ADDR_BROADCAST = {
33         FF, FF, FF, FF, FF, FF
34     };
35 
36     public static final int ETHER_MTU = 1500;
37 
38     /**
39      * IPv4 constants.
40      *
41      * See also:
42      *     - https://tools.ietf.org/html/rfc791
43      */
44     public static final int IPV4_ADDR_BITS = 32;
45 
46     /**
47      * IPv6 constants.
48      *
49      * See also:
50      *     - https://tools.ietf.org/html/rfc2460
51      */
52     public static final int IPV6_ADDR_BITS = 128;
53     public static final int IPV6_ADDR_LEN = 16;
54     public static final int IPV6_MIN_MTU = 1280;
55     public static final int RFC7421_PREFIX_LENGTH = 64;
56 
57     /**
58      * ICMP common (v4/v6) constants.
59      *
60      * See also:
61      *     - https://tools.ietf.org/html/rfc792
62      *     - https://tools.ietf.org/html/rfc4443
63      */
64     public static final int ICMP_HEADER_TYPE_OFFSET = 0;
65     public static final int ICMP_HEADER_CODE_OFFSET = 1;
66     public static final int ICMP_HEADER_CHECKSUM_OFFSET = 2;
67     public static final int ICMP_ECHO_IDENTIFIER_OFFSET = 4;
68     public static final int ICMP_ECHO_SEQUENCE_NUMBER_OFFSET = 6;
69     public static final int ICMP_ECHO_DATA_OFFSET = 8;
70 
71     /**
72      * ICMPv4 constants.
73      *
74      * See also:
75      *     - https://tools.ietf.org/html/rfc792
76      */
77     public static final int ICMPV4_ECHO_REQUEST_TYPE = 8;
78     public static final int ICMPV6_ECHO_REQUEST_TYPE = 128;
79 
80     /**
81      * DNS constants.
82      *
83      * See also:
84      *     - https://tools.ietf.org/html/rfc1035
85      */
86     public static final int DNS_SERVER_PORT = 53;
87 
88     /**
89      * Utility functions.
90      */
asByte(int i)91     public static byte asByte(int i) { return (byte) i; }
92 }
93