epoc32/include/ip4_hdr.h
author William Roberts <williamr@symbian.org>
Wed, 31 Mar 2010 12:33:34 +0100
branchSymbian3
changeset 4 837f303aceeb
parent 2 2fe1408b6811
permissions -rw-r--r--
Current Symbian^3 public API header files (from PDK 3.0.h)
This is the epoc32/include tree with the "platform" subtrees removed, and
all but a selected few mbg and rsg files removed.
williamr@2
     1
// Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
williamr@2
     2
// All rights reserved.
williamr@2
     3
// This component and the accompanying materials are made available
williamr@4
     4
// under the terms of "Eclipse Public License v1.0"
williamr@2
     5
// which accompanies this distribution, and is available
williamr@4
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
williamr@2
     7
//
williamr@2
     8
// Initial Contributors:
williamr@2
     9
// Nokia Corporation - initial contribution.
williamr@2
    10
//
williamr@2
    11
// Contributors:
williamr@2
    12
//
williamr@2
    13
// Description:
williamr@2
    14
// ip4_hdr.h - IPv4 header structure
williamr@2
    15
// Defines the basic classes for accessing the header
williamr@2
    16
// structures within IPv4 packets.
williamr@2
    17
//
williamr@2
    18
williamr@2
    19
williamr@2
    20
williamr@2
    21
/**
williamr@2
    22
 @file ip4_hdr.h
williamr@2
    23
 @ingroup ip_packet_formats
williamr@2
    24
 @publishedAll
williamr@2
    25
 @released
williamr@2
    26
*/
williamr@2
    27
williamr@2
    28
#ifndef __IP4_HDR_H__
williamr@2
    29
#define __IP4_HDR_H__
williamr@2
    30
williamr@2
    31
#include "in_hdr.h"
williamr@2
    32
#include "es_sock.h"		// for ByteOrder only!!!
williamr@2
    33
williamr@2
    34
/**
williamr@2
    35
* @addtogroup ip_packet_formats
williamr@2
    36
* @{
williamr@2
    37
*/
williamr@2
    38
williamr@2
    39
/**
williamr@2
    40
* @name IP v4 constants 
williamr@2
    41
* @since v7.0
williamr@2
    42
* @publishedAll
williamr@2
    43
* @released
williamr@2
    44
*/
williamr@4
    45
//@{
williamr@4
    46
const TUint8 KInet4IP_DF = 0x40;	//< Don't Fragment flag
williamr@4
    47
const TUint8 KInet4IP_MF = 0x20;	//< More Fragments flag
williamr@4
    48
const TInt KInetMinMtu = 68;		//< Minimum MTU as defined in RFC-791 
williamr@4
    49
//@}
williamr@2
    50
williamr@2
    51
class TInet6HeaderIP4
williamr@2
    52
