|
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". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // udp_hdr.h - UDP header structure |
|
15 // Defines the basic classes for accessing the header |
|
16 // structures within UDP packets. |
|
17 // |
|
18 |
|
19 |
|
20 |
|
21 /** |
|
22 @file udp_hdr.h |
|
23 @ingroup ip_packet_formats |
|
24 @publishedAll |
|
25 @released |
|
26 */ |
|
27 |
|
28 #ifndef __UDP_HDR_H__ |
|
29 #define __UDP_HDR_H__ |
|
30 |
|
31 #include <e32def.h> |
|
32 #include "in_hdr.h" |
|
33 |
|
34 /** |
|
35 * @addtogroup ip_packet_formats |
|
36 * @{ |
|
37 */ |
|
38 |
|
39 // TInet6HeaderUPD |
|
40 |
|
41 class TInet6HeaderUDP |
|
42 /** UDP Header format. |
|
43 * User Datagram Header Format |
|
44 * @verbatim |
|
45 Extract from RFC-768 |
|
46 |
|
47 0 7 8 15 16 23 24 31 |
|
48 +--------+--------+--------+--------+ |
|
49 | Source | Destination | |
|
50 | Port | Port | |
|
51 +--------+--------+--------+--------+ |
|
52 | | | |
|
53 | Length | Checksum | |
|
54 +--------+--------+--------+--------+ |
|
55 | |
|
56 | data octets ... |
|
57 +---------------- ... |
|
58 @endverbatim |
|
59 * @publishedAll |
|
60 * @released |
|
61 */ |
|
62 { |
|
63 public: |
|
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();} |
|
68 // |
|
69 // Access, Get UDP field values from the packet |
|
70 // |
|
71 inline TUint SrcPort() const |
|
72 { |
|
73 return (i[0] << 8) + i[1]; |
|
74 } |
|
75 inline TUint DstPort() const |
|
76 { |
|
77 return (i[2] << 8) + i[3]; |
|
78 } |
|
79 inline TInt Length() const |
|
80 { |
|
81 return (i[4] << 8) + i[5]; |
|
82 } |
|
83 inline TInt Checksum() const |
|
84 { |
|
85 // Checksum is used in network byte order |
|
86 return *((TUint16 *)&i[6]); |
|
87 } |
|
88 // |
|
89 // Build, Set UDP field value to the packet |
|
90 // |
|
91 inline void SetSrcPort(TUint aPort) |
|
92 { |
|
93 i[0] = (TUint8)(aPort >> 8); |
|
94 i[1] = (TUint8)aPort; |
|
95 } |
|
96 inline void SetDstPort(TUint aPort) |
|
97 { |
|
98 i[2] = (TUint8)(aPort >> 8); |
|
99 i[3] = (TUint8)aPort; |
|
100 } |
|
101 inline void SetLength(TInt aLength) |
|
102 { |
|
103 i[4] = (TUint8)(aLength / 256); |
|
104 i[5] = (TUint8) aLength; |
|
105 } |
|
106 inline void SetChecksum(TInt aSum) |
|
107 { |
|
108 // Checksum is used in network byte order |
|
109 *((TUint16 *)&i[6]) = (TUint16)aSum; |
|
110 } |
|
111 private: |
|
112 TUint8 i[8]; |
|
113 }; |
|
114 /** @} */ |
|
115 #endif |