|
1 // Copyright (c) 2005-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 // ipaddress.h - Unify IPv4/IPv6 Raw Address handling |
|
15 // |
|
16 |
|
17 |
|
18 |
|
19 /** |
|
20 @internalComponent |
|
21 */ |
|
22 #ifndef __IPADDRESS_H__ |
|
23 #define __IPADDRESS_H__ |
|
24 |
|
25 #include <in_sock.h> |
|
26 |
|
27 class TIpAddress : public TIp6Addr |
|
28 /** |
|
29 * Container for a raw IPv6 address with the scope id. |
|
30 */ |
|
31 { |
|
32 public: |
|
33 TIpAddress() {} |
|
34 TIpAddress(const TIp6Addr &aAddr, const TUint32 aScope) : iScope(aScope) {(TIp6Addr &)*this = aAddr; } |
|
35 inline TIpAddress(const TSockAddr &aAddr); |
|
36 inline const TIp6Addr &Address() const { return *this; } |
|
37 |
|
38 TInt operator==(const TIpAddress &aAddr) const; |
|
39 TBool operator<=(const TIpAddress &aAddr) const; |
|
40 TInt operator!=(const TIpAddress &aAddr) const; |
|
41 |
|
42 TBool IsEqMask(const TIpAddress &aAddr, const TIpAddress &aMask) const; |
|
43 TBool IsMulticast() const; |
|
44 TInt SetAddress(const TDesC &aAddr, TInt aMask = 0); |
|
45 TInt SetAddress(const TSockAddr &aAddr); |
|
46 TInt SetMask(const TSockAddr &aAddr); |
|
47 void SetAddress(const TIp6Addr &aAddr, const TUint32 aScope); |
|
48 void SetAddress(const TUint32 aAddr); |
|
49 void SetAddressNone(); // Set all ZERO address. |
|
50 inline TBool IsNone() const; // Test for all zero address |
|
51 // A dubious method. But, this returns the IPv4 address. |
|
52 // It will return the value of the last 4 bytes swapped into host order. |
|
53 // (basicly a reverse of SetAddress(TUint32), but without any checks) |
|
54 inline TUint32 Ip4Address() const; |
|
55 |
|
56 TUint32 iScope; |
|
57 }; |
|
58 |
|
59 |
|
60 // |
|
61 // ...by EPOC convention, the following should be in "ipaddress.inl" I suppose... |
|
62 // |
|
63 inline TIpAddress::TIpAddress(const TSockAddr &aAddr) |
|
64 /** |
|
65 * Constructor. |
|
66 * |
|
67 * Set initial content from the TSockAddr. |
|
68 * |
|
69 * @param aAddr The initial address. |
|
70 */ |
|
71 { |
|
72 SetAddress(aAddr); |
|
73 } |
|
74 |
|
75 inline TBool TIpAddress::IsNone() const |
|
76 /** |
|
77 * Test if address is unspecified. |
|
78 * |
|
79 * Note: This does not care about the scope id. |
|
80 */ |
|
81 { |
|
82 return IsUnspecified(); |
|
83 } |
|
84 |
|
85 inline TUint32 TIpAddress::Ip4Address() const |
|
86 /** |
|
87 * Return as IPv4 address. |
|
88 * |
|
89 * Assume the content is currently an IPv4 address in |
|
90 * IPv4 mapped format, and return that IPv4 address as |
|
91 * TUint32. |
|
92 * |
|
93 * @return The IPv4 address. |
|
94 */ |
|
95 { |
|
96 return |
|
97 (u.iAddr8[12] << 24) | |
|
98 (u.iAddr8[13] << 16) | |
|
99 (u.iAddr8[14] << 8) | |
|
100 (u.iAddr8[15]); |
|
101 } |
|
102 |
|
103 #endif |