9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* [9fans] etherconf
@ 2000-08-22  5:23 James A. Robinson
  0 siblings, 0 replies; only message in thread
From: James A. Robinson @ 2000-08-22  5:23 UTC (permalink / raw)
  To: Plan 9 Mailing List

[-- Attachment #1: Type: text/plain, Size: 230 bytes --]

I'm probably doing something wrong with /lib/ndb/local, but I can't get
ipconfig to pick up the proper arguments from the file.  So I wrote
a hackish script to set the ethernet device. In case anyone else is
interested...



[-- Attachment #2: etherconf --]
[-- Type: text/plain, Size: 1076 bytes --]

#!/bin/rc
#
# etherconf
# 	call ipconfig with information obtained via ndb/query
#	on the ethernet addresses in /net/ether*/addr
#
if (~ $1 -d) {
	debug=1
}
if not debug=0

for (device in `{ls -d /net/ether*|sort -nr}) {
	addr=`{cat $device/addr}
	ip=`{ndb/query ether $addr ip}
	ipgw=''
	ipmask=''
	networks=(`{awk -v 'ip='^$ip 'BEGIN {
		OFS=".";
		if (split(ip, oct, ".") != 4) {
			exit;
		}
		print oct[1],oct[2],oct[3],0;
		print oct[1],oct[2],0,0;
		print oct[1],0,0,0;
	}'})
	for (net in $networks) {
		if (~ $ipgw '') {
			ipgw=`{ndb/query ip $net ipgw}
		}
		if (~ $ipmask '') {
			ipmask=`{ndb/query ip $net ipmask}
		}
	}
	# why no if/else in rc?
	if (~ $ipgw '') {
		echo etherconf: skipping $ip: no ipgw >[1=2]
	}
	if (~ $ipmask '') {
		echo etherconf: skipping $ip: no ipmask >[1=2]
	}
	if (! ~ $ipgw '' && ! ~ $ipmask '') {
		val=($ip $ipgw $ipmask);
		echo -n 'etherconf: '
		if (! ~ $debug 1) {
			echo set $device: $val
			ip/ipconfig ether $device add $val
		}
		if not echo would set $device to $val
	}
}

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2000-08-22  5:23 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-08-22  5:23 [9fans] etherconf James A. Robinson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).