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.
37void ParseArgs(
int argc,
char** argv,
int* exec_time)
41 if(!memcmp(argv[1],
"-t", 2))
44 *exec_time = strtol(argv[2], &pEnd,0);
50 const UINT32 properties,
void* pUser)
57 int* pNotifyCounter = (
int*) pUser;
64 char* friendlyName = 0;
65 UINT32 friendlyNameLength = 0;
68 friendlyName = malloc(friendlyNameLength);
72 printf(
"Could not resolve adapter friendly name (unexpected status: %d)\n", status);
78 printf(
"\n%03d. Notification\n", *pNotifyCounter);
85 printf(
"Unknown notification reason.");
90 printf(
"%s (%s) added\n", friendlyName, name);
95 printf(
"%s (%s) removed\n", friendlyName, name);
105 printf(
"%s (%s) new connection state: ", friendlyName, name);
106 switch (connectionState)
116 printf(
"%s new friendly name: %s\n", name, friendlyName);
123 printf(
"%s (%s) new IPv4: %u.%u.%u.%u\n", friendlyName, name,
132 printf(
"%s (%s) new IPv6: %x:%x:%x:%x:%x:%x:%x:%x\n", friendlyName, name,
142 printf(
"%s (%s) new max transmission unit: %llu\n", friendlyName, name, mtu);
150 printf(
"%s (%s) new operation state: ", friendlyName, name);
151 switch (operationState)
165 printf(
"%s (%s) new receive (uplink) speed: %u MBit/s\n", friendlyName, name, speed);
173 printf(
"%s (%s) new transmit (uplink) speed: %u MBit/s\n", friendlyName, name, speed);
187int main(
int argc,
char** argv)
190 SetConsoleTitleA(
"bRAWcap Example - Adapter Change Notifier");
194 ParseArgs(argc, argv, &exec_time);
200 int notifyCounter = 0;
207 printf(
"Registration for adapter change notification failed (Status: %d). Will stop now...", status);
216 }
while (++runtime_sec < exec_time);
224 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: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_ERROR_OVERRUN
A buffer overrun was detected.
Definition: brawcap_types_shared.h:245
IPv4 address.
Definition: brawcap_types_um.h:263
IPv6 address.
Definition: brawcap_types_um.h:273
UINT8 bytes[4]
Definition: brawcap_types_um.h:264
UINT16 words[8]
Definition: brawcap_types_um.h:275
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:306
char brawcap_adapter_name_t[BRAWCAP_ADAPTER_NAME_LENGTH]
Fixed size array containing a adapter name.
Definition: brawcap_types_um.h:257
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:287
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:400
brawcap_adapter_operation_state_t
List of adapter operation states. Values indicating the current adapter operation state (adapter driv...
Definition: brawcap_types_um.h:317
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:344
UINT64 brawcap_adapter_mtu_t
Type for handling the adapter maximum transmission unit (MTU).
Definition: brawcap_types_um.h:337
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:380
@ BRAWCAP_ADAPTER_PROPERTY_IPV6
Definition: brawcap_types_um.h:382
@ BRAWCAP_ADAPTER_PROPERTY_OPERATION_STATE
Definition: brawcap_types_um.h:379
@ BRAWCAP_ADAPTER_PROPERTY_RX_SPEED
Definition: brawcap_types_um.h:376
@ BRAWCAP_ADAPTER_PROPERTY_FRIENDLY_NAME
Definition: brawcap_types_um.h:375
@ BRAWCAP_ADAPTER_PROPERTY_IPV4
Definition: brawcap_types_um.h:381
@ BRAWCAP_ADAPTER_PROPERTY_TX_SPEED
Definition: brawcap_types_um.h:377
@ BRAWCAP_ADAPTER_PROPERTY_MTU
Definition: brawcap_types_um.h:378
@ BRAWCAP_ADAPTER_CONNECTION_UP
Definition: brawcap_types_um.h:308
@ BRAWCAP_ADAPTER_CONNECTION_UNKNOWN
Definition: brawcap_types_um.h:307
@ BRAWCAP_ADAPTER_CONNECTION_DOWN
Definition: brawcap_types_um.h:309
@ BRAWCAP_ADAPTER_SPEED_UNKNOWN
Definition: brawcap_types_um.h:288
@ BRAWCAP_ADAPTER_OPERATION_DOWN
Definition: brawcap_types_um.h:320
@ BRAWCAP_ADAPTER_OPERATION_UNKNOWN
Definition: brawcap_types_um.h:318
@ BRAWCAP_ADAPTER_OPERATION_TESTING
Definition: brawcap_types_um.h:321
@ BRAWCAP_ADAPTER_OPERATION_UP
Definition: brawcap_types_um.h:319
@ 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:363
@ 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:353
@ 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:358
@ BRAWCAP_ADAPTER_NOTIFY_REASON_UNKNOWN
The notification reason is unknown.
Definition: brawcap_types_um.h:348