|
1 // Copyright (c) 2002-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 // Name : CIcmpV4Receiver.cpp |
|
15 // Part of : ConnectionMgr |
|
16 // Version : SIP/4.0 |
|
17 // Destination Unreachable Message: |
|
18 // 0 1 2 3 |
|
19 // 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 |
|
20 // | Type | Code | Checksum | |
|
21 // | unused | |
|
22 // | Internet Header + 64 bits of Original Data Datagram | |
|
23 // Internet header: |
|
24 // 0 1 2 3 |
|
25 // 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 |
|
26 // |Version| IHL |Type of Service| Total Length | |
|
27 // | Identification |Flags| Fragment Offset | |
|
28 // | Time to Live | Protocol | Header Checksum | |
|
29 // | Source Address | |
|
30 // | Destination Address | |
|
31 // | Options | Padding | |
|
32 // User datagram: |
|
33 // 0 7 8 15 16 23 24 31 |
|
34 // | Source | Destination | |
|
35 // | Port | Port | |
|
36 // | Length | Checksum | |
|
37 // | data octets ... |
|
38 // In the code the data is located in bytes. |
|
39 // |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 #include <ip4_hdr.h> |
|
45 #include <icmp6_hdr.h> // This is identical to ICMPv4 header |
|
46 #include <udp_hdr.h> |
|
47 #include <in_sock.h> |
|
48 #include "CIcmpV4Receiver.h" |
|
49 #include "MIcmpReceiver.h" |
|
50 #include "CommonConsts.h" |
|
51 #include "SipLogs.h" |
|
52 |
|
53 |
|
54 // ----------------------------------------------------------------------------- |
|
55 // CIcmpV4Receiver::NewL |
|
56 // ----------------------------------------------------------------------------- |
|
57 // |
|
58 CIcmpV4Receiver* CIcmpV4Receiver::NewL(MIcmpErrorObserver& aObserver, |
|
59 RSocketServ& aServer) |
|
60 { |
|
61 CIcmpV4Receiver* self = new (ELeave) CIcmpV4Receiver(); |
|
62 CleanupStack::PushL(self); |
|
63 self->ConstructL(aObserver, aServer); |
|
64 CleanupStack::Pop(); |
|
65 return self; |
|
66 } |
|
67 |
|
68 // ----------------------------------------------------------------------------- |
|
69 // CIcmpV4Receiver::CIcmpV4Receiver |
|
70 // ----------------------------------------------------------------------------- |
|
71 // |
|
72 CIcmpV4Receiver::CIcmpV4Receiver() : CActive( CActive::EPriorityStandard ) |
|
73 { |
|
74 } |
|
75 |
|
76 // ----------------------------------------------------------------------------- |
|
77 // CIcmpV4Receiver::ConstructL |
|
78 // ----------------------------------------------------------------------------- |
|
79 // |
|
80 void CIcmpV4Receiver::ConstructL(MIcmpErrorObserver& aObserver, |
|
81 RSocketServ& aServer) |
|
82 { |
|
83 CActiveScheduler::Add(this); |
|
84 iObserver = &aObserver; |
|
85 iServer = &aServer; |
|
86 |
|
87 // Start |
|
88 User::LeaveIfError(iSocket.Open(*iServer, KAfInet, KSockDatagram, |
|
89 KProtocolInetIcmp)); |
|
90 Receive(); |
|
91 } |
|
92 |
|
93 // ----------------------------------------------------------------------------- |
|
94 // CIcmpV4Receiver::~CIcmpV4Receiver |
|
95 // ----------------------------------------------------------------------------- |
|
96 // |
|
97 CIcmpV4Receiver::~CIcmpV4Receiver() |
|
98 { |
|
99 Cancel(); |
|
100 iSocket.Close(); |
|
101 } |
|
102 |
|
103 // ----------------------------------------------------------------------------- |
|
104 // CIcmpV4Receiver::RunL |
|
105 // ----------------------------------------------------------------------------- |
|
106 // |
|
107 void CIcmpV4Receiver::RunL() |
|
108 { |
|
109 if (iStatus == KErrNone) |
|
110 { |
|
111 CheckError(); |
|
112 Receive(); |
|
113 } |
|
114 } |
|
115 |
|
116 // Disabled PC-Lint warning for "Suspicious pointer-to-pointer conversion |
|
117 // (area too small))". It was caused by TUin8* to TInet6xxx typecasts and could |
|
118 // not be avoided otherwise. |
|
119 /*lint -e826 */ |
|
120 |
|
121 // ----------------------------------------------------------------------------- |
|
122 // CIcmpV4Receiver::CheckError |
|
123 // ----------------------------------------------------------------------------- |
|
124 // |
|
125 void CIcmpV4Receiver::CheckError() |
|
126 { |
|
127 const TUint KDestinationUnreachable = 3; |
|
128 |
|
129 // Pointer to ICMP header |
|
130 TInet6HeaderICMP* icmpPtr = ( TInet6HeaderICMP* ) iData.Ptr(); |
|
131 |
|
132 // Pointer to IPv4 header |
|
133 TInet6HeaderIP4* ipv4Ptr = ( TInet6HeaderIP4* )( iData.Ptr() + 8 ); |
|
134 |
|
135 // Error message type |
|
136 TUint32 error = icmpPtr->Type(); |
|
137 if ( error == KDestinationUnreachable ) |
|
138 { |
|
139 // Check that protocol is UDP |
|
140 TUint32 protocol = ipv4Ptr->Protocol(); |
|
141 if ( protocol == KProtocolInetUdp ) |
|
142 { |
|
143 // Pointer to UDP data |
|
144 TInet6HeaderUDP* udpPtr = ( TInet6HeaderUDP* )( ipv4Ptr->EndPtr() ); |
|
145 |
|
146 // Get the destination port number |
|
147 iAddress.SetPort( udpPtr->DstPort() ); |
|
148 |
|
149 // Set the destination address |
|
150 iAddress.SetAddress( ipv4Ptr->DstAddr() ); |
|
151 |
|
152 __SIP_INT_LOG1( "ICMP error", error ) |
|
153 __SIP_ADDR_LOG( "ICMP error address", iAddress ) |
|
154 |
|
155 // Error message to observer |
|
156 iObserver->IcmpError( iAddress ); |
|
157 } |
|
158 } |
|
159 } |
|
160 |
|
161 // ----------------------------------------------------------------------------- |
|
162 // CIcmpV4Receiver::DoCancel |
|
163 // ----------------------------------------------------------------------------- |
|
164 // |
|
165 void CIcmpV4Receiver::DoCancel() |
|
166 { |
|
167 iSocket.CancelRecv(); |
|
168 } |
|
169 |
|
170 // ----------------------------------------------------------------------------- |
|
171 // CIcmpV4Receiver::Receive |
|
172 // ----------------------------------------------------------------------------- |
|
173 // |
|
174 void CIcmpV4Receiver::Receive() |
|
175 { |
|
176 if(!IsActive()) |
|
177 { |
|
178 iSocket.Recv( iData, 0, iStatus ); |
|
179 SetActive(); |
|
180 } |
|
181 } |