Writing an Inbound Hook Tutorial

This topic describes how to write an inbound hook.

  1. The CIp6Hook() is a base class for all hook protocols. For more information, see the MIp6Hook() and CProtocolBaseUnbind() classes.

  2. The ApplyL() function is derived from the CIp6Hook() class to create an inbound hook. The following are the parameters of an ApplyL() function:
    Option Description

    aPacket

    Packet to process

    aInfo

    Packet information

    Note: The ApplyL() function is not used for post or pre-processing hooks.

How to write an Inbound Hook example

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;
     }

Related concepts
Creating an ESK File