epoc32/include/udp_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/udp_hdr.h	Tue Mar 16 16:12:26 2010 +0000
     1.3 @@ -0,0 +1,115 @@
     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 +// udp_hdr.h - UDP header structure
    1.18 +// Defines the basic classes for accessing the header
    1.19 +// structures within UDP packets.
    1.20 +//
    1.21 +
    1.22 +
    1.23 +
    1.24 +/**
    1.25 + @file udp_hdr.h
    1.26 + @ingroup ip_packet_formats
    1.27 + @publishedAll
    1.28 + @released
    1.29 +*/
    1.30 +
    1.31 +#ifndef __UDP_HDR_H__
    1.32 +#define __UDP_HDR_H__
    1.33 +
    1.34 +#include <e32def.h>
    1.35 +#include "in_hdr.h"
    1.36 +
    1.37 +/**
    1.38 +* @addtogroup ip_packet_formats
    1.39 +* @{
    1.40 +*/
    1.41 +
    1.42 +// TInet6HeaderUPD
    1.43 +
    1.44 +class TInet6HeaderUDP
    1.45 +	/** UDP Header format.
    1.46 +    * User Datagram Header Format
    1.47 +	* @verbatim
    1.48 +Extract from RFC-768
    1.49 +                                    
    1.50 +     0      7 8     15 16    23 24    31  
    1.51 +    +--------+--------+--------+--------+ 
    1.52 +    |     Source      |   Destination   | 
    1.53 +    |      Port       |      Port       | 
    1.54 +    +--------+--------+--------+--------+ 
    1.55 +    |                 |                 | 
    1.56 +    |     Length      |    Checksum     | 
    1.57 +    +--------+--------+--------+--------+ 
    1.58 +    |                                     
    1.59 +    |          data octets ...            
    1.60 +    +---------------- ...                 
    1.61 +@endverbatim
    1.62 +	* @publishedAll
    1.63 +	* @released
    1.64 +	*/
    1.65 +	{
    1.66 +public:
    1.67 +	inline TInt HeaderLength() const {return 8;}
    1.68 +	inline static TInt MinHeaderLength() {return 8; }
    1.69 +	inline static TInt MaxHeaderLength() {return 8; }
    1.70 +	inline TUint8 *EndPtr() {return i + HeaderLength();}
    1.71 +	//
    1.72 +	// Access, Get UDP field values from the packet
    1.73 +	//
    1.74 +	inline TUint SrcPort() const
    1.75 +		{
    1.76 +		return (i[0] << 8) + i[1];
    1.77 +		}
    1.78 +	inline TUint DstPort() const
    1.79 +		{
    1.80 +		return (i[2] << 8) + i[3];
    1.81 +		}
    1.82 +	inline TInt Length() const
    1.83 +		{
    1.84 +		return (i[4] << 8) + i[5];
    1.85 +		}
    1.86 +	inline TInt Checksum() const
    1.87 +		{
    1.88 +		// Checksum is used in network byte order
    1.89 +		return *((TUint16 *)&i[6]);
    1.90 +		}
    1.91 +	//
    1.92 +	// Build, Set UDP field value to the packet
    1.93 +	//
    1.94 +	inline void SetSrcPort(TUint aPort)
    1.95 +		{
    1.96 +		i[0] = (TUint8)(aPort >> 8);
    1.97 +		i[1] = (TUint8)aPort;
    1.98 +		}
    1.99 +	inline void SetDstPort(TUint aPort)
   1.100 +		{
   1.101 +		i[2] = (TUint8)(aPort >> 8);
   1.102 +		i[3] = (TUint8)aPort;
   1.103 +		}
   1.104 +	inline void SetLength(TInt aLength)
   1.105 +		{
   1.106 +		i[4] = (TUint8)(aLength / 256);
   1.107 +		i[5] = (TUint8) aLength;
   1.108 +		}
   1.109 +	inline void SetChecksum(TInt aSum)
   1.110 +		{
   1.111 +		// Checksum is used in network byte order
   1.112 +		*((TUint16 *)&i[6]) = (TUint16)aSum;
   1.113 +		}
   1.114 +private:
   1.115 +	TUint8 i[8];
   1.116 +	};
   1.117 +/** @} */
   1.118 +#endif