/**
williamr@2
    53
*	Encapsulates an IPv4 IP header. 
williamr@2
    54
* 
williamr@2
    55
@verbatim
williamr@2
    56
  ************************
williamr@2
    57
  Extract from the RFC-791
williamr@2
    58
  ************************
williamr@2
    59
  0                   1                   2                   3
williamr@2
    60
  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
williamr@2
    61
  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
williamr@2
    62
  |Version|  IHL  |Type of Service|          Total Length         |
williamr@2
    63
  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
williamr@2
    64
  |         Identification        |Flags|      Fragment Offset    |
williamr@2
    65
  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
williamr@2
    66
  |  Time to Live |    Protocol   |         Header Checksum       |
williamr@2
    67
  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
williamr@2
    68
  |                       Source Address                          |
williamr@2
    69
  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
williamr@2
    70
  |                    Destination Address                        |
williamr@2
    71
  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
williamr@2
    72
  |                    Options                    |    Padding    |
williamr@2
    73
  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
williamr@2
    74
  
williamr@2
    75
  Version:  4 bits = 4
williamr@2
    76
  IHL:  4 bits
williamr@2
    77
williamr@2
    78
    Internet Header Length is the length of the internet header in 32
williamr@2
    79
    bit words, and thus points to the beginning of the data.  Note that
williamr@2
    80
    the minimum value for a correct header is 5
williamr@2
    81
williamr@2
    82
  Type of Service:  8 bits
williamr@2
    83
      Bits 0-2:  Precedence.
williamr@2
    84
      Bit    3:  0 = Normal Delay,      1 = Low Delay.
williamr@2
    85
      Bits   4:  0 = Normal Throughput, 1 = High Throughput.
williamr@2
    86
      Bits   5:  0 = Normal Relibility, 1 = High Relibility.
williamr@2
    87
      Bit  6-7:  Reserved for Future Use.
williamr@2
    88
williamr@2
    89
	  Precedence
williamr@2
    90
williamr@2
    91
          111 - Network Control
williamr@2
    92
          110 - Internetwork Control
williamr@2
    93
          101 - CRITIC/ECP
williamr@2
    94
          100 - Flash Override
williamr@2
    95
          011 - Flash
williamr@2
    96
          010 - Immediate
williamr@2
    97
          001 - Priority
williamr@2
    98
          000 - Routine
williamr@2
    99
  Total Length:  16 bits
williamr@2
   100
    Total Length is the length of the datagram, measured in octets,
williamr@2
   101
    including internet header and data.
williamr@2
   102
williamr@2
   103
  Identification:  16 bits
williamr@2
   104
    An identifying value assigned by the sender to aid in assembling the
williamr@2
   105
    fragments of a datagram.
williamr@2
   106
williamr@2
   107
  Flags:  3 bits
williamr@2
   108
    Various Control Flags.
williamr@2
   109
williamr@2
   110
      Bit 0: reserved, must be zero
williamr@2
   111
      Bit 1: (DF) 0 = May Fragment,  1 = Don't Fragment.
williamr@2
   112
      Bit 2: (MF) 0 = Last Fragment, 1 = More Fragments.
williamr@2
   113
williamr@2
   114
  Fragment Offset:  13 bits
williamr@2
   115
williamr@2
   116
    This field indicates where in the datagram this fragment belongs.
williamr@2
   117
    The fragment offset is measured in units of 8 octets (64 bits).  The
williamr@2
   118
    first fragment has offset zero.
williamr@2
   119
williamr@2
   120
  Time to Live:  8 bits
williamr@2
   121
  Protocol:  8 bits
williamr@2
   122
  Header Checksum:  16 bits
williamr@2
   123
  Source Address:  32 bits
williamr@2
   124
  Destination Address:  32 bits
williamr@2
   125
@endverbatim
williamr@2
   126
williamr@2
   127
@publishedAll
williamr@2
   128
@released
williamr@2
   129
@since v7.0
williamr@2
   130
*/
williamr@2
   131
	{
williamr@2
   132
public:
williamr@2
   133
	//
williamr@2
   134
	// Basic
williamr@2
   135
	//
williamr@2
   136
	/**
williamr@2
   137
	* Gets the minimum header length.	
williamr@2
   138
	* @return Minimum header length (= 20) 
williamr@2
   139
	* @since v7.0
williamr@2
   140
	*/
williamr@2
   141
	inline static TInt MinHeaderLength() {return 4*5; }
williamr@2
   142
	/**
williamr@2
   143
	* Gets the maximum header length.
williamr@2
   144
	* @return Maximum header length (= 60)
williamr@2
   145
	* @since v7.0
williamr@2
   146
	*/
williamr@2
   147
	inline static TInt MaxHeaderLength() {return 4*15; }
williamr@2
   148
	/**
williamr@2
   149
	* Gets a pointer to the byte following the header.
williamr@2
   150
	* @return Pointer to the byte following the header
williamr@2
   151
	* @since v7.0
williamr@2
   152
	*/
williamr@2
   153
	inline TUint8 *EndPtr() {return i + HeaderLength();}
williamr@2
   154
williamr@2
   155
	enum TOffsets
williamr@2
   156
		{
williamr@2
   157
		O_TotalLength = 2,
williamr@2
   158
		O_FragmentOffset = 6,
williamr@2
   159
		O_TTL = 8,
williamr@2
   160
		O_Protocol = 9
williamr@2
   161
		};
williamr@2
   162
	inline TInt Version() const
williamr@2
   163
		/**
williamr@2
   164
		* Gets the IP version from the header.
williamr@2
   165
		* @return IP version (should be 4 for IPv4)
williamr@2
   166
		*/ 
williamr@2
   167
		{
williamr@2
   168
		return (i[0] >> 4) & 0xf;
williamr@2
   169
		}
williamr@2
   170
	inline TInt HeaderLength() const
williamr@2
   171
		/**
williamr@2
   172
		* Gets the header length.
williamr@2
   173
		* @return Header length in bytes (based on IHL field)
williamr@2
   174
		*/
williamr@2
   175
		{
williamr@2
   176
		return (i[0] & 0x0f) * 4;	// Note: Returns bytes length!
williamr@2
   177
		}
williamr@2
   178
	inline TInt TOS() const
williamr@2
   179
		/**
williamr@2
   180
		* Gets the TOS from the header.
williamr@2
   181
		* @return TOS
williamr@2
   182
		*/
williamr@2
   183
		{
williamr@2
   184
		return i[1];
williamr@2
   185
		}
williamr@2
   186
	inline TBool EcnIsCongestion()
williamr@2
   187
		/**
williamr@2
   188
		* Gets ECN congestion status.
williamr@2
   189
		*
williamr@2
   190
		* see RFC-3168 for details.
williamr@2
   191
		*
williamr@2
   192
		* @return	True, if CE bit is set on an ECN capable packet.
williamr@2
   193
		*/
williamr@2
   194
		{
williamr@2
   195
		return ((TOS() & 3) == 3);
williamr@2
   196
		}
williamr@2
   197
	inline TInt TotalLength() const
williamr@2
   198
		/**
williamr@2
   199
		* Gets the Total Length from the header.
williamr@2
   200
		* @return Total Length (includes IP header and payload)
williamr@2
   201
		*/
williamr@2
   202
		{
williamr@2
   203
		return (i[2] << 8) | i[3];
williamr@2
   204
		}
williamr@2
   205
	inline TInt Identification() const
williamr@2
   206
		/**
williamr@2
   207
		* Gets the Identification from the header.
williamr@2
   208
		* @return Identification [0..65535]
williamr@2
   209
		*/
williamr@2
   210
		{
williamr@2
   211
		return (i[4] << 8) | i[5];
williamr@2
   212
		}
williamr@2
   213
	inline TInt Flags() const
williamr@2
   214
		/**
williamr@2
   215
		* Gets the Flags from the header.
williamr@2
   216
		* @note returns flags byte as is, may include bits of fragment offset!
williamr@2
   217
		* @return Flags
williamr@2
   218
		*/
williamr@2
   219
		{
williamr@2
   220
		return i[6];
williamr@2
   221
		}
williamr@2
   222
	inline TInt DF() const
williamr@2
   223
		/**
williamr@2
   224
		* Gets the DF flag from the header.
williamr@2
   225
		* @return DF flag (= KInet4IP_DF, if set and zero otherwise)
williamr@2
   226
		*/
williamr@2
   227
		{
williamr@2
   228
		return i[6] & KInet4IP_DF;
williamr@2
   229
		}
williamr@2
   230
	inline TInt MF() const
williamr@2
   231
		/**
williamr@2
   232
		* Gets the MF flag from the header.
williamr@2
   233
		* @return MF flag (= KInet4IP_MF, if set and zero otherwise)
williamr@2
   234
		*/
williamr@2
   235
		{
williamr@2
   236
		return i[6] & KInet4IP_MF;
williamr@2
   237
		}
williamr@2
   238
	inline TInt FragmentOffset() const
williamr@2
   239
		/**
williamr@2
   240
		* Gets the Fragment Offset from the header.
williamr@2
   241
		* @return Fragment Offset (raw 8 octet units, not a bytes offset!)
williamr@2
   242
		*/
williamr@2
   243
		{
williamr@2
   244
		return ((i[6] & 0x1f) << 8) | i[7];
williamr@2
   245
		}
williamr@2
   246
	inline TInt Ttl() const
williamr@2
   247
		/**
williamr@2
   248
		* Gets the Time to Live from the header.
williamr@2
   249
		* @return Time to Live [0..255]
williamr@2
   250
		*/
williamr@2
   251
		{
williamr@2
   252
		return i[8];
williamr@2
   253
		}
williamr@2
   254
	inline TInt Protocol() const
williamr@2
   255
		/**
williamr@2
   256
		* Gets the Protocol from the header.
williamr@2
   257
		* @return Protocol [0..255]
williamr@2
   258
		*/
williamr@2
   259
		{
williamr@2
   260
		return i[9];
williamr@2
   261
		}
williamr@2
   262
	inline TInt Checksum() const
williamr@2
   263
		/**
williamr@2
   264
		* Gets the Header Checksum from the header.
williamr@2
   265
		* @return Header Checksum (in NETWORK byte order)
williamr@2
   266
		*/
williamr@2
   267
		{
williamr@2
   268
		// Checksum is used in network byte order
williamr@2
   269
		return *((TUint16 *)&i[10]);
williamr@2
   270
		}
williamr@2
   271
	inline TUint32 SrcAddr() const
williamr@2
   272
		/**
williamr@2
   273
		* Gets the source address from the header.
williamr@2
   274
		* @return Source address (in host byte order)
williamr@2
   275
		*/
williamr@2
   276
		{
williamr@2
   277
		return (i[12] << 24) | (i[13] << 16) | (i[14] << 8) | i[15];
williamr@2
   278
		}
williamr@2
   279
	inline TUint32 DstAddr() const
williamr@2
   280
		/**
williamr@2
   281
		* Gets the destination address from the header.
williamr@2
   282
		* @return Destination address (in host byte order)
williamr@2
   283
		*/
williamr@2
   284
		{
williamr@2
   285
		return (i[16] << 24) | (i[17] << 16) | (i[18] << 8) | i[19];
williamr@2
   286
		}
williamr@2
   287
	inline TUint32 &SrcAddrRef() const
williamr@2
   288
		/**
williamr@2
   289
		* Gets a raw reference to the source address in network byte order.
williamr@2
   290
		* @return Raw reference to the source address
williamr@2
   291
		*/
williamr@2
   292
		{
williamr@2
   293
		return (TUint32 &)i[12];
williamr@2
   294
		}
williamr@2
   295
	inline TUint32 &DstAddrRef() const
williamr@2
   296
		/**
williamr@2
   297
		* Gets a raw reference to the destination address in network byte order.
williamr@2
   298
		* @return Raw reference to the destination address
williamr@2
   299
		*/
williamr@2
   300
		{
williamr@2
   301
		return (TUint32 &)i[16];
williamr@2
   302
		}
williamr@2
   303
	inline TPtrC8 Options() const
williamr@2
   304
		/**
williamr@2
   305
		* Gets the Options from the header (const overload).
williamr@2
   306
		* @return Options
williamr@2
   307
		*
williamr@2
   308
		* @note
williamr@2
   309
		*	This relies on correct value of IHL! Must not be used with
williamr@2
   310
		*	corrupt headers (will panic if IHL < 5!).
williamr@2
   311
		*/
williamr@2
   312
		{
williamr@2
   313
		// *NOTE* This includes the padding bytes, or can be empty!
williamr@2
   314
		return TPtrC8((TUint8 *)&i[20], HeaderLength() - 20);
williamr@2
   315
		}
williamr@2
   316
	inline TPtr8 Options()
williamr@2
   317
		/**
williamr@2
   318
		* Gets the Options from the header.
williamr@2
   319
		* @return Options
williamr@2
   320
		*
williamr@2
   321
		* @note
williamr@2
   322
		*	This relies on correct value of IHL! Must not be used with
williamr@2
   323
		*	corrupt headers (will panic if IHL < 5!).
williamr@2
   324
		*/
williamr@2
   325
		{
williamr@2
   326
		// It is yet unclear what will be the best way to build
williamr@2
   327
		// the options into the header. For the time being this
williamr@2
   328
		// method returns a modifiable Ptr8 to the the available
williamr@2
   329
		// option space. For this to work, the application must
williamr@2
   330
		// have used the SetHeaderLength() to fix the current
williamr@2
   331
		// available length.
williamr@2
   332
		return TPtr8((TUint8 *)&i[20], HeaderLength() - 20);
williamr@2
   333
		}
williamr@2
   334
williamr@2
   335
	inline void Init(TInt aTOS = 0)
williamr@2
   336
		/**
williamr@2
   337
		* Initialises the IPv4 header to basic initial values.
williamr@2
   338
		*
williamr@2
   339
		* @li	Version = 4
williamr@2
   340
		* @li	IHL = 5
williamr@2
   341
		* @li	Total Length = 20
williamr@2
   342
		* @li	Identification = 0
williamr@2
   343
		* @li	Fragment Offset = 0
williamr@2
   344
		* @li	Flags = 0
williamr@2
   345
		* @li	TTL = 0
williamr@2
   346
		* @li	Checksum = 0
williamr@2
   347
		* @li	TOS = aTOS (optional parameter, default = 0)
williamr@2
   348
		*
williamr@2
   349
		* However, address fields are not touched, because
williamr@2
   350
		* they are most often set separately in any case.
williamr@2
   351
		*
williamr@2
   352
		* @param	aTOS	initial value for TOS (= 0)
williamr@2
   353
		*/
williamr@2
   354
		{
williamr@2
   355
		i[0] = 0x45;			// Version=4, IHL=5 (= 20 bytes)
williamr@2
   356
		i[1] = (TUint8)aTOS;	// TOS
williamr@2
   357
		i[2] = 0;
williamr@2
   358
		i[3] = 20;				// Total length = 20
williamr@2
   359
		*((TInt32 *)&i[4]) = 0;	// Identification = 0, flags=0, Fragment offset = 0;
williamr@2
   360
		*((TInt32 *)&i[8]) = 0;	// TTL=0,Protocol=0,Checksum=0
williamr@2
   361
		}
williamr@2
   362
	//
williamr@2
   363
	// Build, set IP header field values into the packet
williamr@2
   364
	//
williamr@2
   365
williamr@2
   366
	inline void SetVersion(TInt aVersion)
williamr@2
   367
		/**
williamr@2
   368
		* Sets the IP version in the header.
williamr@2
   369
		* @param	aVersion the value to be set [0..15]
williamr@2
   370
		*/
williamr@2
   371
		{
williamr@2
   372
		i[0] = (TUint8)((i[0] & 0x0f) | ((aVersion << 4) & 0xf0));
williamr@2
   373
		}
williamr@2
   374
	inline void SetHeaderLength(TInt aLength)
williamr@2
   375
		/**
williamr@2
   376
		* Sets the header length (IHL).
williamr@2
   377
		*
williamr@2
   378
		* @param aLength
williamr@2
   379
		*	the length of the IPv4 header in BYTES. The
williamr@2
   380
		*	IHL is computed from this, without any sanity
williamr@2
   381
		*	checks. The valid range is [20..60].
williamr@2
   382
		*/
williamr@2
   383
		{
williamr@2
   384
		i[0] =  (TUint8)((i[0] & 0xf0) | ((aLength >> 2) & 0x0f));
williamr@2
   385
		}
williamr@2
   386
	inline void SetTOS(TInt aTos)
williamr@2
   387
		/**
williamr@2
   388
		* Sets the TOS in the header.
williamr@2
   389
		* @param	aTos	The TOS value to set [0..255]
williamr@2
   390
		*/
williamr@2
   391
		{
williamr@2
   392
		i[1] = (TUint8)aTos;
williamr@2
   393
		}
williamr@2
   394
	inline void SetTotalLength(TInt aLength)
williamr@2
   395
		/**
williamr@2
   396
		* Sets the Total Length in the header.
williamr@2
   397
		*
williamr@2
   398
		* @param	aLength the length of combined header and
williamr@2
   399
		*			payload in bytes (no sanity checks, but the
williamr@2
   400
		*			value should be in range [20..65535]). Only
williamr@2
   401
		*			16 least significant bits used.
williamr@2
   402
		*/
williamr@2
   403
		{
williamr@2
   404
		i[3] = (TUint8)aLength;
williamr@2
   405
		i[2] = (TUint8)(aLength >> 8);
williamr@2
   406
		}
williamr@2
   407
	inline void SetIdentification(TInt aId)
williamr@2
   408
		/**
williamr@2
   409
		* Sets the Identification in the header.
williamr@2
   410
		*
williamr@2
   411
		* @param	aId	the value to be set (only 16 least significant
williamr@2
   412
		*			bits are used, rest is ignored).
williamr@2
   413
		*/
williamr@2
   414
		{
williamr@2
   415
		i[5] = (TUint8)aId;
williamr@2
   416
		i[4] = (TUint8)(aId >> 8);
williamr@2
   417
		}
williamr@2
   418
williamr@2
   419
	inline void SetFlags(TUint8 aFlags)
williamr@2
   420
		/**
williamr@2
   421
		* Sets the Flags in the header.
williamr@2
   422
		*
williamr@2
   423
		* Flags are assumed to be in the three most significant bits
williamr@2
   424
		* of aFlags, in their proper positions.
williamr@2
   425
		* (No individual settings provided, if you need to set a flag
williamr@2
   426
		* without affecting others, use Flags() to get old values,
williamr@2
   427
		* update and store the result with SetFlags()).
williamr@2
   428
		*
williamr@2
   429
		* @param	aFlags	contains the new flags
williamr@2
   430
		*/
williamr@2
   431
		{
williamr@2
   432
		i[6] = (TUint8)((i[6] & 0x1f) | (aFlags & 0xe0));
williamr@2
   433
		}
williamr@2
   434
	inline void SetFragmentOffset(TUint16 aOffset)
williamr@2
   435
		/**
williamr@2
   436
		* Sets the Fragment Offset in the header.
williamr@2
   437
		* @param aOffset Fragment Offset (8 octet units, not in bytes)
williamr@2
   438
		*/
williamr@2
   439
		{
williamr@2
   440
		i[6] = (TUint8)((i[6] & 0xe0) | ((aOffset >> 8) & 0x1f));
williamr@2
   441
		i[7] = (TUint8)aOffset;
williamr@2
   442
		}
williamr@2
   443
	inline void SetTtl(TInt aTTL)
williamr@2
   444
		/**
williamr@2
   445
		* Sets the Time to Live in the header.
williamr@2
   446
		* @param aTTL Time to Live [0..255]
williamr@2
   447
		*/
williamr@2
   448
		{
williamr@2
   449
		i[8] = (TUint8)aTTL;
williamr@2
   450
		}
williamr@2
   451
	inline void SetProtocol(TInt aProtocol)
williamr@2
   452
		/**
williamr@2
   453
		* Sets the Protocol in the header.
williamr@2
   454
		* @param aProtocol Protocol [0..255]
williamr@2
   455
		*/
williamr@2
   456
		{
williamr@2
   457
		i[9] = (TUint8)aProtocol;
williamr@2
   458
		}
williamr@2
   459
	inline void SetChecksum(TInt aSum)
williamr@2
   460
		/**
williamr@2
   461
		* Sets the Header Checksum in the header.
williamr@2
   462
		* @param aSum Header Checksum [0..65535]
williamr@2
   463
		*	(16 least significant bits stored
williamr@2
   464
		*	as is (assumed to be in NETWORK byte order).					
williamr@2
   465
		*/
williamr@2
   466
		{
williamr@2
   467
		// Checksum is used in network byte order
williamr@2
   468
		*((TUint16 *)&i[10]) = (TUint16)aSum;
williamr@2
   469
		}
williamr@2
   470
williamr@2
   471
	inline void SetSrcAddr(TUint32 aAddr)
williamr@2
   472
		/**
williamr@2
   473
		* Sets the source address in the header.
williamr@2
   474
		* @param aAddr Source address (IPv4, 32 bit integer in host byte order)
williamr@2
   475
		*/
williamr@2
   476
		{
williamr@2
   477
		i[15] = (TUint8)aAddr;
williamr@2
   478
		i[14] = (TUint8)(aAddr >> 8);
williamr@2
   479
		i[13] = (TUint8)(aAddr >> 16);
williamr@2
   480
		i[12] = (TUint8)(aAddr >> 24);
williamr@2
   481
		}
williamr@2
   482
williamr@2
   483
	inline void SetDstAddr(TUint32 aAddr)
williamr@2
   484
		/**
williamr@2
   485
		* Sets the destination address in the header.
williamr@2
   486
		* @param aAddr Destination IPv4 address (32 bit integer) in host byte order
williamr@2
   487
		*/
williamr@2
   488
		{
williamr@2
   489
		i[19] = (TUint8)aAddr;
williamr@2
   490
		i[18] = (TUint8)(aAddr >> 8);
williamr@2
   491
		i[17] = (TUint8)(aAddr >> 16);
williamr@2
   492
		i[16] = (TUint8)(aAddr >> 24);
williamr@2
   493
		}
williamr@2
   494
williamr@2
   495
	//
williamr@2
   496
	// The old IPv4 stack leaves IP header in packet when passing it upwards,
williamr@2
   497
	// but this header is swapped into host order. As upper layers really don't
williamr@2
   498
	// need this stuff much, only few "compatibility" methods is defined here
williamr@2
   499
	//
williamr@2
   500
williamr@2
   501
	inline TInt HostHeaderLength() const
williamr@2
   502
		{
williamr@2
   503
		/**
williamr@2
   504
		* Gets the Header Length from a header that is in Host byte order.
williamr@2
   505
		* @return Header Length
williamr@2
   506
		*
williamr@2
   507
		* @deprecated There is no reason to use swapped headers
williamr@2
   508
		*/
williamr@2
   509
		return (i[3] & 0x0f) * 4;
williamr@2
   510
		}
williamr@2
   511
	inline TInt HostProtocol() const
williamr@2
   512
		/**
williamr@2
   513
		* Gets the Protocol from a header that is in Host byte order.
williamr@2
   514
		* @return Protocol
williamr@2
   515
		* @deprecated There is no reason to use swapped headers
williamr@2
   516
		*/
williamr@2
   517
		{
williamr@2
   518
		return i[10];
williamr@2
   519
		}
williamr@2
   520
williamr@2
   521
	inline void Swap()
williamr@2
   522
		/**
williamr@2
   523
		* Swaps the byte order in the header.
williamr@2
   524
		* @deprecated There is no reason to use swapped headers
williamr@2
   525
		*/
williamr@2
   526
		{
williamr@2
   527
		*(TUint32 *)(&i[0]) = ByteOrder::Swap32(*(TUint32 *)(&i[0]));
williamr@2
   528
		*(TUint32 *)(&i[4]) = ByteOrder::Swap32(*(TUint32 *)(&i[4]));
williamr@2
   529
		*(TUint32 *)(&i[8]) = ByteOrder::Swap32(*(TUint32 *)(&i[8]));
williamr@2
   530
		*(TUint32 *)(&i[12]) = ByteOrder::Swap32(*(TUint32 *)(&i[12]));
williamr@2
   531
		*(TUint32 *)(&i[16]) = ByteOrder::Swap32(*(TUint32 *)(&i[16]));
williamr@2
   532
		}
williamr@2
   533
				
williamr@2
   534
private:
williamr@2
   535
	union
williamr@2
   536
		{
williamr@4
   537
		TUint8 i[4*15];	//< This allocates maximum length (60 bytes)
williamr@4
   538
		TUint32 iAlign;	//< A dummy member to force the 4 byte alignment
williamr@2
   539
		};
williamr@2
   540
	};
