This example shows how to register and handle adapter change notifications. It will print each received notification to command line. Each output will also include the change reason and the new adapter property value.
41void ParseArgs(
int argc,
char** argv,
int* exec_time)
45 if(!memcmp(argv[1],
"-t", 2))
48 *exec_time = strtol(argv[2], &pEnd,0);
54 const UINT32 properties,
void* pUser)
61 int* pNotifyCounter = (
int*) pUser;
68 char* friendlyName = 0;
69 UINT32 friendlyNameLength = 0;
72 friendlyName = (
char*) malloc(friendlyNameLength);
76 printf(
"Could not resolve adapter friendly name (unexpected status: %d)\n", status);
82 printf(
"\n%03d. Notification\n", *pNotifyCounter);
89 printf(
"Unknown notification reason.");
94 printf(
"%s (%s) added\n", friendlyName, name);
99 printf(
"%s (%s) removed\n", friendlyName, name);
109 printf(
"%s (%s) new connection state: ", friendlyName, name);
110 switch (connectionState)
120 printf(
"%s new friendly name: %s\n", name, friendlyName);
127 printf(
"%s (%s) new IPv4: %u.%u.%u.%u\n", friendlyName, name,
136 printf(
"%s (%s) new IPv6: %x:%x:%x:%x:%x:%x:%x:%x\n", friendlyName, name,
146 printf(
"%s (%s) new max transmission unit: %llu\n", friendlyName, name, mtu);
154 printf(
"%s (%s) new operation state: ", friendlyName, name);
155 switch (operationState)
169 printf(
"%s (%s) new receive (uplink) speed: %u MBit/s\n", friendlyName, name, speed);
177 printf(
"%s (%s) new transmit (uplink) speed: %u MBit/s\n", friendlyName, name, speed);
188int main(
int argc,
char** argv)
191 SetConsoleTitleA(
"bRAWcap Example - Adapter Change Notifier");
195 ParseArgs(argc, argv, &exec_time);
201 int notifyCounter = 0;
208 printf(
"Registration for adapter change notification failed (Status: %d). Will stop now...", status);
217 }
while (++runtime_sec < exec_time);
225 printf(
"Unregistration for adapter change noTification failed (Status: %d). Will stop now...", status);
brawcap_status_t
bRAWcap status/return codes.
Definition: brawcap_types_shared.h:140
#define BRAWCAP_SUCCESS(status)
Checks if the returned status indicates a success with no additional info.
Definition: brawcap_types_shared.h:112
@ BRAWCAP_STATUS_SUCCESS
Definition: brawcap_types_shared.h:142
@ BRAWCAP_STATUS_ERROR_OVERRUN
A buffer overrun was detected.
Definition: brawcap_types_shared.h:235
IPv4 address.
Definition: brawcap_types_um.h:307
IPv6 address.
Definition: brawcap_types_um.h:317
UINT8 bytes[4]
Definition: brawcap_types_um.h:308
UINT16 words[8]
Definition: brawcap_types_um.h:319
brawcap_status_t brawcap_adapter_notify_unregister()
Unregisters the calling process from receiving adapter change notifications.
brawcap_status_t brawcap_adapter_mtu(const brawcap_adapter_name_t name, brawcap_adapter_mtu_t *const pMtu)
Reads out the configured MTU of the specified adapter.
brawcap_status_t brawcap_adapter_speed_rx(const brawcap_adapter_name_t name, brawcap_adapter_speed_t *const pSpeed)
Reads out the current receive speed of the specified adapter.
brawcap_status_t brawcap_adapter_ipv4(const brawcap_adapter_name_t name, brawcap_adapter_ipv4_t *const pIpv4)
Reads out the currently set IPv4 address of the specified adapter.
brawcap_status_t brawcap_adapter_friendly_name(const brawcap_adapter_name_t name, char *const friendlyName, UINT32 *const pLength)
Reads out the currently set adapter friendly name for the specified adapter.
brawcap_adapter_connection_state_t
List of adapter connection states. Values indicating the current adapter connection state (uplink/cab...
Definition: brawcap_types_um.h:350
char brawcap_adapter_name_t[BRAWCAP_ADAPTER_NAME_LENGTH]
Fixed size array containing a adapter name.
Definition: brawcap_types_um.h:301
brawcap_status_t brawcap_adapter_connection(const brawcap_adapter_name_t name, brawcap_adapter_connection_state_t *const pConnection)
Reads out the current connection state of the specified adapter.
brawcap_status_t brawcap_adapter_ipv6(const brawcap_adapter_name_t name, brawcap_adapter_ipv6_t *const pIpv6)
Reads out the currently set IPv6 address of the specified adapter.
brawcap_adapter_speed_t
List of bRAWcap adapter speeds. Values indicating the current adapter uplink speed.
Definition: brawcap_types_um.h:331
void(* brawcap_adapter_notify_callback_t)(const brawcap_adapter_name_t name, const brawcap_adapter_notify_reason_t reason, const UINT32 properties, void *pUser)
The general callback for adapter change notifications. It will be called each time a available and su...
Definition: brawcap_types_um.h:441
brawcap_adapter_operation_state_t
List of adapter operation states. Values indicating the current adapter operation state (adapter driv...
Definition: brawcap_types_um.h:361
brawcap_status_t brawcap_adapter_notify_register(brawcap_adapter_notify_callback_t const callback, void *const pUser)
Registers the calling process for receiving adapter change notifications.
brawcap_status_t brawcap_adapter_speed_tx(const brawcap_adapter_name_t name, brawcap_adapter_speed_t *const pSpeed)
Reads out the current transmit speed of the specified adapter.
brawcap_adapter_notify_reason_t
List of reasons for adapter change notifications. This values indicate why a adapter change notificat...
Definition: brawcap_types_um.h:388
UINT64 brawcap_adapter_mtu_t
Type for handling the adapter maximum transmission unit (MTU).
Definition: brawcap_types_um.h:381
brawcap_status_t brawcap_adapter_operation(const brawcap_adapter_name_t name, brawcap_adapter_operation_state_t *const pOperation)
Reads out the current operation state of the specified adapter.
@ BRAWCAP_ADAPTER_PROPERTY_CONNECTION_STATE
Definition: brawcap_types_um.h:424
@ BRAWCAP_ADAPTER_PROPERTY_IPV6
Definition: brawcap_types_um.h:426
@ BRAWCAP_ADAPTER_PROPERTY_OPERATION_STATE
Definition: brawcap_types_um.h:423
@ BRAWCAP_ADAPTER_PROPERTY_RX_SPEED
Definition: brawcap_types_um.h:420
@ BRAWCAP_ADAPTER_PROPERTY_FRIENDLY_NAME
Definition: brawcap_types_um.h:419
@ BRAWCAP_ADAPTER_PROPERTY_IPV4
Definition: brawcap_types_um.h:425
@ BRAWCAP_ADAPTER_PROPERTY_TX_SPEED
Definition: brawcap_types_um.h:421
@ BRAWCAP_ADAPTER_PROPERTY_MTU
Definition: brawcap_types_um.h:422
@ BRAWCAP_ADAPTER_CONNECTION_UP
Definition: brawcap_types_um.h:352
@ BRAWCAP_ADAPTER_CONNECTION_UNKNOWN
Definition: brawcap_types_um.h:351
@ BRAWCAP_ADAPTER_CONNECTION_DOWN
Definition: brawcap_types_um.h:353
@ BRAWCAP_ADAPTER_SPEED_UNKNOWN
Definition: brawcap_types_um.h:332
@ BRAWCAP_ADAPTER_OPERATION_DOWN
Definition: brawcap_types_um.h:364
@ BRAWCAP_ADAPTER_OPERATION_UNKNOWN
Definition: brawcap_types_um.h:362
@ BRAWCAP_ADAPTER_OPERATION_TESTING
Definition: brawcap_types_um.h:365
@ BRAWCAP_ADAPTER_OPERATION_UP
Definition: brawcap_types_um.h:363
@ BRAWCAP_ADAPTER_NOTIFY_REASON_PROPERTY_CHANGE
A adapter property has changed. This can have several reasons, for a list of all properties see brawc...
Definition: brawcap_types_um.h:407
@ BRAWCAP_ADAPTER_NOTIFY_REASON_ADD
A new bRAWcap adapter was detected. E.g. due to enabling bRAWcap driver on an adapter where it was di...
Definition: brawcap_types_um.h:397
@ BRAWCAP_ADAPTER_NOTIFY_REASON_REMOVE
A bRAWcap adapter was removed. E.g. due to disabling bRAWcap driver on an adapter where it was enable...
Definition: brawcap_types_um.h:402
@ BRAWCAP_ADAPTER_NOTIFY_REASON_UNKNOWN
The notification reason is unknown.
Definition: brawcap_types_um.h:392