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 56 /** 57 * ICMP common (v4/v6) constants. 58 * 59 * See also: 60 * - https://tools.ietf.org/html/rfc792 61 * - https://tools.ietf.org/html/rfc4443 62 */ 63 public static final int ICMP_HEADER_TYPE_OFFSET = 0; 64 public static final int ICMP_HEADER_CODE_OFFSET = 1; 65 public static final int ICMP_HEADER_CHECKSUM_OFFSET = 2; 66 public static final int ICMP_ECHO_IDENTIFIER_OFFSET = 4; 67 public static final int ICMP_ECHO_SEQUENCE_NUMBER_OFFSET = 6; 68 public static final int ICMP_ECHO_DATA_OFFSET = 8; 69 70 /** 71 * ICMPv4 constants. 72 * 73 * See also: 74 * - https://tools.ietf.org/html/rfc792 75 */ 76 public static final int ICMPV4_ECHO_REQUEST_TYPE = 8; 77 public static final int ICMPV6_ECHO_REQUEST_TYPE = 128; 78 79 /** 80 * DNS constants. 81 * 82 * See also: 83 * - https://tools.ietf.org/html/rfc1035 84 */ 85 public static final int DNS_SERVER_PORT = 53; 86 87 /** 88 * Utility functions. 89 */ asByte(int i)90 public static byte asByte(int i) { return (byte) i; } 91 } 92