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