]>
Commit | Line | Data |
---|---|---|
45a07212 | 1 | /* |
73470cfe | 2 | * Copyright (C) 2012 Tobias Brunner |
c71d53ba MW |
3 | * Copyright (C) 2005-2006 Martin Willi |
4 | * Copyright (C) 2005 Jan Hutter | |
45a07212 MW |
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. | |
552cc11b MW |
16 | */ |
17 | ||
18 | /** | |
19 | * @defgroup packet packet | |
5764a9b3 | 20 | * @{ @ingroup utils |
45a07212 | 21 | */ |
382b4817 | 22 | |
45a07212 MW |
23 | #ifndef PACKET_H_ |
24 | #define PACKET_H_ | |
25 | ||
382b4817 | 26 | typedef struct packet_t packet_t; |
45a07212 | 27 | |
db7ef624 | 28 | #include <library.h> |
2e7cc07e | 29 | #include <networking/host.h> |
45a07212 | 30 | |
45a07212 | 31 | /** |
5764a9b3 | 32 | * Abstraction of an IP/UDP-Packet, contains data, sender and receiver. |
45a07212 | 33 | */ |
95c61cb9 | 34 | struct packet_t { |
90c50445 | 35 | |
9317c2a1 | 36 | /** |
552cc11b | 37 | * Set the source address. |
7daf5226 | 38 | * |
5764a9b3 | 39 | * @param source address to set as source (gets owned) |
9317c2a1 | 40 | */ |
5764a9b3 | 41 | void (*set_source)(packet_t *packet, host_t *source); |
7daf5226 | 42 | |
45a07212 | 43 | /** |
552cc11b | 44 | * Set the destination address. |
7daf5226 | 45 | * |
5764a9b3 | 46 | * @param source address to set as destination (gets owned) |
45a07212 | 47 | */ |
5764a9b3 | 48 | void (*set_destination)(packet_t *packet, host_t *destination); |
7daf5226 | 49 | |
3818e5c8 | 50 | /** |
552cc11b | 51 | * Get the source address. |
7daf5226 | 52 | * |
5764a9b3 | 53 | * @return source address (internal data) |
2b547481 | 54 | */ |
5764a9b3 | 55 | host_t *(*get_source)(packet_t *packet); |
7daf5226 | 56 | |
2b547481 | 57 | /** |
552cc11b | 58 | * Get the destination address. |
7daf5226 | 59 | * |
5764a9b3 | 60 | * @return destination address (internal data) |
2b547481 | 61 | */ |
5764a9b3 | 62 | host_t *(*get_destination)(packet_t *packet); |
7daf5226 | 63 | |
2b547481 | 64 | /** |
552cc11b | 65 | * Get the data from the packet. |
7daf5226 | 66 | * |
5764a9b3 | 67 | * @return chunk containing the data (internal data) |
2b547481 | 68 | */ |
5764a9b3 | 69 | chunk_t (*get_data)(packet_t *packet); |
7daf5226 | 70 | |
2b547481 | 71 | /** |
552cc11b | 72 | * Set the data in the packet. |
7daf5226 | 73 | * |
5764a9b3 | 74 | * @param data chunk with data to set (gets owned) |
2b547481 | 75 | */ |
5764a9b3 | 76 | void (*set_data)(packet_t *packet, chunk_t data); |
7daf5226 | 77 | |
73470cfe TB |
78 | /** |
79 | * Increase the offset where the actual packet data starts. | |
80 | * | |
5764a9b3 TB |
81 | * The total offset applies to future calls of get_data() and clone(). |
82 | * | |
73470cfe TB |
83 | * @note The offset is reset to 0 when set_data() is called. |
84 | * | |
85 | * @param bytes the number of additional bytes to skip | |
86 | */ | |
5764a9b3 | 87 | void (*skip_bytes)(packet_t *packet, size_t bytes); |
73470cfe | 88 | |
2b547481 | 89 | /** |
552cc11b | 90 | * Clones a packet_t object. |
7daf5226 | 91 | * |
5764a9b3 TB |
92 | * @note Data is cloned without skipped bytes. |
93 | * | |
552cc11b | 94 | * @param clone clone of the packet |
3818e5c8 | 95 | */ |
5764a9b3 | 96 | packet_t* (*clone)(packet_t *packet); |
7daf5226 | 97 | |
45a07212 | 98 | /** |
552cc11b | 99 | * Destroy the packet, freeing contained data. |
45a07212 | 100 | */ |
5764a9b3 | 101 | void (*destroy)(packet_t *packet); |
45a07212 MW |
102 | }; |
103 | ||
104 | /** | |
5764a9b3 | 105 | * Create an empty packet |
7daf5226 | 106 | * |
2b547481 | 107 | * @return packet_t object |
45a07212 | 108 | */ |
5764a9b3 | 109 | packet_t *packet_create(); |
45a07212 | 110 | |
ec486e94 TB |
111 | /** |
112 | * Create a packet from the supplied data | |
113 | * | |
114 | * @param src source address (gets owned) | |
115 | * @param dst destination address (gets owned) | |
116 | * @param data packet data (gets owned) | |
117 | * @return packet_t object | |
118 | */ | |
119 | packet_t *packet_create_from_data(host_t *src, host_t *dst, chunk_t data); | |
120 | ||
1490ff4d | 121 | #endif /** PACKET_H_ @}*/ |