1 // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // 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
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.symbianfoundation.org/legal/licencesv10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // udp_hdr.h - UDP header structure
15 // Defines the basic classes for accessing the header
16 // structures within UDP packets.
23 @ingroup ip_packet_formats
35 * @addtogroup ip_packet_formats
42 /** UDP Header format.
43 * User Datagram Header Format
48 +--------+--------+--------+--------+
49 | Source | Destination |
51 +--------+--------+--------+--------+
54 +--------+--------+--------+--------+
64 inline TInt HeaderLength() const {return 8;}
65 inline static TInt MinHeaderLength() {return 8; }
66 inline static TInt MaxHeaderLength() {return 8; }
67 inline TUint8 *EndPtr() {return i + HeaderLength();}
69 // Access, Get UDP field values from the packet
71 inline TUint SrcPort() const
73 return (i[0] << 8) + i[1];
75 inline TUint DstPort() const
77 return (i[2] << 8) + i[3];
79 inline TInt Length() const
81 return (i[4] << 8) + i[5];
83 inline TInt Checksum() const
85 // Checksum is used in network byte order
86 return *((TUint16 *)&i[6]);
89 // Build, Set UDP field value to the packet
91 inline void SetSrcPort(TUint aPort)
93 i[0] = (TUint8)(aPort >> 8);
96 inline void SetDstPort(TUint aPort)
98 i[2] = (TUint8)(aPort >> 8);
101 inline void SetLength(TInt aLength)
103 i[4] = (TUint8)(aLength / 256);
104 i[5] = (TUint8) aLength;
106 inline void SetChecksum(TInt aSum)
108 // Checksum is used in network byte order
109 *((TUint16 *)&i[6]) = (TUint16)aSum;