Initial commit - from Precise source
[freerdp-ubuntu-pcb-backport.git] / include / freerdp / utils / pcap.h
1 /**
2  * FreeRDP: A Remote Desktop Protocol Client
3  * pcap File Format Utils
4  *
5  * Copyright 2011 Marc-Andre Moreau <marcandre.moreau@gmail.com>
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *     http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19
20 #ifndef __UTILS_PCAP_H
21 #define __UTILS_PCAP_H
22
23 #include <freerdp/api.h>
24 #include <freerdp/types.h>
25
26 struct _pcap_header
27 {
28         uint32 magic_number;   /* magic number */
29         uint16 version_major;  /* major version number */
30         uint16 version_minor;  /* minor version number */
31         sint32 thiszone;       /* GMT to local correction */
32         uint32 sigfigs;        /* accuracy of timestamps */
33         uint32 snaplen;        /* max length of captured packets, in octets */
34         uint32 network;        /* data link type */
35 };
36 typedef struct _pcap_header pcap_header;
37
38 struct _pcap_record_header
39 {
40         uint32 ts_sec;         /* timestamp seconds */
41         uint32 ts_usec;        /* timestamp microseconds */
42         uint32 incl_len;       /* number of octets of packet saved in file */
43         uint32 orig_len;       /* actual length of packet */
44 };
45 typedef struct _pcap_record_header pcap_record_header;
46
47 typedef struct _pcap_record pcap_record;
48
49 struct _pcap_record
50 {
51         pcap_record_header header;
52         void* data;
53         uint32 length;
54         pcap_record* next;
55 };
56
57 struct rdp_pcap
58 {
59         FILE* fp;
60         char* name;
61         boolean write;
62         int file_size;
63         int record_count;
64         pcap_header header;
65         pcap_record* head;
66         pcap_record* tail;
67         pcap_record* record;
68 };
69 typedef struct rdp_pcap rdpPcap;
70
71 FREERDP_API rdpPcap* pcap_open(char* name, boolean write);
72 FREERDP_API void pcap_close(rdpPcap* pcap);
73
74 FREERDP_API void pcap_add_record(rdpPcap* pcap, void* data, uint32 length);
75 FREERDP_API boolean pcap_has_next_record(rdpPcap* pcap);
76 FREERDP_API boolean pcap_get_next_record(rdpPcap* pcap, pcap_record* record);
77 FREERDP_API boolean pcap_get_next_record_header(rdpPcap* pcap, pcap_record* record);
78 FREERDP_API boolean pcap_get_next_record_content(rdpPcap* pcap, pcap_record* record);
79 FREERDP_API void pcap_flush(rdpPcap* pcap);
80
81 #endif /* __UTILS_PCAP_H */