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.
34int main(
int argc,
char** argv)
37 SetConsoleTitleA(
"bRAWcap Example - Simple Packet Receiver");
41 unsigned char demoModeLogged = 0;
42 unsigned long long packetCounter = 0;
65 printf(
"[WARNING] No bRAWcap adapter available... Will stop now.");
75 printf(
"[ERROR] Unexpected status while retrieving adapter name: %d",
brawcap_last_status());
102 UINT64 timestamp_sec = 0;
103 UINT32 timestamp_ns = 0;
104 const char* pPayload = 0;
119 printf(
"[NOTICE] DEMO MODE: Limitation period elapsed, receiving is available again.\n");
132 printf(
"%llu. Packet:\n", ++packetCounter);
133 printf(
" - Capture Length: %04u Bytes\n", captureLength);
134 printf(
" - Length On Wire: %04u Bytes\n", lengthOnWire);
135 printf(
" - Timestamp: %llu %09u ns\n", timestamp_sec, timestamp_ns);
136 printf(
" - Payload: ");
138 UINT32 byteCounter = 1;
139 for (
const char* pByte = pPayload; byteCounter <= captureLength; ++byteCounter)
141 printf(
"%02X ", (
unsigned char)*pByte++);
142 if (!(byteCounter % 16)) printf(
"\n ");
143 else if(!(byteCounter % 8)) printf(
" ");
159 printf(
"[WARNING] DEMO MODE: Receiving not available.\n");
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_INFO_NO_DATA
Indicates that a function returns without any data.
Definition: brawcap_types_shared.h:333
@ BRAWCAP_STATUS_WARNING_DEMO_MODE
The operation was not executed due to demo mode limitations.
Definition: brawcap_types_shared.h:256
struct _brawcap_timestamp brawcap_timestamp_t
bRAWcap timestamp object.
Definition: brawcap_types_shared.h:612
brawcap_status_t brawcap_timestamp_value_ns_get(brawcap_timestamp_t *const pTimestamp, UINT64 *const pSeconds, UINT32 *const pNanoseconds)
Reads out the timestamp value in seconds and nanoseconds.
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_create(brawcap_packet_t **const pPacket, const brawcap_packet_size_t maxSize)
Creates a new packet.
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
brawcap_status_t brawcap_packet_payload_get(brawcap_packet_t *const pPacket, const char **const pPayload, brawcap_packet_size_t *const pLength)
Reads out the payload of the specified packet.
brawcap_status_t brawcap_packet_length_on_wire_get(brawcap_packet_t *const pPacket, brawcap_packet_size_t *const pLengthOnWire)
Reads out the length on wire of the specified packet. This value is especially useful for received pa...
brawcap_status_t brawcap_packet_timestamp_get(brawcap_packet_t *const pPacket, brawcap_timestamp_t **const pTimestamp)
Reads out the timestamp object for the specified packet.
brawcap_status_t brawcap_packet_free(brawcap_packet_t *pPacket)
Frees the specified packet. When this function is called the specified packet becomes invalid and it´...
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_packet(brawcap_handle_t *const pHandle, brawcap_packet_t *const pPacket)
Receives a single packet from the specified handle.