|
1 /* |
|
2 * Copyright (c) 1997-2002 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 #if !defined(__IN_SOCK_H__) |
|
20 #define __IN_SOCK_H__ |
|
21 |
|
22 #if !defined(__ES_SOCK_H__) |
|
23 #include <es_sock.h> |
|
24 #endif |
|
25 |
|
26 // Address family ID |
|
27 const TUint KAfInet = 0x0800; |
|
28 |
|
29 // IP Protocol IDs |
|
30 const TUint KProtocolInetIcmp = 1; |
|
31 const TUint KProtocolInetTcp = 6; |
|
32 const TUint KProtocolInetUdp = 17; |
|
33 const TUint KProtocolInetIp = 0x100; // Psuedo protocol |
|
34 |
|
35 // Socket option/ioctl levels |
|
36 const TUint KSolInetIcmp = 0x101; |
|
37 const TUint KSolInetTcp = 0x106; |
|
38 const TUint KSolInetUdp = 0x111; |
|
39 const TUint KSolInetIp = 0x100; |
|
40 const TUint KSolInetIfCtrl = 0x201; |
|
41 const TUint KSolInetRtCtrl = 0x202; |
|
42 const TUint KSolInetDnsCtrl = 0x204; |
|
43 // Security specific |
|
44 const TUint KSolInetSSL = 0x205; // SSL setopts/ioctls |
|
45 |
|
46 // Maximum IPv4 address |
|
47 const TInt KInetAddrMaxBits = 32; |
|
48 |
|
49 // Port constants |
|
50 const TUint KInetPortAny = 0x0000; |
|
51 const TUint KInetPortNone = 0x0000; |
|
52 const TUint KInetMinAutoPort = 1024; |
|
53 const TUint KInetMaxAutoPort = 5000; |
|
54 |
|
55 // Address constants and utilities |
|
56 #define INET_ADDR(a,b,c,d) (TUint32)(((a)<<24)|((b)<<16)|((c)<<8)|(d)) |
|
57 |
|
58 const TUint32 KInetAddrAny = INET_ADDR(0,0,0,0); |
|
59 const TUint32 KInetAddrNone = INET_ADDR(0,0,0,0); |
|
60 const TUint32 KInetAddrAll = INET_ADDR(255,255,255,255); |
|
61 const TUint32 KInetAddrBroadcast = INET_ADDR(255,255,255,255); |
|
62 const TUint32 KInetAddrLoop = INET_ADDR(127,0,0,1); |
|
63 |
|
64 const TUint32 KInetAddrGroupUnspec = INET_ADDR(224,0,0,0); |
|
65 const TUint32 KInetAddrGroupAllHosts = INET_ADDR(224,0,0,1); |
|
66 |
|
67 const TUint32 KInetAddrMaskAll = INET_ADDR(0,0,0,0); |
|
68 const TUint32 KInetAddrMaskHost = INET_ADDR(255,255,255,255); |
|
69 |
|
70 const TUint32 KInetAddrNetMaskA = INET_ADDR(255,0,0,0); |
|
71 const TUint32 KInetAddrHostMaskA = ~KInetAddrNetMaskA; |
|
72 const TInt KInetAddrShiftA = 24; |
|
73 const TUint32 KInetAddrNetMaskB = INET_ADDR(255,255,0,0); |
|
74 const TUint32 KInetAddrHostMaskB = ~KInetAddrNetMaskB; |
|
75 const TInt KInetAddrShiftB = 16; |
|
76 const TUint32 KInetAddrNetMaskC = INET_ADDR(255,255,255,0); |
|
77 const TUint32 KInetAddrHostMaskC = ~KInetAddrNetMaskC; |
|
78 const TInt KInetAddrShiftC = 8; |
|
79 |
|
80 const TUint32 KInetAddrIdMaskA = 0x80000000; |
|
81 const TUint32 KInetAddrIdValA = 0x00000000; |
|
82 const TUint32 KInetAddrIdMaskB = 0xc0000000; |
|
83 const TUint32 KInetAddrIdValB = 0x80000000; |
|
84 const TUint32 KInetAddrIdMaskC = 0xe0000000; |
|
85 const TUint32 KInetAddrIdValC = 0xc0000000; |
|
86 const TUint32 KInetAddrIdMaskD = 0xf0000000; |
|
87 const TUint32 KInetAddrIdValD = 0xe0000000; |
|
88 const TUint32 KInetAddrIdMaskE = 0xf8000000; |
|
89 const TUint32 KInetAddrIdValE = 0xf0000000; |
|
90 |
|
91 enum TInetAddrClass |
|
92 { |
|
93 EInetClassUnknown = 0, |
|
94 EInetClassA, |
|
95 EInetClassB, |
|
96 EInetClassC, |
|
97 EInetClassD, |
|
98 EInetClassE, |
|
99 EInetMulticast = EInetClassD, |
|
100 EInetExperimental = EInetClassE |
|
101 }; |
|
102 |
|
103 struct SInetAddr |
|
104 { TUint32 iAddr; }; |
|
105 |
|
106 class TInetAddr : public TSockAddr |
|
107 { |
|
108 public: |
|
109 IMPORT_C TInetAddr(); |
|
110 IMPORT_C TInetAddr(const TSockAddr& anAddr); |
|
111 IMPORT_C TInetAddr(TUint aPort); |
|
112 IMPORT_C TInetAddr(TUint32 anAddr, TUint aPort); |
|
113 // |
|
114 IMPORT_C void SetAddress(TUint32 anAddr); |
|
115 IMPORT_C TUint32 Address() const; |
|
116 // |
|
117 IMPORT_C TBool CmpAddr(const TInetAddr& anAddr) const; |
|
118 IMPORT_C TBool Match(const TInetAddr& aHost) const; |
|
119 IMPORT_C TBool Match(const TInetAddr& aNet, const TInetAddr& aMask) const; |
|
120 // |
|
121 IMPORT_C void Output(TDes &aBuf) const; |
|
122 IMPORT_C TInt Input(const TDesC &aBuf); // Accepts a, a.b, a.b.c, a.b.c.d or 0xaabbccdd |
|
123 // |
|
124 IMPORT_C void NetMask(const TInetAddr& aAddr); |
|
125 IMPORT_C void Net(const TInetAddr& aAddr); |
|
126 IMPORT_C void NetBroadcast(const TInetAddr& aAddr); |
|
127 IMPORT_C void SubNet(const TInetAddr& aAddr, const TInetAddr& aMask); |
|
128 IMPORT_C void SubNetBroadcast(const TInetAddr& aAddr, const TInetAddr& aMask); |
|
129 // |
|
130 inline TBool IsClassA(); |
|
131 inline TBool IsClassB(); |
|
132 inline TBool IsClassC(); |
|
133 inline TBool IsMulticast(); |
|
134 inline TBool IsBroadcast(); // == 255.255.255.255 |
|
135 inline TBool IsWildAddr(); // == 0.0.0.0 |
|
136 inline TBool IsWildPort(); // == 0 |
|
137 // |
|
138 inline static TInetAddr& Cast(const TSockAddr& anAddr); |
|
139 inline static TInetAddr& Cast(const TSockAddr* anAddr); |
|
140 protected: |
|
141 inline SInetAddr *Addr4Ptr() const; |
|
142 inline static TInt AddrLen(); |
|
143 }; |
|
144 |
|
145 // Send/Recv Flags (Datagram sockets only) |
|
146 const TUint KIpDontFragment = 0x010000; |
|
147 const TUint KIpHeaderIncluded = 0x020000; |
|
148 const TUint KIpDontRoute = 0x040000; |
|
149 |
|
150 // Structure returned by KSoInetLastError/KIoctlInetLastError |
|
151 class TSoInetLastErr |
|
152 { |
|
153 public: |
|
154 TInt iStatus; // ESock error code |
|
155 TInt iErrType; // ICMP type |
|
156 TInt iErrCode; // ICMP code |
|
157 TInetAddr iSrcAddr; // Src of failed datagram |
|
158 TInetAddr iDstAddr; // Dst of failed datagram |
|
159 TInetAddr iErrAddr; // Addr of host that generated the error |
|
160 }; |
|
161 |
|
162 // Enumerating & Configuring Interfaces TPckgBuf<TSoInetInterfaceInfo> |
|
163 // With a level of KSolInetIfCtrl |
|
164 const TInt KSoInetEnumInterfaces = 0x211; |
|
165 const TInt KSoInetNextInterface = 0x212; |
|
166 const TInt KSoInetConfigInterface = 0x213; |
|
167 |
|
168 enum TIfStatus |
|
169 { |
|
170 EIfPending, |
|
171 EIfUp, |
|
172 EIfBusy, |
|
173 EIfDown, |
|
174 }; |
|
175 |
|
176 class TSoInetInterfaceInfo |
|
177 { |
|
178 public: |
|
179 TName iTag; // Interface tag |
|
180 TName iName; // Interface name |
|
181 TIfStatus iState; // State |
|
182 TInt iMtu; // max transmition size |
|
183 TInt iSpeedMetric; // Metric - bigger is better |
|
184 TUint iFeatures; // Feature flags |
|
185 TSockAddr iHwAddr; // Hardware address (*) |
|
186 TInetAddr iAddress; // Interface IP Address (*) |
|
187 TInetAddr iNetMask; // IP netmask |
|
188 TInetAddr iBrdAddr; // IP broadcast address |
|
189 TInetAddr iDefGate; // IP default gateway or peer address (if known) |
|
190 TInetAddr iNameSer1; // IP Primary name server (if any) |
|
191 TInetAddr iNameSer2; // IP Secondary name server (if any) |
|
192 }; |
|
193 |
|
194 // Enumerating & Configuring Routes TPckgBuf<TSoInetRouteInfo> |
|
195 // With a level of KSolInetRtCtrl |
|
196 const TInt KSoInetEnumRoutes = 0x221; |
|
197 const TInt KSoInetNextRoute = 0x222; |
|
198 const TInt KSoInetAddRoute = 0x223; |
|
199 const TInt KSoInetDeleteRoute = 0x224; |
|
200 const TInt KSoInetChangeRoute = 0x225; |
|
201 |
|
202 enum TRouteState |
|
203 { |
|
204 ERtNone, |
|
205 ERtPending, // Interface has been started as a dialup, but no info available |
|
206 ERtBusy, // Interface is up but flowed off |
|
207 ERtReady, // Interface is up and ready |
|
208 ERtDown // Route is down and most likely to stay that way |
|
209 }; |
|
210 |
|
211 enum TRouteType |
|
212 { |
|
213 ERtNormal, // Created when interface was started |
|
214 ERtUser, // Created by user - ie via SetOpt() |
|
215 ERtIcmpAdd, // Added by ICMP redirect |
|
216 ERtIcmpDel // Replaced by an ICMP redirect |
|
217 }; |
|
218 |
|
219 class TSoInetRouteInfo |
|
220 { |
|
221 public: |
|
222 TRouteType iType; // Type of route (normal/icmp generated etc) |
|
223 TRouteState iState; // State of route |
|
224 TInt iMetric; // Smaller is better (less hops and/or faster link) |
|
225 TInetAddr iIfAddr; // IP address of interface used for this route |
|
226 TInetAddr iGateway; // IP address of gateway (might be the interface) |
|
227 TInetAddr iDstAddr; // Destination network or host |
|
228 TInetAddr iNetMask; // Destination mask of network (or host if KInetMaskHost) |
|
229 }; |
|
230 |
|
231 // Access to route cache TPckgBuf<TSoInetCachedRouteInfo>, set iDstAddr for required address |
|
232 // With a level of KSolInetRtCtrl |
|
233 const TInt KSoInetCachedRouteByDest = 0x225; |
|
234 |
|
235 class TSoInetCachedRouteInfo : public TSoInetRouteInfo |
|
236 { |
|
237 public: |
|
238 TInt iPathMtu; // Set if used by DF datagram (incl TCP SYN), else 0 |
|
239 TUint iPathRtt; // Set if used by TCP, else 0 |
|
240 }; |
|
241 |
|
242 // Flags returned from DNS records |
|
243 enum TNameRecordFlags |
|
244 { |
|
245 EDnsAlias=0x00000001, // Name is an Alias |
|
246 EDnsAuthoritive=0x00000002, // Answer is authoritive |
|
247 EDnsHostsFile=0x00000004, // Answer is from hosts file |
|
248 EDnsServer=0x00000008, // Answer is from a DNS server |
|
249 EDnsHostName=0x00000010, // Answer is host name for this host |
|
250 EDnsCache=0x00000020 // Answer is from the resolver cache |
|
251 }; |
|
252 const TUint KSoDnsCacheEnable = 0x600; // Get/Set |
|
253 const TUint KSoDnsCacheFlush = 0x601; //Set |
|
254 |
|
255 // TCP specific options and ioctls with a level of KSolInetTcp |
|
256 // Ioclt |
|
257 const TUint KIoctlTcpNotifyDataSent = 0x300; |
|
258 // Options |
|
259 const TUint KSoTcpSendWinSize = 0x301; // Get/Set before connect |
|
260 const TUint KSoTcpRecvWinSize = 0x302; // Get/Set before connect |
|
261 const TUint KSoTcpMaxSegSize = 0x303; // Get/Set before connect |
|
262 const TUint KSoTcpNoDelay = 0x304; // Get/Set |
|
263 const TUint KSoTcpKeepAlive = 0x305; // Get/Set |
|
264 const TUint KSoTcpAsync2MslWait = 0x306; // Get/Set |
|
265 const TUint KSoTcpSendBytesPending = 0x307; //Get |
|
266 const TUint KSoTcpReadBytesPending = 0x308; //Get |
|
267 const TUint KSoTcpListening = 0x309; //Get |
|
268 const TUint KSoTcpNumSockets = 0x310; //Get |
|
269 const TUint KSoTcpReadUrgentData = 0x311; //Get |
|
270 const TUint KSoTcpPeekUrgentData = 0x312; //Get |
|
271 const TUint KSoTcpRcvAtMark = 0x313; //Get |
|
272 const TUint KSoTcpNextSendUrgentData = 0x314; //Get/Set |
|
273 const TUint KSoTcpOobInline = 0x315; //Set |
|
274 const TUint KSOTcpDebugMode = 0x11110000; |
|
275 // SECURITY SPECIFIC STUFF |
|
276 // At level KSolInetSSL |
|
277 const TUint KSoSecureSocket = 0x400; // set/clear secure socket |
|
278 const TUint KSoSSLUnloadTimeout = 0x401; // set/get SSL dll unload timeout |
|
279 const TUint KSoCurrentCipherSuite = 0x402; // set/get current cipher suite |
|
280 const TUint KSoSSLServerCert = 0x403; // get current server cert |
|
281 const TUint KSoDialogMode = 0x404; // set/get current dialog mode |
|
282 const TUint KSoAvailableCipherSuites = 0x405; // set/get supported cipher suites |
|
283 |
|
284 // For KSoTcpSecureSocket |
|
285 const TUint KSSLClearSecureStatus = 0x00; // disconnect SSL session |
|
286 const TUint KSSLSetSecureStatus = 0x01; // complete connect on SSL connect |
|
287 |
|
288 // For KSoDialogMode |
|
289 const TUint KSSLDialogUnattendedMode = 0x00; // dialogs |
|
290 const TUint KSSLDialogAttendedMode = 0x01; // no dialogs |
|
291 |
|
292 // Generic with a level of KSolInetIp |
|
293 const TUint KSoIpOptions = 0x401; // Set/Get |
|
294 const TUint KSoRawMode = 0x402; // Set/Get |
|
295 const TUint KSoHeaderIncluded = 0x403; // Set/Get |
|
296 const TUint KSoIpTOS = 0x404; // Set/Get |
|
297 const TUint KSoIpTTL = 0x405; // Set/Get |
|
298 const TUint KSoReuseAddr = 0x406; //Set/Get |
|
299 const TUint KSoNoInterfaceError = 0x407; //Set/Get |
|
300 const TUint KSoInetLastError = 0x200; // Get Last ICMP error TPckgBuf<TSoInetLastErr> |
|
301 const TUint KIoctlInetLastError = 0x200; // Exactly the same a the GetOpt |
|
302 |
|
303 // UDP specific with a level of KSolInetUdp |
|
304 const TUint KSoUdpReceiveICMPError = 0x500; //Set/Get |
|
305 |
|
306 // Extended error codes |
|
307 const TInt KErrNetUnreach = -190; |
|
308 const TInt KErrHostUnreach = -191; |
|
309 const TInt KErrNoProtocolOpt = -192; |
|
310 const TInt KErrUrgentData = -193; |
|
311 |
|
312 inline SInetAddr* TInetAddr::Addr4Ptr() const |
|
313 { return (SInetAddr*)UserPtr(); } |
|
314 class TInetReserved0 |
|
315 { |
|
316 public: |
|
317 union |
|
318 { |
|
319 TUint8 ixxx0[16]; |
|
320 TUint16 ixxx1[8]; |
|
321 TUint32 ixxx2[4]; |
|
322 } uxxx; |
|
323 }; |
|
324 struct TInetReserved1 |
|
325 { |
|
326 TInetReserved0 ixxx0; |
|
327 TUint32 ixxx1; |
|
328 TUint32 ixxx2; |
|
329 }; |
|
330 |
|
331 inline TInt TInetAddr::AddrLen() |
|
332 { return sizeof(TInetReserved1); } |
|
333 |
|
334 inline TInetAddr& TInetAddr::Cast(const TSockAddr& anAddr) |
|
335 { return *((TInetAddr*)&anAddr); } |
|
336 inline TInetAddr& TInetAddr::Cast(const TSockAddr* anAddr) |
|
337 { return *((TInetAddr*)anAddr); } |
|
338 inline TBool TInetAddr::IsBroadcast() |
|
339 { return Address()==KInetAddrBroadcast; } |
|
340 inline TBool TInetAddr::IsWildPort() |
|
341 { return Port()==KInetPortNone; } |
|
342 inline TBool TInetAddr::IsWildAddr() |
|
343 { return Address()==KInetAddrNone; } |
|
344 inline TBool TInetAddr::IsClassA() |
|
345 { return (Address() & KInetAddrIdMaskA) == KInetAddrIdValA; } |
|
346 inline TBool TInetAddr::IsClassB() |
|
347 { return (Address() & KInetAddrIdMaskB) == KInetAddrIdValB; } |
|
348 inline TBool TInetAddr::IsClassC() |
|
349 { return (Address() & KInetAddrIdMaskC) == KInetAddrIdValC; } |
|
350 inline TBool TInetAddr::IsMulticast() |
|
351 { return (Address() & KInetAddrIdMaskD) == KInetAddrIdValD; } |
|
352 |
|
353 #endif |