078a42477f0177a56d0b8f24d22b495cdd244f65
[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     // See RFC768
38     template <class Iterator=nil, class IPacket=nil>
39     struct Parse_UDP : public ParserBase<Iterator,IPacket>
40     {
41         template <class I, class P=nil>
42         struct rebind { typedef Parse_UDP<I,P> parser; };
43         typedef Iterator byte_iterator;
44
45         Parse_UDP() {}
46         Parse_UDP(Iterator const & i) : ParserBase<Iterator,IPacket>(i) {}
47
48         static unsigned bytes() { return 8; }
49
50         ///////////////////////////////////////////////////////////////////////////
51
52         typedef Parse_UInt16 < Iterator > Parse_16bit;  
53         
54         Parse_16bit source()          const { return Parse_16bit      (this->i()     ); }
55         Parse_16bit destination()     const { return Parse_16bit      (this->i() + 2 ); }
56         Parse_16bit length()          const { return Parse_16bit      (this->i() + 4 ); }
57         Parse_16bit crc()             const { return Parse_16bit      (this->i() + 6 ); }
58
59     };
60
61     class UDPPacket
62         : public Packet, 
63           public Parse_UDP<Packet::iterator, UDPPacket>
64     {
65     public:
66         ///////////////////////////////////////////////////////////////////////////
67         // Types
68
69         typedef ptr_t<UDPPacket>::ptr ptr;
70
71         ///////////////////////////////////////////////////////////////////////////
72
73     private:
74         template <class Arg>
75         UDPPacket(Arg const & arg);
76
77         virtual void v_nextInterpreter() const;
78         virtual void v_finalize();
79         virtual void v_dump(std::ostream & os) const;
80
81         friend class Packet;
82     };
83 }
84
85
86 ///////////////////////////////hh.e////////////////////////////////////////
87 //#include UDPPacket.cci"
88 //#include "UDPPacket.ct"
89 #include "UDPPacket.cti"
90 #endif
91
92 \f
93 // Local Variables:
94 // mode: c++
95 // c-file-style: "senf"
96 // End: