epoc32/include/arp_hdr.h
branchSymbian2
changeset 2 2fe1408b6811
child 4 837f303aceeb
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/epoc32/include/arp_hdr.h	Tue Mar 16 16:12:26 2010 +0000
     1.3 @@ -0,0 +1,190 @@
     1.4 +// Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of the License "Symbian Foundation License v1.0" to Symbian Foundation members and "Symbian Foundation End User License Agreement v1.0" to non-members
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.symbianfoundation.org/legal/licencesv10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +// arp_hdr.h - ARP header structure
    1.18 +// ARP header structure.
    1.19 +//
    1.20 +
    1.21 +
    1.22 +
    1.23 +/**
    1.24 + @file arp_hdr.h
    1.25 + @ingroup ip_packet_formats
    1.26 + @publishedAll
    1.27 + @released
    1.28 +*/
    1.29 +
    1.30 +#ifndef __ARP_HDR_H__
    1.31 +#define __ARP_HDR_H__
    1.32 +
    1.33 +#include "in_hdr.h"
    1.34 +
    1.35 +/**
    1.36 +* @addtogroup  ip_packet_formats
    1.37 +* @{
    1.38 +*/
    1.39 +
    1.40 +/**
    1.41 +* "Fake" protocol number for ARP.
    1.42 +*
    1.43 +* This protocol value is only used to recognize the ARP packets
    1.44 +* coming from the interface. There is no "real" ARP.PRT.
    1.45 +*/
    1.46 +const TUint KProtocolArp		= 0xFAD;	// (get some better value)
    1.47 +
    1.48 +const TUint16 KArpProtocolType_IP = 0x0800;	// Protocol Type value for IPv4
    1.49 +//
    1.50 +// Hardware types listed only as example, it is assumed that the
    1.51 +// driver knows its own type...
    1.52 +//
    1.53 +const TUint16 KArpHarwareType_ETHERNET = 1;
    1.54 +const TUint16 KArpHarwareType_IEEE_802 = 6;
    1.55 +
    1.56 +/**
    1.57 +@publishedAll
    1.58 +@released
    1.59 +*/
    1.60 +enum TArpOperation	// from RFC-1700
    1.61 +	{
    1.62 +	EArpOperation_REQUEST = 1,			// RFC-826
    1.63 +	EArpOperation_REPLY = 2,			// RFC-826
    1.64 +	EArpOperation_REQUEST_REVERSE = 3,	// RFC-903
    1.65 +	EArpOperation_REPLY_REVERSE = 4,	// RFC-903
    1.66 +	EArpOperation_DRARP_REQUEST = 5,	//
    1.67 +	EArpOperation_DRARP_REPLY = 6,
    1.68 +	EArpOperation_DRARP_ERROR = 7,
    1.69 +	EArpOperation_INARP_REQUEST = 8,	// RFC-1293
    1.70 +	EArpOperation_INARP_REPLY = 9,		// RFC-1293
    1.71 +	EArpOperation_ARP_NAK = 10
    1.72 +	};
    1.73 +
    1.74 +
    1.75 +class TInet6HeaderArp
    1.76 +	/**
    1.77 +	* ARP Header.
    1.78 +	*
    1.79 +@verbatim
    1.80 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    1.81 + |        Hardware Type          |         Protocol Type         |
    1.82 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    1.83 + |  HwAddrLen    |   PrAddrLen   |         ARP Operation         |
    1.84 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    1.85 + |         Sender's physical hardware address                    |
    1.86 +   - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    1.87 + |         Sender's protocol address                             |
    1.88 +   - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    1.89 + |         Target's physical hardware address                    |
    1.90 +   - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    1.91 + |         Target's protocol address                             |
    1.92 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    1.93 +@endverbatim
    1.94 +	* @note
    1.95 +	* This definition covers only the fixed portion of the
    1.96 +	* message. DO NOT DECLARE A VARIABLE WITH THIS CLASS!
    1.97 +	* @publishedAll
    1.98 +	* @released
    1.99 +	*/
   1.100 +	{
   1.101 +public:
   1.102 +	inline static TInt MinHeaderLength() {return 8; }
   1.103 +	inline static TInt MaxHeaderLength() {return 128; }	
   1.104 +
   1.105 +	inline TUint8* EndPtr() { return i + HeaderLength(); }
   1.106 +	inline TInt HeaderLength() const { return 8 + 2 * HwAddrLen() + 2 * PrAddrLen(); } // Return true byte length
   1.107 +
   1.108 +	// Access methods
   1.109 +
   1.110 +	inline TInt HardwareType() const	// Return hardware type value in host order
   1.111 +		{
   1.112 +		return i[0] << 8 | i[1];
   1.113 +		}
   1.114 +
   1.115 +	inline TInt ProtocolType() const	// Return protocol type value in host order
   1.116 +		{
   1.117 +		return i[2] << 8 | i[3];
   1.118 +		}
   1.119 +
   1.120 +	inline TInt HwAddrLen()	const		// Return hardware address length (in bytes)
   1.121 +		{
   1.122 +		return i[4];
   1.123 +		}
   1.124 +
   1.125 +	inline TInt PrAddrLen()	const		// Return protocol address length (in bytes)
   1.126 +		{
   1.127 +		return i[5];
   1.128 +		}
   1.129 +
   1.130 +	inline TInt Operation() const
   1.131 +		{
   1.132 +		return i[6] << 8 | i[7];
   1.133 +		}
   1.134 +
   1.135 +	// Access/Modify
   1.136 +
   1.137 +	inline TPtr8 SenderHwAddr()
   1.138 +		{
   1.139 +		return TPtr8(&i[8], HwAddrLen(), HwAddrLen());
   1.140 +		}
   1.141 +	inline TPtr8 SenderPrAddr()
   1.142 +		{
   1.143 +		return TPtr8(&i[8] + HwAddrLen(), PrAddrLen(), PrAddrLen());
   1.144 +		}
   1.145 +	inline TPtr8 TargetHwAddr()
   1.146 +		{
   1.147 +		return TPtr8(&i[8] + HwAddrLen() + PrAddrLen(), HwAddrLen(), HwAddrLen());
   1.148 +		}
   1.149 +	inline TPtr8 TargetPrAddr()
   1.150 +		{
   1.151 +		return TPtr8(&i[8] + 2*HwAddrLen() + PrAddrLen(), PrAddrLen(), PrAddrLen());
   1.152 +		}
   1.153 +
   1.154 +	// Modify
   1.155 +
   1.156 +	inline void SetHardwareType(TInt aType)	// Set hardware type value
   1.157 +		{
   1.158 +		i[1] = (TUint8)aType;
   1.159 +		i[0] = (TUint8)(aType >> 8);
   1.160 +		}
   1.161 +
   1.162 +	inline void SetProtocolType(TInt aType)	// Set protocol type value
   1.163 +		{
   1.164 +		i[3] = (TUint8)aType;
   1.165 +		i[2] = (TUint8)(aType >> 8);
   1.166 +		}
   1.167 +
   1.168 +	inline void SetHwAddrLen(TInt aLength)	// Set hardware address length (in bytes)
   1.169 +		{
   1.170 +		i[4] = (TUint8)aLength;
   1.171 +		}
   1.172 +
   1.173 +	inline void SetPrAddrLen(TInt aLength)	// Set protocol address length (in bytes)
   1.174 +		{
   1.175 +		i[5] = (TUint8)aLength;
   1.176 +		}
   1.177 +
   1.178 +	inline void SetOperation(TInt aOperation)
   1.179 +		{
   1.180 +		i[7] = (TUint8)aOperation;
   1.181 +		i[6] = (TUint8)(aOperation >> 8);
   1.182 +		}
   1.183 +
   1.184 +private:
   1.185 +	union
   1.186 +		{
   1.187 +		TUint8 i[8];
   1.188 +		TUint32 iAlign;	// A dummy member to force the 4 byte alignment
   1.189 +		};
   1.190 +	};
   1.191 +
   1.192 +/** @} */
   1.193 +#endif