Implemented IpV6Packet and added raw-data constructor to INet6Address
[senf.git] / Packets / UDPPacket.hh
1 // $Id$
2 //
3 // Copyright (C) 2006 
4 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
5 // Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
6 //     Stefan Bund <stefan.bund@fokus.fraunhofer.de>
7 //
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
12 //
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 // GNU General Public License for more details.
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the
20 // Free Software Foundation, Inc.,
21 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22
23 #ifndef HH_UDPPacket_
24 #define HH_UDPPacket_ 1
25
26 // Custom includes
27 #include "Packet.hh"
28 #include "ParseInt.hh"
29 #include "ParseArray.hh"
30 #include "PacketRegistry.hh"
31
32 //#include "UDPPacket.mpp"
33 ///////////////////////////////hh.p////////////////////////////////////////
34
35 namespace senf {
36     
37     template <class Iterator=nil, class IPacket=nil>
38     struct Parse_UDP : public ParserBase<Iterator,IPacket>
39     {
40         template <class I, class P=nil>
41         struct rebind { typedef Parse_UDP<I,P> parser; };
42         typedef Iterator byte_iterator;
43
44         Parse_UDP() {}
45         Parse_UDP(Iterator const & i) : ParserBase<Iterator,IPacket>(i) {}
46
47         static unsigned bytes() { return 8; }
48
49         ///////////////////////////////////////////////////////////////////////////
50
51         typedef Parse_UInt16 < Iterator > Parse_16bit;  
52         
53         Parse_16bit source()          const { return Parse_16bit      (this->i()     ); }
54         Parse_16bit destination()     const { return Parse_16bit      (this->i() + 2 ); }
55         Parse_16bit length()          const { return Parse_16bit      (this->i() + 4 ); }
56         Parse_16bit crc()             const { return Parse_16bit      (this->i() + 6 ); }
57
58     };
59
60     class UDPPacket
61         : public Packet, 
62           public Parse_UDP<Packet::iterator, UDPPacket>
63     {
64     public:
65         ///////////////////////////////////////////////////////////////////////////
66         // Types
67
68         typedef ptr_t<UDPPacket>::ptr ptr;
69
70         ///////////////////////////////////////////////////////////////////////////
71
72     private:
73         template <class Arg>
74         UDPPacket(Arg const & arg);
75
76         virtual void v_nextInterpreter() const;
77         virtual void v_finalize();
78         virtual void v_dump(std::ostream & os) const;
79
80         friend class Packet;
81     };
82 }
83
84
85 ///////////////////////////////hh.e////////////////////////////////////////
86 //#include UDPPacket.cci"
87 //#include "UDPPacket.ct"
88 #include "UDPPacket.cti"
89 #endif
90
91 \f
92 // Local Variables:
93 // mode: c++
94 // c-file-style: "senf"
95 // End: