updated copyright information
[strongswan.git] / src / charon / network / packet.h
1 /**
2 * @file packet.h
3 *
4 * @brief Interface of packet_t.
5 *
6 */
7
8 /*
9 * Copyright (C) 2005-2006 Martin Willi
10 * Copyright (C) 2005 Jan Hutter
11 * Hochschule fuer Technik Rapperswil
12 *
13 * This program is free software; you can redistribute it and/or modify it
14 * under the terms of the GNU General Public License as published by the
15 * Free Software Foundation; either version 2 of the License, or (at your
16 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
17 *
18 * This program is distributed in the hope that it will be useful, but
19 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
20 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 * for more details.
22 */
23
24 #ifndef PACKET_H_
25 #define PACKET_H_
26
27
28 #include <types.h>
29 #include <utils/host.h>
30
31
32 typedef struct packet_t packet_t;
33
34 /**
35 * @brief Abstraction of an UDP-Packet, contains data, sender and receiver.
36 *
37 * @b Constructors:
38 * - packet_create()
39 *
40 * @ingroup network
41 */
42 struct packet_t {
43
44 /**
45 * @brief Set the source address.
46 *
47 * Set host_t is now owned by packet_t, it will destroy
48 * it if necessary.
49 *
50 * @param this calling object
51 * @param source address to set as source
52 */
53 void (*set_source) (packet_t *packet, host_t *source);
54
55 /**
56 * @brief Set the destination address.
57 *
58 * Set host_t is now owned by packet_t, it will destroy
59 * it if necessary.
60 *
61 * @param this calling object
62 * @param source address to set as destination
63 */
64 void (*set_destination) (packet_t *packet, host_t *destination);
65
66 /**
67 * @brief Get the source address.
68 *
69 * Set host_t is still owned by packet_t, clone it
70 * if needed.
71 *
72 * @param this calling object
73 * @return source address
74 */
75 host_t *(*get_source) (packet_t *packet);
76
77 /**
78 * @brief Get the destination address.
79 *
80 * Set host_t is still owned by packet_t, clone it
81 * if needed.
82 *
83 * @param this calling object
84 * @return destination address
85 */
86 host_t *(*get_destination) (packet_t *packet);
87
88 /**
89 * @brief Get the data from the packet.
90 *
91 * The data pointed by the chunk is still owned
92 * by the packet. Clone it if needed.
93 *
94 * @param this calling object
95 * @return chunk containing the data
96 */
97 chunk_t (*get_data) (packet_t *packet);
98
99 /**
100 * @brief Set the data in the packet.
101 *
102 * Supplied chunk data is now owned by the
103 * packet. It will free it.
104 *
105 * @param this calling object
106 * @param data chunk with data to set
107 */
108 void (*set_data) (packet_t *packet, chunk_t data);
109
110 /**
111 * @brief Clones a packet_t object.
112 *
113 * @param packet calling object
114 * @param clone pointer to a packet_t object pointer where the new object is stored
115 */
116 packet_t* (*clone) (packet_t *packet);
117
118 /**
119 * @brief Destroy the packet, freeing contained data.
120 *
121 * @param packet packet to destroy
122 */
123 void (*destroy) (packet_t *packet);
124 };
125
126 /**
127 * @brief create an empty packet
128 *
129 * @return packet_t object
130 *
131 * @ingroup network
132 */
133 packet_t *packet_create(void);
134
135
136 #endif /*PACKET_H_*/