0
|
1 |
/*
|
|
2 |
* Copyright (c) 2004-2005 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* which accompanies this distribution, and is available
|
|
6 |
*
|
|
7 |
* Initial Contributors:
|
|
8 |
* Nokia Corporation - initial contribution.
|
|
9 |
*
|
|
10 |
* Contributors:
|
|
11 |
*
|
|
12 |
*
|
|
13 |
*/
|
|
14 |
|
|
15 |
|
|
16 |
#define TRACE_PREFIX "WSOCK: ProtocolFamily: "
|
|
17 |
#include "wsock.h"
|
|
18 |
#include "WinsockProtocol.h"
|
|
19 |
#include "WinsockProtocolFamily.h"
|
|
20 |
#include <winsock2.h>
|
|
21 |
|
|
22 |
#define IPPROTO_ICMPV6 58
|
|
23 |
|
|
24 |
const TUint KProtocolInetRes = 0xF01;
|
|
25 |
|
|
26 |
// Initializer for TWinProtocolDesc structure
|
|
27 |
class TWinProtocolDescInit: public TWinProtocolDesc
|
|
28 |
{
|
|
29 |
public:
|
|
30 |
TWinProtocolDescInit(const TText * aName,
|
|
31 |
TUint aAddrFamily, TUint aSockType, TUint aProtocol,
|
|
32 |
TUint aServiceInfo, TInt aMessageSize, TInt aServiceTypeInfo,
|
|
33 |
TUint aWinSockType, TUint aWinProtocol)
|
|
34 |
{
|
|
35 |
iName = aName;
|
|
36 |
iAddrFamily = aAddrFamily;
|
|
37 |
iSockType = aSockType;
|
|
38 |
iProtocol = aProtocol;
|
|
39 |
iVersion = TVersion(1,0,0);
|
|
40 |
iByteOrder = EBigEndian;
|
|
41 |
iServiceInfo = aServiceInfo;
|
|
42 |
iNamingServices = KNSNameResolution;
|
|
43 |
iSecurity = KSocketNoSecurity;
|
|
44 |
iMessageSize = aMessageSize;
|
|
45 |
iServiceTypeInfo = aServiceTypeInfo;
|
|
46 |
iNumSockets = KUnlimitedSockets;
|
|
47 |
iWinSockType = aWinSockType;
|
|
48 |
iWinProtocol = aWinProtocol;
|
|
49 |
}
|
|
50 |
};
|
|
51 |
|
1
|
52 |
#if 0
|
|
53 |
|
|
54 |
TWinProtocolDescInit IP(_S("ip"),
|
|
55 |
KAfInet, KSockStream, KProtocolInetTcp, KSIStreamBased | KSIInOrder |
|
|
56 |
KSIReliable | KSIGracefulClose | KSIPeekData | KSIUrgentData,
|
|
57 |
KSocketMessageSizeIsStream, ESocketSupport,
|
|
58 |
SOCK_STREAM, IPPROTO_TCP);
|
|
59 |
|
|
60 |
#ifdef WSOCK_IPV6
|
|
61 |
|
|
62 |
TWinProtocolDescInit IP6(_S("ip6"),
|
|
63 |
KAfInet6, KSockStream, KProtocolInetTcp, KSIStreamBased | KSIInOrder |
|
|
64 |
KSIReliable | KSIGracefulClose | KSIPeekData | KSIUrgentData,
|
|
65 |
KSocketMessageSizeIsStream, ESocketSupport,
|
|
66 |
SOCK_STREAM, IPPROTO_TCP);
|
|
67 |
#endif
|
|
68 |
|
|
69 |
// NOTE: the order of protocols must match the order of entries in the
|
|
70 |
// ip.tcp.esk file (at the time of thie writing this file was located
|
|
71 |
// in c:\private\101f7989\ESock directory).
|
|
72 |
static const TWinProtocolDesc* ipProtocols[] = {
|
|
73 |
&IP,
|
|
74 |
#ifdef WSOCK_IPV6
|
|
75 |
&IP6
|
|
76 |
#endif // WSOCK_IPV6
|
|
77 |
};
|
|
78 |
#else
|
|
79 |
TWinProtocolDescInit IP(_S("ip"),
|
|
80 |
KAfInet, KSockStream, KProtocolInetTcp, KSIStreamBased | KSIInOrder |
|
|
81 |
KSIReliable | KSIGracefulClose | KSIPeekData | KSIUrgentData,
|
|
82 |
KSocketMessageSizeIsStream, ESocketSupport,
|
|
83 |
SOCK_STREAM, IPPROTO_IP);
|
|
84 |
|
0
|
85 |
TWinProtocolDescInit TCP(_S("tcp"),
|
|
86 |
KAfInet, KSockStream, KProtocolInetTcp, KSIStreamBased | KSIInOrder |
|
|
87 |
KSIReliable | KSIGracefulClose | KSIPeekData | KSIUrgentData,
|
|
88 |
KSocketMessageSizeIsStream, ESocketSupport,
|
|
89 |
SOCK_STREAM, IPPROTO_TCP);
|
|
90 |
|
|
91 |
TWinProtocolDescInit UDP(_S("udp"),
|
|
92 |
KAfInet, KSockDatagram, KProtocolInetUdp,
|
|
93 |
KSIConnectionLess | KSIDatagram | KSIGracefulClose | KSIPeekData,
|
|
94 |
65516, ESocketSupport,
|
|
95 |
SOCK_DGRAM, IPPROTO_UDP);
|
|
96 |
|
|
97 |
TWinProtocolDescInit ICMP4(_S("icmp"),
|
|
98 |
KAfInet, KSockDatagram, KProtocolInetIcmp, KSIConnectionLess |
|
|
99 |
KSIMessageBased | KSIBroadcast | KSIPeekData | KSIGracefulClose,
|
|
100 |
65000, ESocketSupport | ETransport | EPreferDescriptors | EUseCanSend,
|
|
101 |
SOCK_RAW, IPPROTO_ICMP);
|
|
102 |
|
|
103 |
TWinProtocolDescInit ICMP6(_S("icmp6"),
|
|
104 |
KAfInet, KSockDatagram, KProtocolInet6Icmp, KSIConnectionLess |
|
|
105 |
KSIMessageBased | KSIBroadcast | KSIPeekData | KSIGracefulClose,
|
|
106 |
65000, ESocketSupport | ETransport | EPreferDescriptors | EUseCanSend,
|
|
107 |
SOCK_RAW, IPPROTO_ICMPV6);
|
|
108 |
|
|
109 |
#ifdef WSOCK_IPV6
|
1
|
110 |
|
|
111 |
TWinProtocolDescInit IP6(_S("ip6"),
|
|
112 |
KAfInet6, KSockStream, KProtocolInetTcp, KSIStreamBased | KSIInOrder |
|
|
113 |
KSIReliable | KSIGracefulClose | KSIPeekData | KSIUrgentData,
|
|
114 |
KSocketMessageSizeIsStream, ESocketSupport,
|
|
115 |
SOCK_STREAM, IPPROTO_IP);
|
|
116 |
|
0
|
117 |
TWinProtocolDescInit TCP6(_S("tcp"),
|
|
118 |
KAfInet6, KSockStream, KProtocolInetTcp, KSIStreamBased | KSIInOrder |
|
|
119 |
KSIReliable | KSIGracefulClose | KSIPeekData | KSIUrgentData,
|
|
120 |
KSocketMessageSizeIsStream, ESocketSupport,
|
|
121 |
SOCK_STREAM, IPPROTO_TCP);
|
|
122 |
|
|
123 |
TWinProtocolDescInit UDP6(_S("udp"),
|
|
124 |
KAfInet6, KSockDatagram, KProtocolInetUdp,
|
|
125 |
KSIConnectionLess | KSIDatagram |KSIGracefulClose | KSIPeekData,
|
|
126 |
65516, ESocketSupport,
|
|
127 |
SOCK_DGRAM, IPPROTO_UDP);
|
|
128 |
|
|
129 |
TWinProtocolDescInit ICMP46(_S("icmp"),
|
|
130 |
KAfInet6, KSockDatagram, KProtocolInetIcmp, KSIConnectionLess |
|
|
131 |
KSIMessageBased | KSIBroadcast | KSIPeekData | KSIGracefulClose,
|
|
132 |
65000, ESocketSupport | ETransport | EPreferDescriptors | EUseCanSend,
|
|
133 |
SOCK_RAW, IPPROTO_ICMP);
|
|
134 |
|
|
135 |
TWinProtocolDescInit ICMP66(_S("icmp6"),
|
|
136 |
KAfInet6, KSockDatagram, KProtocolInet6Icmp, KSIConnectionLess |
|
|
137 |
KSIMessageBased | KSIBroadcast | KSIPeekData | KSIGracefulClose,
|
|
138 |
65000, ESocketSupport | ETransport | EPreferDescriptors | EUseCanSend,
|
|
139 |
SOCK_RAW, IPPROTO_ICMPV6);
|
|
140 |
|
|
141 |
#endif // WSOCK_IPV6
|
|
142 |
|
1
|
143 |
|
|
144 |
|
0
|
145 |
// NOTE: the order of protocols must match the order of entries in the
|
|
146 |
// ip.tcp.esk file (at the time of thie writing this file was located
|
|
147 |
// in c:\private\101f7989\ESock directory).
|
|
148 |
static const TWinProtocolDesc* ipProtocols[] = {
|
1
|
149 |
&IP,&TCP,&UDP,&ICMP4,&ICMP6,
|
0
|
150 |
#ifdef WSOCK_IPV6
|
1
|
151 |
&IP6,&TCP6,&UDP6,&ICMP46,&ICMP66
|
0
|
152 |
#endif // WSOCK_IPV6
|
|
153 |
};
|
1
|
154 |
#endif
|
0
|
155 |
CWinsockProtocolFamily::CWinsockProtocolFamily(TUint aAddrFamily) :
|
|
156 |
iAddrFamily(aAddrFamily)
|
|
157 |
{
|
|
158 |
TRACE2("[%08X] created (0x%04x)",this,aAddrFamily);
|
|
159 |
}
|
|
160 |
|
|
161 |
CWinsockProtocolFamily::~CWinsockProtocolFamily()
|
|
162 |
{
|
|
163 |
TRACE1("[%08X] destroyed",this);
|
|
164 |
}
|
|
165 |
|
|
166 |
TInt CWinsockProtocolFamily::Install()
|
|
167 |
{
|
|
168 |
TRACE1("[%08X] Install",this);
|
|
169 |
return KErrNone;
|
|
170 |
}
|
|
171 |
|
|
172 |
// Access to the list of protocols
|
|
173 |
TInt CWinsockProtocolFamily::ProtocolCount()
|
|
174 |
{
|
|
175 |
return N(ipProtocols);
|
|
176 |
}
|
|
177 |
|
|
178 |
const TServerProtocolDesc* CWinsockProtocolFamily::ProtocolDesc(TInt aIndex)
|
|
179 |
{
|
|
180 |
ASSERT(aIndex >= 0 && aIndex < N(ipProtocols));
|
|
181 |
if (aIndex >= 0 && aIndex < N(ipProtocols))
|
|
182 |
{
|
|
183 |
return ipProtocols[aIndex];
|
|
184 |
}
|
|
185 |
else
|
|
186 |
{
|
|
187 |
return NULL;
|
|
188 |
}
|
|
189 |
}
|
|
190 |
|
|
191 |
// Returns comma separated list of protocol names
|
1
|
192 |
void CWinsockProtocolFamily::ProtocolNamesfownetwork(TDes& aProtocols)
|
|
193 |
{
|
|
194 |
aProtocols.SetLength(0);
|
|
195 |
/* for (TInt i=0; i<N(ipProtocols); i++)
|
|
196 |
{
|
|
197 |
TBool alreadyThere = EFalse;
|
|
198 |
for (TInt k=0; k<i; k++)
|
|
199 |
{
|
|
200 |
if (!ipProtocols[i]->iName.Compare(ipProtocols[k]->iName))
|
|
201 |
{
|
|
202 |
alreadyThere = ETrue;
|
|
203 |
break;
|
|
204 |
}
|
|
205 |
}
|
|
206 |
if (!alreadyThere)
|
|
207 |
{
|
|
208 |
if (i > 0) aProtocols.Append(',');
|
|
209 |
aProtocols.Append(ipProtocols[i]->iName);
|
|
210 |
}
|
|
211 |
}*/
|
|
212 |
aProtocols.Append(ipProtocols[0]->iName);
|
|
213 |
aProtocols.Append(',');
|
|
214 |
aProtocols.Append(ipProtocols[5]->iName);
|
|
215 |
|
|
216 |
TRACE1("ProtocolNames: %S",&aProtocols);
|
|
217 |
}
|
|
218 |
|
|
219 |
// Returns comma separated list of protocol names
|
0
|
220 |
void CWinsockProtocolFamily::ProtocolNames(TDes& aProtocols)
|
|
221 |
{
|
|
222 |
aProtocols.SetLength(0);
|
|
223 |
for (TInt i=0; i<N(ipProtocols); i++)
|
|
224 |
{
|
|
225 |
TBool alreadyThere = EFalse;
|
|
226 |
for (TInt k=0; k<i; k++)
|
|
227 |
{
|
|
228 |
if (!ipProtocols[i]->iName.Compare(ipProtocols[k]->iName))
|
|
229 |
{
|
|
230 |
alreadyThere = ETrue;
|
|
231 |
break;
|
|
232 |
}
|
|
233 |
}
|
|
234 |
if (!alreadyThere)
|
|
235 |
{
|
|
236 |
if (i > 0) aProtocols.Append(',');
|
|
237 |
aProtocols.Append(ipProtocols[i]->iName);
|
|
238 |
}
|
|
239 |
}
|
|
240 |
TRACE1("ProtocolNames: %S",&aProtocols);
|
|
241 |
}
|
|
242 |
|
|
243 |
// CProtocolFamilyBase
|
|
244 |
TUint CWinsockProtocolFamily::ProtocolList(TServerProtocolDesc*& aProtocolList)
|
|
245 |
{
|
|
246 |
// we allocate slightly more, but that's OK
|
|
247 |
TInt count = 0;
|
|
248 |
aProtocolList = new(ELeave)TServerProtocolDesc[N(ipProtocols)];
|
|
249 |
if (aProtocolList)
|
|
250 |
{
|
|
251 |
for (TInt i=0; i<N(ipProtocols); i++)
|
|
252 |
{
|
|
253 |
if (ipProtocols[i]->iAddrFamily == iAddrFamily)
|
|
254 |
{
|
|
255 |
const TServerProtocolDesc* src = ipProtocols[i];
|
|
256 |
aProtocolList[count++] = *src;
|
|
257 |
}
|
|
258 |
}
|
|
259 |
|
|
260 |
if (!count)
|
|
261 |
{
|
|
262 |
delete aProtocolList;
|
|
263 |
aProtocolList = NULL;
|
|
264 |
}
|
|
265 |
}
|
|
266 |
|
|
267 |
TRACE2("[%08X] ProtocolList - %d protocols",this,count);
|
|
268 |
return count;
|
|
269 |
}
|
|
270 |
|
|
271 |
CProtocolBase* CWinsockProtocolFamily::NewProtocolL(TUint aSockType,
|
|
272 |
TUint aProtocol)
|
|
273 |
{
|
|
274 |
TRACE3("[%08X] NewProtocolL(%d,%d)",this,aSockType,aProtocol);
|
|
275 |
if (aProtocol == KUndefinedProtocol)
|
|
276 |
{
|
|
277 |
switch (aSockType)
|
|
278 |
{
|
|
279 |
case KSockDatagram:
|
|
280 |
aProtocol = KProtocolInetUdp;
|
|
281 |
break;
|
|
282 |
case KSockStream:
|
|
283 |
aProtocol = KProtocolInetTcp;
|
|
284 |
break;
|
|
285 |
default:
|
|
286 |
LEAVE(KErrNotSupported);
|
|
287 |
break;
|
|
288 |
}
|
|
289 |
}
|
|
290 |
|
|
291 |
// Finds requested protocol
|
|
292 |
for (TInt i=0; i<N(ipProtocols); i++)
|
|
293 |
{
|
|
294 |
if (ipProtocols[i]->iAddrFamily == iAddrFamily &&
|
|
295 |
ipProtocols[i]->iSockType == aSockType &&
|
|
296 |
ipProtocols[i]->iProtocol == aProtocol)
|
|
297 |
{
|
|
298 |
return new(ELeave)CWinsockProtocol(ipProtocols[i]);
|
|
299 |
}
|
|
300 |
}
|
|
301 |
|
|
302 |
LEAVE(KErrNotSupported);
|
|
303 |
return NULL;
|
|
304 |
}
|
|
305 |
|
|
306 |
/**
|
|
307 |
* Local Variables:
|
|
308 |
* c-basic-offset: 4
|
|
309 |
* indent-tabs-mode: nil
|
|
310 |
* End:
|
|
311 |
*/
|