Bug 1885565 - Part 1: Add mozac_ic_avatar_circle_24 to ui-icons r=android-reviewers...
[gecko.git] / netwerk / base / IPv6Utils.h
blob437c0befec92018b04fdc171de4261800ba0b3ed
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #ifndef NETWORK_IPV6_UTILS_H_
6 #define NETWORK_IPV6_UTILS_H_
8 namespace mozilla {
9 namespace net {
10 namespace utils {
12 // IPv6 address scopes.
13 #define IPV6_SCOPE_GLOBAL 0 // Global scope.
14 #define IPV6_SCOPE_LINKLOCAL 1 // Link-local scope.
15 #define IPV6_SCOPE_SITELOCAL 2 // Site-local scope (deprecated).
16 #define IPV6_SCOPE_UNIQUELOCAL 3 // Unique local
17 #define IPV6_SCOPE_NODELOCAL 4 // Loopback
19 // Return the scope of the given address.
20 static int ipv6_scope(const unsigned char addr[16]) {
21 const unsigned char* b = addr;
22 unsigned short w = (unsigned short)((b[0] << 8) | b[1]);
24 if ((b[0] & 0xFE) == 0xFC) {
25 return IPV6_SCOPE_UNIQUELOCAL;
27 switch (w & 0xFFC0) {
28 case 0xFE80:
29 return IPV6_SCOPE_LINKLOCAL;
30 case 0xFEC0:
31 return IPV6_SCOPE_SITELOCAL;
32 case 0x0000:
33 w = b[1] | b[2] | b[3] | b[4] | b[5] | b[6] | b[7] | b[8] | b[9] | b[10] |
34 b[11] | b[12] | b[13] | b[14];
35 if (w || b[15] != 0x01) {
36 break;
38 return IPV6_SCOPE_NODELOCAL;
39 default:
40 break;
43 return IPV6_SCOPE_GLOBAL;
46 } // namespace utils
47 } // namespace net
48 } // namespace mozilla
50 #endif // NETWORK_IPV6_UTILS_H_