williamr@2
   541
williamr@2
   542
/**
williamr@2
   543
* @name IP v4 Option constants
williamr@2
   544
* @since v7.0
williamr@2
   545
* @publishedAll
williamr@2
   546
* @released
williamr@2
   547
*/
williamr@4
   548
//@{
williamr@2
   549
const TUint8 KInet4Option_End			= 0x00;
williamr@2
   550
const TUint8 KInet4Option_Nop			= 0x01;
williamr@2
   551
williamr@2
   552
const TUint8 KInet4OptionFlag_Copy		= 0x80;
williamr@4
   553
//@}
williamr@2
   554
williamr@2
   555
//
williamr@2
   556
//	ICMP v4 constants
williamr@2
   557
//	=================
williamr@2
   558
//
williamr@2
   559
/**
williamr@2
   560
* @name ICMP v4 constants 
williamr@2
   561
* @since v7.0
williamr@2
   562
* @publishedAll
williamr@2
   563
* @released
williamr@2
   564
*/
williamr@4
   565
//@{
williamr@2
   566
/** Echo Reply. See TInet6HeaderICMP_Echo (IPv4 and IPv6 use the same format). */
williamr@2
   567
const TUint8 KInet4ICMP_EchoReply		=  0;
williamr@2
   568
const TUint8 KInet4ICMP_Unreachable		=  3;
williamr@2
   569
const TUint8 KInet4ICMP_SourceQuench	=  4;
williamr@2
   570
const TUint8 KInet4ICMP_Redirect		=  5;
williamr@2
   571
/** Echo Request. See TInet6HeaderICMP_Echo (IPv4 and IPv6 use the same format). */
williamr@2
   572
const TUint8 KInet4ICMP_Echo			=  8;
williamr@2
   573
const TUint8 KInet4ICMP_TimeExceeded	= 11;
williamr@2
   574
const TUint8 KInet4ICMP_ParameterProblem = 12;
williamr@2
   575
const TUint8 KInet4ICMP_TimeStamp		= 13;
williamr@2
   576
const TUint8 KInet4ICMP_TimeStampReply	= 14;
williamr@4
   577
//@}
williamr@2
   578
williamr@4
   579
//@}
williamr@2
   580
#endif