[BusyBox 0001076]: "ip addr del" does not work

Bernhard Fischer rep.nop at aon.at
Thu Oct 26 04:39:18 PDT 2006


On Thu, Oct 26, 2006 at 11:51:13AM +0200, Bernhard Fischer wrote:
>On Wed, Oct 25, 2006 at 10:01:04PM -0500, Jason Schoon wrote:
>>On 10/25/06, Denis Vlasenko <vda.linux at googlemail.com> wrote:
>>>
>>>On Wednesday 25 October 2006 18:06, Bernhard Fischer wrote:
>>>> >----------------------------------------------------------------------
>>>> > Andreas Winter - 10-25-06 03:26
>>>> >----------------------------------------------------------------------
>>>> >To be more precise: del should work in addition to delete
>>>> >
>>>> >----------------------------------------------------------------------
>>>> > bernhardf - 10-25-06 09:01
>>>> >----------------------------------------------------------------------
>>>> >I disagree. ip addr delete should still be supported, so you cannot
>>>simply
>>>> >change "delete" to "del" there.
>>>> >
>>>> >The attached snippet uses strncmp(,key,strlen(key)) rather than strcmp.
>>>> >This does not catch ambiguous args when you compare the string_array.
>>>> >
>>>> >For this to work, we'd need to keep track on how many matches we got
>>>and
>>>> >bail if matches > 1.
>>>> >
>>>> >For the ip applet, the strncmp thing should do it for now, though.
>>>>
>>>> What do you think about keeping track of the number of matches to catch
>>>> if we've seen ambiguous matches in compare_string_array?
>>>
>>>int do_ipaddr(int argc, char **argv)
>>>{
>>>        static const char *const commands[] = {
>>>                "add", "delete", "list", "show", "lst", "flush", 0
>>>        };
>>>
>>>I think adding "del" here will be perfectly ok.
>>>(do_iproute has "del" and "delete, for example).

nah. Don't like that, it's inaccurate and adds too much bloat.
>>>
>>>I am committing this change.
>>>
>>>Thank you guys.
>>>--
>>>vda
>>>
>>
>>The reason this initially led to more discussion is that there were numerous
>>short aliases supported in the full version, and possibly other applets as
>>well.  The thought was to find a way to more generically support them
>>without needing to increase the size of applets by adding every possible
>>alias variation as a string.
>
>That's why i (still) propose to use strncmp.. :)

What about adding an "exact_match" param to compare_string_array?
/* Returns the array number of the string.  */
int compare_string_array(const char * const string_array[],
	const char *key, unsigned exact_match)
{
        int i;

        for (i = 0; string_array[i] != 0; i++) {
		if (exact_match) {
			if (strncmp(string_array[i], key, strlen(key)) == 0)
				return i;
                } else {
			if (strcmp(string_array[i], key) == 0)
				return i;
		}
        }
        return -i;
}
untested and can most likely be written to add only a few bytes.
Alternatively add a compare_substring_array() that strncmps.


More information about the busybox mailing list