|
1 // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // addr46.cpp - an extention to TIp6Addr |
|
15 // |
|
16 |
|
17 #include "addr46.h" |
|
18 |
|
19 static const union {TUint8 a[4]; TUint32 b;} v4Prefix = { {0, 0, 0xff, 0xff} }; |
|
20 |
|
21 // |
|
22 // TIp46Addr::TIp46Addr |
|
23 // ******************** |
|
24 // Construct TIp6Addr as IPv4 mapped address from IPv4 address |
|
25 // |
|
26 TIp46Addr::TIp46Addr(const TUint32 aAddr) |
|
27 { |
|
28 u.iAddr32[0] = 0; |
|
29 u.iAddr32[1] = 0; |
|
30 u.iAddr32[2] = v4Prefix.b; |
|
31 u.iAddr8[15] = (TUint8)aAddr; |
|
32 u.iAddr8[14] = (TUint8)(aAddr >> 8); |
|
33 u.iAddr8[13] = (TUint8)(aAddr >> 16); |
|
34 u.iAddr8[12] = (TUint8)(aAddr >> 24); |
|
35 } |
|
36 // |
|
37 // Construct TIp6Adr from generic TInetAddr, |
|
38 // |
|
39 TIp46Addr::TIp46Addr(const TInetAddr &aAddr) |
|
40 { |
|
41 if (aAddr.Family() == KAfInet6) |
|
42 (*(TIp6Addr *)this) = aAddr.Ip6Address(); |
|
43 else if (aAddr.Family() == KAfInet) |
|
44 (*(TIp6Addr *)this) = TIp46Addr(aAddr.Address()); |
|
45 else |
|
46 (*(TIp6Addr *)this) = KInet6AddrNone; |
|
47 } |
|
48 |
|
49 |
|
50 // |
|
51 // TIp46Addr::IsMulticast |
|
52 // ********************** |
|
53 // Return TRUE if address is IPv4 or IPv6 multicast |
|
54 // |
|
55 TBool TIp46Addr::IsMulticast() const |
|
56 { |
|
57 // TRUE, if real IPv6 multicast |
|
58 if (TIp6Addr::IsMulticast()) |
|
59 return TRUE; |
|
60 // |
|
61 // Otherwise, return TRUE, if address is the IPv4 |
|
62 // multicast address. |
|
63 return |
|
64 u.iAddr32[0] == 0 && |
|
65 u.iAddr32[1] == 0 && |
|
66 u.iAddr32[2] == v4Prefix.b && |
|
67 (u.iAddr8[12] & 0xF0) == 0xE0; |
|
68 } |
|
69 |
|
70 // |
|
71 // TIp46Addr::IsLinklocal |
|
72 // ********************** |
|
73 // Return TRUE if address is IPv4 or IPv6 multicast |
|
74 // |
|
75 TBool TIp46Addr::IsLinkLocal() const |
|
76 { |
|
77 return Scope() == KIp6AddrScopeLinkLocal; |
|
78 } |
|
79 |
|
80 |
|
81 // TIp46Addr::IsUnspecified |
|
82 // ************************ |
|
83 TBool TIp46Addr::IsUnspecified() const |
|
84 { |
|
85 return |
|
86 u.iAddr32[0] == 0 && |
|
87 u.iAddr32[1] == 0 && |
|
88 (u.iAddr32[2] == 0 || u.iAddr32[2] == v4Prefix.b) && |
|
89 u.iAddr32[3] == 0; |
|
90 } |