There's a HIP_ASSERT() macro that takes care of logging violations, and it's
correctly disabled in non-debug builds.
> - /* We should NEVER run out of white list slots!!! */
> - HIP_DIE("Error: ran out of space for white listed interfaces!\n");
> + /* We should NEVER run out of whitelist slots!!! */
> + HIP_DIE("Error: ran out of space for whitelisted interfaces!\n");
I know you didn't introduce the comment, but it's stupid nevertheless.
> * @return interface index if the network address is bound to one, zero if
> - * no interface index was found.
> + * no interface index was found.
> */
Unrelated: is zero a valid index, according to netlink? eth0 is, after all.
Changing the return value on failure to a negative number won't hurt
in any case.
> +START_TEST(test_hip_netdev_find_label_for_address_parameters)
> +{
> + struct ifaddrs *myaddrs, *ifa = NULL;
> + char label[IF_NAMESIZE];
> +
> + /* The passed label parameter for the function hip_find_label_for_address
> + * must be at least 1 greater than the found label in the function. So
> + * a size of 1 would be for sure too short to store at least the shortest
> + * label of only 1 character.
> + */
> + char label_too_short[1];
> +
> + getifaddrs(&myaddrs);
You should warn that this test was skipped if getifaddrs() doesn't return anything.
Using mock functions would be more correct, but in this case it's probably not
worth the effort.
Almost there:
> + assert( strlen( device_ name) < sizeof( whitelist[ 0].if_label) ); MAX_WHITE_ LIST) { whitelist_ count]. if_index = if_index; whitelist[ whitelist_ count]. if_label, whitelist[ 0].if_label) );
> + if (whitelist_count < HIP_NETDEV_
> + whitelist[
> + strncpy(
> + device_name, sizeof(
> + whitelist_count++;
There's a HIP_ASSERT() macro that takes care of logging violations, and it's
correctly disabled in non-debug builds.
> - /* We should NEVER run out of white list slots!!! */
> - HIP_DIE("Error: ran out of space for white listed interfaces!\n");
> + /* We should NEVER run out of whitelist slots!!! */
> + HIP_DIE("Error: ran out of space for whitelisted interfaces!\n");
I know you didn't introduce the comment, but it's stupid nevertheless.
> - strncpy( ifr.ifr_ name, device_name, IF_NAMESIZE); ifr.ifr_ name, device_name, sizeof( ifr.ifr_ name));
> + strncpy(
Would a HIP_ASSERT be appropriate here as well?
> * @return interface index if the network address is bound to one, zero if
> - * no interface index was found.
> + * no interface index was found.
> */
Unrelated: is zero a valid index, according to netlink? eth0 is, after all.
Changing the return value on failure to a negative number won't hurt
in any case.
> +START_ TEST(test_ hip_netdev_ find_label_ for_address_ parameters) label_for_ address &myaddrs) ;
> +{
> + struct ifaddrs *myaddrs, *ifa = NULL;
> + char label[IF_NAMESIZE];
> +
> + /* The passed label parameter for the function hip_find_
> + * must be at least 1 greater than the found label in the function. So
> + * a size of 1 would be for sure too short to store at least the shortest
> + * label of only 1 character.
> + */
> + char label_too_short[1];
> +
> + getifaddrs(
You should warn that this test was skipped if getifaddrs() doesn't return anything.
Using mock functions would be more correct, but in this case it's probably not
worth the effort.