1<?php 2 3namespace IPLib\Range; 4 5/** 6 * Types of IP address classes. 7 */ 8class Type 9{ 10 /** 11 * Unspecified/unknown address. 12 * 13 * @var int 14 */ 15 const T_UNSPECIFIED = 1; 16 17 /** 18 * Reserved/internal use only. 19 * 20 * @var int 21 */ 22 const T_RESERVED = 2; 23 24 /** 25 * Refer to source hosts on "this" network. 26 * 27 * @var int 28 */ 29 const T_THISNETWORK = 3; 30 31 /** 32 * Internet host loopback address. 33 * 34 * @var int 35 */ 36 const T_LOOPBACK = 4; 37 38 /** 39 * Relay anycast address. 40 * 41 * @var int 42 */ 43 const T_ANYCASTRELAY = 5; 44 45 /** 46 * "Limited broadcast" destination address. 47 * 48 * @var int 49 */ 50 const T_LIMITEDBROADCAST = 6; 51 52 /** 53 * Multicast address assignments - Indentify a group of interfaces. 54 * 55 * @var int 56 */ 57 const T_MULTICAST = 7; 58 59 /** 60 * "Link local" address, allocated for communication between hosts on a single link. 61 * 62 * @var int 63 */ 64 const T_LINKLOCAL = 8; 65 66 /** 67 * Link local unicast / Linked-scoped unicast. 68 * 69 * @var int 70 */ 71 const T_LINKLOCAL_UNICAST = 9; 72 73 /** 74 * Discard-Only address. 75 * 76 * @var int 77 */ 78 const T_DISCARDONLY = 10; 79 80 /** 81 * Discard address. 82 * 83 * @var int 84 */ 85 const T_DISCARD = 11; 86 87 /** 88 * For use in private networks. 89 * 90 * @var int 91 */ 92 const T_PRIVATENETWORK = 12; 93 94 /** 95 * Public address. 96 * 97 * @var int 98 */ 99 const T_PUBLIC = 13; 100 101 /** 102 * Carrier-grade NAT address. 103 * 104 * @var int 105 * 106 * @since 1.10.0 107 */ 108 const T_CGNAT = 14; 109 110 /** 111 * Get the name of a type. 112 * 113 * @param int $type 114 * 115 * @return string 116 */ 117 public static function getName($type) 118 { 119 switch ($type) { 120 case static::T_UNSPECIFIED: 121 return 'Unspecified/unknown address'; 122 case static::T_RESERVED: 123 return 'Reserved/internal use only'; 124 case static::T_THISNETWORK: 125 return 'Refer to source hosts on "this" network'; 126 case static::T_LOOPBACK: 127 return 'Internet host loopback address'; 128 case static::T_ANYCASTRELAY: 129 return 'Relay anycast address'; 130 case static::T_LIMITEDBROADCAST: 131 return '"Limited broadcast" destination address'; 132 case static::T_MULTICAST: 133 return 'Multicast address assignments - Indentify a group of interfaces'; 134 case static::T_LINKLOCAL: 135 return '"Link local" address, allocated for communication between hosts on a single link'; 136 case static::T_LINKLOCAL_UNICAST: 137 return 'Link local unicast / Linked-scoped unicast'; 138 case static::T_DISCARDONLY: 139 return 'Discard only'; 140 case static::T_DISCARD: 141 return 'Discard'; 142 case static::T_PRIVATENETWORK: 143 return 'For use in private networks'; 144 case static::T_PUBLIC: 145 return 'Public address'; 146 case static::T_CGNAT: 147 return 'Carrier-grade NAT'; 148 default: 149 return $type === null ? 'Unknown type' : sprintf('Unknown type (%s)', $type); 150 } 151 } 152} 153