This topic describes how to write an inbound hook.
The following is an example code for how to write an inbound hook:
CHookExample::ApplyL(RMBufHookPacket &aPacket, RMBufRecvInfo &aInfo) { if (aInfo.iProtocol != iProtocol) // Normally, it should never get here in this example. But, // if the prototocol was just changed via SetOption... return KIp6Hook_PASS; TInet6Packet<TExtensionHeader> ext(aPacket, aInfo.iOffset); if (ext.iHdr == NULL) return KIp6Hook_PASS; // Bad packet? But let someone else worry about it. if (ext.iHdr->Port() != iPort) return KIp6Hook_PASS; // Not for me, let someone else handle it. const TInt hdrlen = aInfo.CheckL(ext.iHdr->HeaderLength()); if (aInfo.iIcmp) { // Header is in returned packet of an ICMP Error const TInt offset = aInfo.iOffset - aInfo.iOffsetIp;// Relative offset within problem packet if (aInfo.iIcmp == KProtocolInet6Icmp && // only ICMP6 can be tested like this aInfo.iType == KInet6ICMP_ParameterProblem &&// A parameter problem... offset <= (TInt)aInfo.iParameter && // after start of this header? offset + hdrlen > (TInt)aInfo.iParameter)// and before end of this header? { // Someone didn't accept my strange header. // Could set some flag and stop sending it. aPacket.Free(); return -1; } // Error is not about my header, fall to DONE } else { // Implement header semantics // (none in this example). } // Header processed (Done), skip over // - need to indicate the location of "my next header" field, aInfo.iPrevNextHdr = (TUint16)(aInfo.iOffset+1); // - need to make the protocol of the following header available aInfo.iProtocol = ext.iHdr->NextHeader(); // - and finally, update the offset over my header. aInfo.iOffset += hdrlen; return KIp6Hook_DONE; }
Copyright ©2010 Nokia Corporation and/or its subsidiary(-ies).
All rights
reserved. Unless otherwise stated, these materials are provided under the terms of the Eclipse Public License
v1.0.