|
1 /* |
|
2 * Copyright (c) 2003 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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 #include "localaddrresolver.h" |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 // ----------------------------------------------------------------------------- |
|
28 // CLocalAddrResolver::NewL |
|
29 // ----------------------------------------------------------------------------- |
|
30 // |
|
31 CLocalAddrResolver* CLocalAddrResolver::NewL( RSocketServ& aServer ) |
|
32 { |
|
33 CLocalAddrResolver* self = NewLC( aServer ); |
|
34 CleanupStack::Pop(); |
|
35 return self; |
|
36 } |
|
37 |
|
38 // ----------------------------------------------------------------------------- |
|
39 // CLocalAddrResolver::NewLC |
|
40 // ----------------------------------------------------------------------------- |
|
41 // |
|
42 CLocalAddrResolver* CLocalAddrResolver::NewLC( RSocketServ& aServer ) |
|
43 { |
|
44 CLocalAddrResolver* self = new (ELeave)CLocalAddrResolver(aServer); |
|
45 CleanupStack::PushL(self); |
|
46 self->ConstructL(); |
|
47 return self; |
|
48 } |
|
49 |
|
50 // ----------------------------------------------------------------------------- |
|
51 // CLocalAddrResolver::ConstructL |
|
52 // ----------------------------------------------------------------------------- |
|
53 // |
|
54 void CLocalAddrResolver::ConstructL() |
|
55 { |
|
56 } |
|
57 |
|
58 |
|
59 // ----------------------------------------------------------------------------- |
|
60 // CLocalAddrResolver::SetAddr |
|
61 // ----------------------------------------------------------------------------- |
|
62 // |
|
63 void CLocalAddrResolver::SetAddr( TInetAddr& aTarget, TInetAddr& aSource ) |
|
64 { |
|
65 if ( aSource.Family() == KAfInet6 ) |
|
66 { |
|
67 if(!aSource.IsLinkLocal()) |
|
68 { |
|
69 aTarget = aSource; |
|
70 aTarget.SetScope(0); |
|
71 } |
|
72 } |
|
73 else |
|
74 { |
|
75 aTarget = aSource; |
|
76 aTarget.SetScope(0); |
|
77 } |
|
78 } |
|
79 |
|
80 // ----------------------------------------------------------------------------- |
|
81 // CLocalAddrResolver::CheckAndSetAddr |
|
82 // ----------------------------------------------------------------------------- |
|
83 // |
|
84 void CLocalAddrResolver::CheckAndSetAddr( TInetAddr& aTarget, |
|
85 TInetAddr& aCandidate, |
|
86 TUint32 aCandidateIap, |
|
87 TUint32 aSpecifiedIap ) |
|
88 { |
|
89 if ( !aCandidate.IsUnspecified() && !aCandidate.IsLoopback() ) |
|
90 { |
|
91 if ( aCandidate.IsV4Mapped()) |
|
92 { |
|
93 aCandidate.ConvertToV4(); |
|
94 } |
|
95 if ( aCandidateIap == aSpecifiedIap ) |
|
96 { |
|
97 SetAddr( aTarget, aCandidate ); |
|
98 } |
|
99 } |
|
100 } |
|
101 |
|
102 // ----------------------------------------------------------------------------- |
|
103 // CLocalAddrResolver::GetLocalAddrL |
|
104 // ----------------------------------------------------------------------------- |
|
105 // |
|
106 void CLocalAddrResolver::GetLocalAddrL(TInetAddr& aAddr, TUint32 aIap) |
|
107 { |
|
108 RSocket socket; |
|
109 User::LeaveIfError( socket.Open( *iServer, KAfInet, KSockDatagram, |
|
110 KProtocolInetUdp ) ); |
|
111 |
|
112 if (socket.SetOpt( KSoInetEnumInterfaces, KSolInetIfCtrl ) == KErrNone ) |
|
113 { |
|
114 TPckgBuf<TSoInetInterfaceInfo> opt; |
|
115 |
|
116 while ( socket.GetOpt( KSoInetNextInterface, KSolInetIfCtrl, opt ) == KErrNone) |
|
117 { |
|
118 TPckgBuf<TSoInetIfQuery> optifquery; |
|
119 optifquery().iName = opt().iName; |
|
120 |
|
121 if(socket.GetOpt( KSoInetIfQueryByName, KSolInetIfQuery, optifquery ) == KErrNone) |
|
122 { |
|
123 CheckAndSetAddr( aAddr, ( TInetAddr& )opt().iAddress, |
|
124 optifquery().iZone[1], aIap ); |
|
125 } |
|
126 } |
|
127 } |
|
128 |
|
129 socket.Close(); |
|
130 } |
|
131 |
|
132 |
|
133 // ----------------------------------------------------------------------------- |
|
134 // CLocalAddrResolver::~CLocalAddrResolver |
|
135 // ----------------------------------------------------------------------------- |
|
136 // |
|
137 CLocalAddrResolver::~CLocalAddrResolver() |
|
138 { |
|
139 } |
|
140 |
|
141 // ----------------------------------------------------------------------------- |
|
142 // CLocalAddrResolver::CLocalAddrResolver |
|
143 // ----------------------------------------------------------------------------- |
|
144 // |
|
145 CLocalAddrResolver::CLocalAddrResolver(RSocketServ& aServer) : |
|
146 iServer(&aServer) |
|
147 { |
|
148 } |