Fix parsing of IPv6 headers in ip_packet_t
[strongswan.git] / src / libipsec / ip_packet.h
1 /*
2 * Copyright (C) 2012 Tobias Brunner
3 * Hochschule fuer Technik Rapperswil
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * for more details.
14 */
15
16 /**
17 * @defgroup ip_packet ip_packet
18 * @{ @ingroup libipsec
19 */
20
21 #ifndef IP_PACKET_H_
22 #define IP_PACKET_H_
23
24 #include <library.h>
25 #include <utils/host.h>
26 #include <utils/packet.h>
27
28 typedef struct ip_packet_t ip_packet_t;
29
30 /**
31 * IP packet
32 */
33 struct ip_packet_t {
34
35 /**
36 * IP version of this packet
37 *
38 * @return ip version
39 */
40 u_int8_t (*get_version)(ip_packet_t *this);
41
42 /**
43 * Get the source address of this packet
44 *
45 * @return source host
46 */
47 host_t *(*get_source)(ip_packet_t *this);
48
49 /**
50 * Get the destination address of this packet
51 *
52 * @return destination host
53 */
54 host_t *(*get_destination)(ip_packet_t *this);
55
56 /**
57 * Get the protocol (IPv4) or next header (IPv6) field of this packet.
58 *
59 * @return protocol|next header field
60 */
61 u_int8_t (*get_next_header)(ip_packet_t *this);
62
63 /**
64 * Get the complete IP packet (including the header)
65 *
66 * @return IP packet (internal data)
67 */
68 chunk_t (*get_encoding)(ip_packet_t *this);
69
70 /**
71 * Clone the IP packet
72 *
73 * @return clone of the packet
74 */
75 ip_packet_t *(*clone)(ip_packet_t *this);
76
77 /**
78 * Destroy an ip_packet_t
79 */
80 void (*destroy)(ip_packet_t *this);
81
82 };
83
84 /**
85 * Create an IP packet out of data from the wire (or decapsulated from another
86 * packet).
87 *
88 * @note The raw IP packet gets either owned by the new object, or destroyed,
89 * if the data is invalid.
90 *
91 * @param packet the IP packet (including header), gets owned
92 * @return ip_packet_t instance, or NULL if invalid
93 */
94 ip_packet_t *ip_packet_create(chunk_t packet);
95
96 #endif /** IP_PACKET_H_ @}*/