This example shows how to use the bRAWcap single packet receive feature. It opens a handle to the first available bRAWcap adapter, creates a bRAWcap packet to store received data to. For each received packet it will print the packet information to console.
37typedef struct receive_counters
39 unsigned long long packets;
40 unsigned long long bytes;
43typedef struct example_context
45 unsigned char demoLogged;
46 receive_counters_t counters;
51void ParseArgs(
int argc,
char** argv,
int* exec_time)
55 if(!memcmp(argv[1],
"-t", 2))
58 *exec_time = strtol(argv[2], &pEnd,0);
66 example_context_t* pContext = (example_context_t*) pUser;
69 if(!pContext->demoLogged)
71 printf(
"[WARNING] DEMO MODE: Receiving not available.\n");
72 pContext->demoLogged = 1;
77 if(pContext->demoLogged)
79 printf(
"[NOTICE] DEMO MODE: Limitation period elapsed, receiving is available again.\n");
80 pContext->demoLogged = 0;
95 pContext->counters.bytes += packetSize;
96 ++pContext->counters.packets;
103 printf(
"[NOTICE] Received new packets [Total Packets: %llu / Total Bytes: %llu].\n",
104 pContext->counters.packets, pContext->counters.bytes);
108int main(
int argc,
char** argv)
111 SetConsoleTitleA(
"bRAWcap Example - Buffered Receiver");
115 ParseArgs(argc, argv, &exec_time);
119 example_context_t context = {0};
143 printf(
"[WARNING] No bRAWcap adapter available... Will stop now.");
153 printf(
"[ERROR] Unexpected status while retrieving adapter name: %d",
brawcap_last_status());
171 printf(
"[ERROR] Unexpected status while creating packet buffer: %d",
brawcap_last_status());
177 printf(
"[ERROR] Unexpected status while creating packet buffer: %d",
brawcap_last_status());
194 }
while (++runtime_sec < exec_time);
struct _brawcap_handle brawcap_handle_t
A bRAWcap handle.
Definition: brawcap_types_um.h:173
brawcap_status_t brawcap_close(brawcap_handle_t *pHandle)
Closes the specified bRAWcap handle.
brawcap_status_t brawcap_open(const brawcap_adapter_name_t name, brawcap_handle_t **const pHandle)
Opens a new bRAWcap handle on the adapter, specified by it´s name.
brawcap_status_t brawcap_last_status()
Reads the last status appeared in bRAWcap, for the calling thread.
brawcap_status_t
bRAWcap status/return codes.
Definition: brawcap_types_shared.h:150
#define BRAWCAP_SUCCESS(status)
Checks if the returned status indicates a success with no additional info.
Definition: brawcap_types_shared.h:122
@ BRAWCAP_STATUS_SUCCESS
Definition: brawcap_types_shared.h:152
@ BRAWCAP_STATUS_WARNING_DEMO_MODE
The operation was not executed due to demo mode limitations.
Definition: brawcap_types_shared.h:256
UINT16 brawcap_packet_size_t
Type for handling the number of payload bytes per packet.
Definition: brawcap_types_shared.h:670
brawcap_status_t brawcap_packet_payload_size_get(brawcap_packet_t *const pPacket, brawcap_packet_size_t *const pLength)
Reads out the captured payload byte size of the specified packet. This indicates the total byte size ...
struct _brawcap_packet brawcap_packet_t
bRAWcap packet object.
Definition: brawcap_types_shared.h:679
#define BRAWCAP_PACKET_SIZE_MAX
The maximum supported (byte) size for a single packet payload.
Definition: brawcap_types_shared.h:649
struct _brawcap_buffer brawcap_buffer_t
bRAWcap packet buffer object.
Definition: brawcap_types_shared.h:742
brawcap_status_t brawcap_buffer_free(brawcap_buffer_t *pBuffer)
Frees the specified packet buffer. When this function is called the specified packet buffer becomes i...
brawcap_status_t brawcap_buffer_create(brawcap_buffer_t **const pBuffer, const brawcap_packet_size_t maxPacketPayloadSize, const brawcap_buffer_packet_count_t numPackets)
Creates a new packet buffer.
brawcap_status_t brawcap_buffer_iterator_free(brawcap_buffer_iterator_t *const pIterator)
Frees the specified iterator. When this function is called the specified iterator becomes invalid and...
struct _brawcap_buffer_iterator brawcap_buffer_iterator_t
bRAWcap packet buffer iterator object.
Definition: brawcap_types_shared.h:770
brawcap_packet_t * brawcap_buffer_iterator_eval(brawcap_buffer_iterator_t *const pIterator)
Returns the buffered packet for the specified iterator.
brawcap_status_t brawcap_buffer_iterator_create(brawcap_buffer_iterator_t **const pIterator, brawcap_buffer_t *const pBuffer, brawcap_buffer_packet_count_t startPosition)
Creates a new iterator for the specified buffer.
brawcap_status_t brawcap_buffer_iterator_next(brawcap_buffer_iterator_t *const pIterator)
Increments the iterator to the next buffered packet.
brawcap_status_t brawcap_adapter_list_at(const brawcap_adapter_count_t index, brawcap_adapter_name_t name)
Reads out the adapter name of the adapter at the adapter list index.
brawcap_status_t brawcap_adapter_list_count(brawcap_adapter_count_t *const pCount)
Reads out the current number of supported adapters in the adapter list.
char brawcap_adapter_name_t[BRAWCAP_ADAPTER_NAME_LENGTH]
Fixed size array containing a adapter name.
Definition: brawcap_types_um.h:257
UINT8 brawcap_adapter_count_t
Type used for counting the available/supported adapters on a machine.
Definition: brawcap_types_um.h:242
brawcap_status_t brawcap_rx_buffer_detach(brawcap_handle_t *const pHandle, brawcap_buffer_t *const pBuffer)
Detaches the specified bRAWcap packet buffer from the specified handle.
brawcap_status_t brawcap_rx_start(brawcap_handle_t *const pHandle, brawcap_rx_callback_t const callback, void *const pUser, const BOOLEAN indicateNoPackets)
Starts the internal receive loop.
brawcap_status_t brawcap_rx_stop(brawcap_handle_t *const pHandle)
Stops the internal receive loop.
brawcap_status_t brawcap_rx_buffer_attach(brawcap_handle_t *const pHandle, brawcap_buffer_t *const pBuffer)
Attaches the specified bRAWcap packet buffer to the specified handle.