pcap.h (2571B)
1/** 2 * FreeRDP: A Remote Desktop Protocol Implementation 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 FREERDP_UTILS_PCAP_H 21#define FREERDP_UTILS_PCAP_H 22 23#include <freerdp/api.h> 24#include <freerdp/types.h> 25 26struct _pcap_header 27{ 28 UINT32 magic_number; /* magic number */ 29 UINT16 version_major; /* major version number */ 30 UINT16 version_minor; /* minor version number */ 31 INT32 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}; 36typedef struct _pcap_header pcap_header; 37 38struct _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}; 45typedef struct _pcap_record_header pcap_record_header; 46 47typedef struct _pcap_record pcap_record; 48 49struct _pcap_record 50{ 51 pcap_record_header header; 52 union 53 { 54 void* data; 55 const void* cdata; 56 }; 57 UINT32 length; 58 pcap_record* next; 59}; 60 61struct rdp_pcap 62{ 63 FILE* fp; 64 char* name; 65 BOOL write; 66 INT64 file_size; 67 int record_count; 68 pcap_header header; 69 pcap_record* head; 70 pcap_record* tail; 71 pcap_record* record; 72}; 73typedef struct rdp_pcap rdpPcap; 74 75#ifdef __cplusplus 76extern "C" 77{ 78#endif 79 80 FREERDP_API rdpPcap* pcap_open(char* name, BOOL write); 81 FREERDP_API void pcap_close(rdpPcap* pcap); 82 83 FREERDP_API BOOL pcap_add_record(rdpPcap* pcap, const void* data, UINT32 length); 84 FREERDP_API BOOL pcap_has_next_record(rdpPcap* pcap); 85 FREERDP_API BOOL pcap_get_next_record(rdpPcap* pcap, pcap_record* record); 86 FREERDP_API BOOL pcap_get_next_record_header(rdpPcap* pcap, pcap_record* record); 87 FREERDP_API BOOL pcap_get_next_record_content(rdpPcap* pcap, pcap_record* record); 88 FREERDP_API void pcap_flush(rdpPcap* pcap); 89 90#ifdef __cplusplus 91} 92#endif 93 94#endif /* FREERDP_UTILS_PCAP_H */