any real rationale for "for_all_interfaces()"??

Robert P. J. Day rpjday at mindspring.com
Sat Jun 17 17:19:48 UTC 2006


  i'm looking at the function for_all_interfaces() in
networking/interface.c and, frankly, it just seems overly cumbersome,
restrictive and, well, useless.  (yes, i am going somewhere with
this.)

  i can see what it's doing, but it seems that it would be *far* more
useful, if one wanted to iterate over some set, to define a macro of
some kind that just returned the elements one at a time, and let the
*caller* decide what to do with each one.  eg.,

  #define FOR_ALL_INTERFACES(i) \
	for (i = int_list ; i ; i = i->next)

  as it stands, that function *will* iterate over all network
interfaces, but only if you additionally give it a function of a
particular kind and a "cookie".  if you want to do anything else,
you're SOL.  (besides, that function is being called from only one
location so it's not like it's a focal point for activity or
anything.)

  the reason i bring this up is i was going to submit a patch that
modified ifconfig.c to use two interface display routines:

  display_interface(char *ifname) ;
  display_all_interfaces("bool" opt_a) ;

which would be a far more meaningful and less brain-damaging
implementation than what's there.  but what should take only a few
minutes of recoding gets hung up on the ugliness that is
for_all_interfaces().

  so, as a test, i'm going to toss that, replace it with a simple
macro and submit a patch.  it should do just what it does now, but in
a way that doesn't make people want to claw their eyes out when they
read the code.

  comments?

rday



More information about the busybox mailing list