better split up of library files "types.h" & "definitions.h"
[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 typedef struct packet_t packet_t;
28
29 #include <library.h>
30 #include <utils/host.h>
31
32 /**
33 * @brief Abstraction of an UDP-Packet, contains data, sender and receiver.
34 *
35 * @b Constructors:
36 * - packet_create()
37 *
38 * @ingroup network
39 */
40 struct packet_t {
41
42 /**
43 * @brief Set the source address.
44 *
45 * Set host_t is now owned by packet_t, it will destroy
46 * it if necessary.
47 *
48 * @param this calling object
49 * @param source address to set as source
50 */
51 void (*set_source) (packet_t *packet, host_t *source);
52
53 /**
54 * @brief Set the destination address.
55 *
56 * Set host_t is now owned by packet_t, it will destroy
57 * it if necessary.
58 *
59 * @param this calling object
60 * @param source address to set as destination
61 */
62 void (*set_destination) (packet_t *packet, host_t *destination);
63
64 /**
65 * @brief Get the source address.
66 *
67 * Set host_t is still owned by packet_t, clone it
68 * if needed.
69 *
70 * @param this calling object
71 * @return source address
72 */
73 host_t *(*get_source) (packet_t *packet);
74
75 /**
76 * @brief Get the destination address.
77 *
78 * Set host_t is still owned by packet_t, clone it
79 * if needed.
80 *
81 * @param this calling object
82 * @return destination address
83 */
84 host_t *(*get_destination) (packet_t *packet);
85
86 /**
87 * @brief Get the data from the packet.
88 *
89 * The data pointed by the chunk is still owned
90 * by the packet. Clone it if needed.
91 *
92 * @param this calling object
93 * @return chunk containing the data
94 */
95 chunk_t (*get_data) (packet_t *packet);
96
97 /**
98 * @brief Set the data in the packet.
99 *
100 * Supplied chunk data is now owned by the
101 * packet. It will free it.
102 *
103 * @param this calling object
104 * @param data chunk with data to set
105 */
106 void (*set_data) (packet_t *packet, chunk_t data);
107
108 /**
109 * @brief Clones a packet_t object.
110 *
111 * @param packet calling object
112 * @param clone pointer to a packet_t object pointer where the new object is stored
113 */
114 packet_t* (*clone) (packet_t *packet);
115
116 /**
117 * @brief Destroy the packet, freeing contained data.
118 *
119 * @param packet packet to destroy
120 */
121 void (*destroy) (packet_t *packet);
122 };
123
124 /**
125 * @brief create an empty packet
126 *
127 * @return packet_t object
128 *
129 * @ingroup network
130 */
131 packet_t *packet_create(void);
132
133
134 #endif /*PACKET_H_*/