|
1 /* |
|
2 * Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Address resolver utility class |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef C_IPAPPUTILSADDRESSRESOLVER_H |
|
20 #define C_IPAPPUTILSADDRESSRESOLVER_H |
|
21 |
|
22 #include <e32base.h> |
|
23 #include <es_sock.h> |
|
24 #include <in_sock.h> |
|
25 |
|
26 /** |
|
27 * Utility class for querying local ip address and wlan mac address |
|
28 * |
|
29 * @code |
|
30 * TInetAddr localAddr; |
|
31 * TUint32 iapId = 1; |
|
32 * iAddressResolver = CIPAppUtilsAddressResolver::NewL(); |
|
33 * iAddressResolver->GetLocalAddressFromIapL( |
|
34 * localAddr, iapId ); |
|
35 * delete iAddressResolver; |
|
36 * @endcode |
|
37 * |
|
38 * @lib ipapputils.lib |
|
39 * @since S60 v3.2 |
|
40 */ |
|
41 NONSHARABLE_CLASS( CIPAppUtilsAddressResolver ) : public CBase |
|
42 { |
|
43 public: // Constructors and destructor |
|
44 |
|
45 /** |
|
46 * Two-phased constructor. |
|
47 */ |
|
48 IMPORT_C static CIPAppUtilsAddressResolver* NewL(); |
|
49 /** |
|
50 * Two-phased constructor. |
|
51 */ |
|
52 IMPORT_C static CIPAppUtilsAddressResolver* NewLC(); |
|
53 |
|
54 /** |
|
55 * Destructor. |
|
56 */ |
|
57 virtual ~CIPAppUtilsAddressResolver(); |
|
58 |
|
59 |
|
60 public: // New functions |
|
61 |
|
62 /** |
|
63 * Get Wlan MAC address from the device. If WLAN interface couldn't found, |
|
64 * return error code. |
|
65 * |
|
66 * @param aWlanMacAddress on return, this descriptor will contain the |
|
67 * WLAN mac address. Client must see that the descriptor is long enough |
|
68 * to hold the address in given format. |
|
69 * @param aByteFormat defines the format for WLAN MAC bytes, e.g. "%02X:" |
|
70 * if aByteFormat == KNullDesC(), function will return raw hwaddress data |
|
71 * (six bytes long descriptor, no formatting whatsoever) |
|
72 * @return error code. KErrNone if successful, KErrNotFound if WLAN IF is |
|
73 * not found from the system or other system error code |
|
74 * @since S60 5.0 |
|
75 */ |
|
76 IMPORT_C TInt GetWlanMACAddress ( |
|
77 TDes8& aWlanMacAddress, const TDesC8& aByteFormat ); |
|
78 |
|
79 /** |
|
80 * Retrieve local ip address |
|
81 * |
|
82 * @param aLocalIpAddr on return, this parameter will contain the local ip address. |
|
83 * @param aIapId specifies the IAP from which the ip address is queried from |
|
84 * @return error code. KErrNone if successful, KErrNotFound if cannot fetch the |
|
85 * addr from given iap, or other system error code |
|
86 * @since S60 5.0 |
|
87 */ |
|
88 IMPORT_C TInt GetLocalIpAddressFromIap( |
|
89 TInetAddr& aLocalIpAddr, TUint32 aIapId ); |
|
90 |
|
91 /** |
|
92 * Returns WLAN SSID based on given IAP id. |
|
93 * |
|
94 * @since S60 v5.0 |
|
95 * @param aIapId for IAP id |
|
96 * @param aWlanSsid for WLAN SSID |
|
97 */ |
|
98 IMPORT_C void WlanSsidL( TUint32 aIapId, TDes& aWlanSsid ); |
|
99 |
|
100 |
|
101 private: |
|
102 |
|
103 /** |
|
104 * C++ default constructor. |
|
105 */ |
|
106 CIPAppUtilsAddressResolver(); |
|
107 |
|
108 /** |
|
109 * By default Symbian 2nd phase constructor is private. |
|
110 */ |
|
111 void ConstructL(); |
|
112 |
|
113 /** |
|
114 * Helper function used from GetLocalIPAddressFromIap. |
|
115 * Checks the validity of the fetched local ip addr and sets it to target |
|
116 * @param aTarget will contain the local ip addr on return |
|
117 * @param aCandidate proposed ip address |
|
118 * @param aCandidateIap IAP of the proposed IP address |
|
119 * @param aSpecifiedIap reference IAP ID. Must match with aCandidateIap. |
|
120 * @return Status Code. KErrNotFound if cannot set the target. |
|
121 */ |
|
122 TInt CheckAndSetAddr( TInetAddr& aTarget, TInetAddr& aCandidate, |
|
123 TUint32 aCandidateIap, TUint32 aSpecifiedIap ) const; |
|
124 |
|
125 |
|
126 private: // data |
|
127 /** |
|
128 * Handle to Socket's server. |
|
129 * Own. |
|
130 */ |
|
131 RSocketServ iSocketServer; |
|
132 |
|
133 /** |
|
134 * Handle to Socket. |
|
135 * Own. |
|
136 */ |
|
137 RSocket iSocket; |
|
138 |
|
139 |
|
140 #ifdef _DEBUG |
|
141 friend class T_CIPAppUtilsAddressResolver; |
|
142 #endif |
|
143 }; |
|
144 |
|
145 #endif // C_IPAPPUTILSADDRESSRESOLVER_H |