[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: new options for ifconfig



On 27/07/2002, Andreas Krennmair <a.krennmair@aon.at> wrote To tech@openbsd.org:
> I wrote the following patch for ifconfig. It adds the three new options
> -ip, -bc and -nm to print out _only_ an interface's IP address,

man awk

BEGIN	{ num=0; FS=":[ \t]*|[ \t]+" }
	    /^[a-z]/	{ ifn[num] = $1 }
	    /inet addr/	{ ifa[num] = $4 }
	    /netmask/	{ ifa[num-1] = $3 }
	    /UP/	{ ifu[num] = 1; num++ }
END	{ count=0
	    while (count <= num) {
		if (ifu[count] ) print ifn[count] ":" ifa[count]
		count++
	    }
        }

Side effect, it lists only 'UP' interfaces, and works under linux as well.
OTOH, it has a bug w/ ip-aliases on BSD. Feel free to fix.

> broadcast address or netmask. This makes it _much_ easier for shell
> scripts etc. to find out these values. I don't know if this is cleanly
> integrated into ifconfig, but I think you can recognize the intention.

Maybe you should learn more about sh/awk/whatever scripting.

Usually one uses shell-scripts for crossplattform tasks. Do you send
such patches to HP, Sun, IBM, .... on this behalf as well?

On the point of coding, get a grip on case switches.

ciao
-- 
Philipp Buehler, aka fips | sysfive.com GmbH | BOfH | NUCH | <double-p> 

#1: Break the clue barrier!
#2: Already had buzzword confuseritis ?