Imported Upstream version 0.3
[anytun.git] / src / plainPacket.h
1 /*
2  *  anytun
3  *
4  *  The secure anycast tunneling protocol (satp) defines a protocol used
5  *  for communication between any combination of unicast and anycast
6  *  tunnel endpoints.  It has less protocol overhead than IPSec in Tunnel
7  *  mode and allows tunneling of every ETHER TYPE protocol (e.g.
8  *  ethernet, ip, arp ...). satp directly includes cryptography and
9  *  message authentication based on the methodes used by SRTP.  It is
10  *  intended to deliver a generic, scaleable and secure solution for
11  *  tunneling and relaying of packets of any protocol.
12  *
13  *
14  *  Copyright (C) 2007-2008 Othmar Gsenger, Erwin Nindl, 
15  *                          Christian Pointner <satp@wirdorange.org>
16  *
17  *  This file is part of Anytun.
18  *
19  *  Anytun is free software: you can redistribute it and/or modify
20  *  it under the terms of the GNU General Public License version 3 as
21  *  published by the Free Software Foundation.
22  *
23  *  Anytun is distributed in the hope that it will be useful,
24  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
25  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
26  *  GNU General Public License for more details.
27  *
28  *  You should have received a copy of the GNU General Public License
29  *  along with anytun.  If not, see <http://www.gnu.org/licenses/>.
30  */
31
32 #ifndef _PLAIN_PACKET_H_
33 #define _PLAIN_PACKET_H_
34
35 #include "datatypes.h"
36 #include "buffer.h"
37
38 #include "networkAddress.h"
39
40 class Cipher;
41 /**
42  * plain SATP packet class<br>
43  * includes payload_type and payload
44  */
45
46 #define PAYLOAD_TYPE_TAP 0x6558
47 #define PAYLOAD_TYPE_TUN 0x0000
48 #define PAYLOAD_TYPE_TUN4 0x0800
49 #define PAYLOAD_TYPE_TUN6 0x86DD 
50
51 class PlainPacket : public Buffer
52 {
53 public:
54   /**
55    * Packet constructor
56    * @param the length of the payload 
57    * @param allow reallocation of buffer
58    */
59   PlainPacket(u_int32_t payload_length, bool allow_realloc = false);
60
61   /**
62    * Packet destructor
63    */
64   ~PlainPacket() {};
65
66   /**
67    * Get the length of the header
68    * @return the length of the header
69    */
70   static u_int32_t getHeaderLength();
71
72   /**
73    * Get the payload type
74    * @return the id of the payload type 
75    */
76   payload_type_t getPayloadType() const;
77
78   /**
79    * Set the payload type
80    * @param payload_type payload type id
81    */
82   void setPayloadType(payload_type_t payload_type);
83
84   /**
85    * Get the length of the payload
86    * @return the length of the payload
87    */
88   u_int32_t getPayloadLength() const;
89
90   /**
91    * Set the length of the payload
92    * @param length length of the payload
93    */
94   void setPayloadLength(u_int32_t payload_length);
95
96   /**
97    * Get the the payload
98    * @return the Pointer to the payload
99    */
100   u_int8_t* getPayload();
101
102 //  NetworkAddress getSrcAddr() const;
103   NetworkAddress getDstAddr() const;
104
105 private:
106   PlainPacket();
107   PlainPacket(const PlainPacket &src);
108
109   void reinit();
110
111   payload_type_t* payload_type_;
112   u_int8_t* payload_;
113 };
114
115 #endif