eth32cfg eth32cfg_discover_ip(eth32cfg_ip_t *bcastaddr, unsigned int flags, unsigned char *mac, unsigned char product_id, unsigned short serialnum_batch, unsigned short serialnum_unit, int *number, int *result);
This function is used to detect ETH32 devices and their currently-active IP configuration settings. This function allows you to specify filter flags so that only the information for the specific ETH32 device that you are interested in will be returned (in case there are multiple ETH32s on the network). This is intended for applications that need to discover the IP of a device that is using DHCP to get its IP address. This function uses a new command to the ETH32 device that is only supported by devices with firmware v3.000 and on. Any older devices on the network will not be detected. The eth32cfg_data_t structure for devices detected with this function will not have all fields filled in, since the response from the ETH32 does not include all available information. Only the product_id, mac, serialnum_batch, serialnum_unit, active_ip, active_gateway, active_netmask, and dhcp fields will be filled in and valid.
The flags parameter instructs the function which data to filter on. Although this function includes parameters for both MAC and serial number information, they will only be considered if the appropriate flag is present in the flags parameter.
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 should 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.
flags - Specifies which parameters should be considered in discovering the device. If more than one flag is specified, then the device must match BOTH. This parameter may be one or a combination of the following values:
ETH32CFG_FILTER_NONE - The parameters will be ignored. All devices will be discovered.
ETH32CFG_FILTER_MAC - Only devices matching the provided MAC address will be discovered.
ETH32CFG_FILTER_SERIAL - Only devices matching the provided serial number information (id, batch, unit) will be discovered.
mac - The MAC address of the device you are trying to discover. If flags does not include ETH32CFG_FILTER_SERIAL, this can be NULL.
product_id - The product ID code (part of the serial number) of the device you are trying to discover. For ETH32 devices, this is 105.
serialnum_batch - The batch number portion of the serial number for the device you are trying to discover.
serialnum_unit - The unit number portion of the serial number for the device you are trying to discover.
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.
eth32 dev; eth32cfg handle; eth32cfg_ip_t bcast; eth32cfg_data_t devdata; char buf[50]; int number; int result; // We could just pass a null pointer in for the broadcast address, but // we'll show how 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] // Find a device by serial number -- we can use the ETH32_PRODUCT_ID constant, // 1 for the batch (AB), and 82 for the unit number. // This would be serial number 105-AB082 as shown on the device. handle=eth32cfg_discover_ip(&bcast, ETH32CFG_FILTER_SERIAL, NULL, ETH32_PRODUCT_ID, 1, 82, &number, &result); if(result) { printf("Error detecting device: %s\n", eth32_error_string(result)); // handle error as appropriate in your code, prevent falling through // to code below. } if(number==0) { printf("Device not found.\n"); } else { // Retrieve all the device information into our structure eth32cfg_get_config(handle, 0, &devdata); // Convert the Active IP into a string eth32cfg_ip_to_string(&(devdata.active_ip), buf); // Now connect to the device and turn on LED 0 // Error checking omitted for brevity dev=eth32_open(buf, ETH32_PORT, 0, &result); eth32_set_led(dev, 0, 1); eth32_close(dev); } // Free the results when finished eth32cfg_free(handle);