void test_pcap(void) { rdpPcap* pcap; pcap_record record; test_packet packets[3]; packets[0].data = test_packet_1; packets[0].length = sizeof(test_packet_1); packets[1].data = test_packet_2; packets[1].length = sizeof(test_packet_2); packets[2].data = test_packet_3; packets[2].length = sizeof(test_packet_3); pcap = pcap_open("/tmp/test.pcap", true); pcap_add_record(pcap, test_packet_1, sizeof(test_packet_1)); pcap_flush(pcap); pcap_add_record(pcap, test_packet_2, sizeof(test_packet_2)); pcap_flush(pcap); pcap_add_record(pcap, test_packet_3, sizeof(test_packet_3)); pcap_close(pcap); pcap = pcap_open("/tmp/test.pcap", false); int i = 0; while (pcap_has_next_record(pcap)) { pcap_get_next_record(pcap, &record); CU_ASSERT(record.length == packets[i].length) i++; } CU_ASSERT(i == 3); pcap_close(pcap); }
void pcap_close(rdpPcap* pcap) { pcap_flush(pcap); if (pcap->fp != NULL) fclose(pcap->fp); }
int update_recv_surfcmds(rdpUpdate* update, UINT32 size, wStream* s) { BYTE* mark; UINT16 cmdType; UINT32 cmdLength = 0; while (size > 2) { Stream_GetPointer(s, mark); Stream_Read_UINT16(s, cmdType); size -= 2; switch (cmdType) { case CMDTYPE_SET_SURFACE_BITS: case CMDTYPE_STREAM_SURFACE_BITS: if (update_recv_surfcmd_surface_bits(update, s, &cmdLength) < 0) return -1; break; case CMDTYPE_FRAME_MARKER: if (update_recv_surfcmd_frame_marker(update, s, &cmdLength) < 0) return -1; break; default: WLog_ERR(TAG, "unknown cmdType 0x%X", cmdType); return -1; } size -= cmdLength; if (update->dump_rfx) { /* TODO: treat return values */ pcap_add_record(update->pcap_rfx, mark, cmdLength + 2); pcap_flush(update->pcap_rfx); } } return 0; }
int update_recv_surfcmds(rdpUpdate* update, UINT32 size, STREAM* s) { BYTE* mark; UINT16 cmdType; UINT32 cmdLength; while (size > 2) { stream_get_mark(s, mark); stream_read_UINT16(s, cmdType); size -= 2; switch (cmdType) { case CMDTYPE_SET_SURFACE_BITS: case CMDTYPE_STREAM_SURFACE_BITS: if (!update_recv_surfcmd_surface_bits(update, s, &cmdLength)) return -1; break; case CMDTYPE_FRAME_MARKER: if (!update_recv_surfcmd_frame_marker(update, s, &cmdLength)) return -1; break; default: DEBUG_WARN("unknown cmdType 0x%X", cmdType); return -1; } size -= cmdLength; if (update->dump_rfx) { pcap_add_record(update->pcap_rfx, mark, cmdLength + 2); pcap_flush(update->pcap_rfx); } } return 0; }
boolean update_recv_surfcmds(rdpUpdate* update, uint32 size, STREAM* s) { uint8* mark; uint16 cmdType; uint32 cmdLength; while (size > 2) { stream_get_mark(s, mark); stream_read_uint16(s, cmdType); size -= 2; switch (cmdType) { case CMDTYPE_SET_SURFACE_BITS: case CMDTYPE_STREAM_SURFACE_BITS: cmdLength = update_recv_surfcmd_surface_bits(update, s); break; case CMDTYPE_FRAME_MARKER: cmdLength = update_recv_surfcmd_frame_marker(update, s); break; default: DEBUG_WARN("unknown cmdType 0x%X", cmdType); return false; } size -= cmdLength; if (update->dump_rfx) { pcap_add_record(update->pcap_rfx, mark, cmdLength + 2); pcap_flush(update->pcap_rfx); } } return true; }