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     * Get the name of a type.
103     *
104     * @param int $type
105     *
106     * @return string
107     */
108    public static function getName($type)
109    {
110        switch ($type) {
111            case static::T_UNSPECIFIED:
112                return 'Unspecified/unknown address';
113            case static::T_RESERVED:
114                 return 'Reserved/internal use only';
115            case static::T_THISNETWORK:
116                 return 'Refer to source hosts on "this" network';
117            case static::T_LOOPBACK:
118                 return 'Internet host loopback address';
119            case static::T_ANYCASTRELAY:
120                 return 'Relay anycast address';
121            case static::T_LIMITEDBROADCAST:
122                 return '"Limited broadcast" destination address';
123            case static::T_MULTICAST:
124                 return 'Multicast address assignments - Indentify a group of interfaces';
125            case static::T_LINKLOCAL:
126                 return '"Link local" address, allocated for communication between hosts on a single link';
127            case static::T_LINKLOCAL_UNICAST:
128                return 'Link local unicast / Linked-scoped unicast';
129            case static::T_DISCARDONLY:
130                 return 'Discard only';
131            case static::T_DISCARD:
132                 return 'Discard';
133            case static::T_PRIVATENETWORK:
134                 return 'For use in private networks';
135            case static::T_PUBLIC:
136                 return 'Public address';
137            default:
138                return $type === null ? 'Unknown type' : sprintf('Unknown type (%s)', $type);
139        }
140    }
141}
142