eth32cfg eth32cfg_query(eth32cfg_ip_t *bcastaddr, int *number, int *result);
This function is used to detect all ETH32 devices on the local network segment and all of their available device information and configuration settings. Once this function returns, the configuration data for any devices that have been found will be available through the eth32cfg_get_config function. When you are finished with the results, they must be freed using eth32cfg_free.
bcastaddr - Broadcast address to which queries should be sent. Passing in NULL will use 255.255.255.255, which is suitable for most situations.
number - A pointer to an integer which will receive the number of devices that were found.
result - A pointer to an integer which will receive an error code. If the function returns a nonzero handle, this value will be zero.
The return type is defined as eth32cfg, which is a handle typedef'ed as a void pointer. This function returns a nonzero handle on success, or zero on failure. In case of failure, the specific error code is stored into the result parameter, if provided. A valid returned handle can be used with the eth32cfg_get_config function to retrieve device information.
If no devices are found, but no error has occurred, the function will still return a nonzero handle, but also indicate in the number parameter that 0 devices were found. Even in this case, the handle must be freed using eth32cfg_free.
As opposed to the eth32cfg_discover_ip function, which is only supported by devices with firmware 3.000 and greater, the eth32cfg_query function detects all devices with all firmware versions. This function sends several queries out repeatedly in case any queries or responses are lost on the network. It also delays for a short while to listen for responses. Because of this, the eth32cfg_discover_ip function will be faster if you are looking for a specific device, know its MAC address or serial number, and know it is running firmware v3.000 or greater.
eth32cfg handle; eth32cfg_ip_t bcast; eth32cfg_data_t devdata; char buf[50]; int number; int result; int i; // We could just pass a null pointer in for the broadcast address, but // we'll show ways to define a broadcast address here. eth32cfg_string_to_ip("255.255.255.255", &bcast); // We could also do bcast.byte[0]=255; and so on through byte[3] handle=eth32cfg_query(&bcast, &number, &result); if(result) { printf("Error detecting devices: %s\n", eth32_error_string(result)); // handle error as appropriate in your code, prevent falling through // to code below. } if(number==0) { printf("No devices were found.\n"); } else { for(i=0; i<number; i++) { // Retrieve all the device information into our structure eth32cfg_get_config(handle, i, &devdata); // Convert the Active IP into a string eth32cfg_ip_to_string(&(devdata.active_ip), buf); // And print it out printf("Device found with IP address of: %s\n", buf); } } // Free the results when finished eth32cfg_free(handle);