Check-in [e28b7fa02d]
Overview
SHA1:e28b7fa02def941325cc02f907465a97e736bada
Date: 2014-11-03 18:00:05
User: rkeene
Comment:Work towards a better ifconfig interface
Timelines: family | ancestors | descendants | both | trunk
Downloads: Tarball | ZIP archive
Other Links: files | file ages | folders | manifest
Tags And Properties
Context
2014-12-15
16:19
[8a0dedb7c5] Added wildcard matching to modprobe (user: rkeene, tags: trunk)
2014-11-03
18:00
[e28b7fa02d] Work towards a better ifconfig interface (user: rkeene, tags: trunk)
17:15
[55756e0014] Added UNIX command-workalikes for dmesg/ulimit (user: rkeene, tags: trunk)
Changes

Modified tuapi.tcl from [271a0d4ae4] to [f5399ad231].

   238    238   			"up" {
   239    239   				if {[info exists ifaceinfo(flags)]} {
   240    240   					set flags $ifaceinfo(flags)
   241    241   				} else {
   242    242   					set flags ""
   243    243   				}
   244    244   
   245         -				foreach newflag [list UP RUNNING] {
          245  +				foreach newflag [list UP] {
   246    246   					if {[lsearch -exact $flags $newflag] == -1} {
   247    247   						lappend flags $newflag
   248    248   					}
   249    249   				}
   250    250   
   251    251   				::tuapi::syscall::ifconfig $interface flags $flags
   252    252   			}
          253  +			"down" {
          254  +				if {[info exists ifaceinfo(flags)]} {
          255  +					set flags $ifaceinfo(flags)
          256  +				} else {
          257  +					set flags ""
          258  +				}
   253    259   
          260  +				set flagidx [lsearch -exact $flags "UP"]
          261  +				if {$flagidx != -1} {
          262  +					set flags [lreplace $flags $flagidx $flagidx]
          263  +
          264  +					::tuapi::syscall::ifconfig $interface flags $flags
          265  +				}
          266  +			}
          267  +			default {
          268  +				incr idx
          269  +				set optval [lindex $args $idx]
          270  +
          271  +				::tuapi::syscall::ifconfig $interface $opt $optval
          272  +			}
   254    273   		}
   255    274   	}
   256    275   }
   257    276   
   258    277   proc ::tuapi::helper::foreach_line {fd sep code} {
   259    278   	while {![eof $fd]} {
   260    279   		gets $fd line
................................................................................
   623    642   			if {![info exists optval]} {
   624    643   				continue
   625    644   			}
   626    645   
   627    646   			puts "${include_help}$optval"
   628    647   		}
   629    648   	}
          649  +
          650  +	proc ::ifconfig {{ifacelist ""} {config ""}} {
          651  +		if {$ifacelist == "" || $ifacelist == "-a"} {
          652  +			set ifacelist [tuapi::syscall::ifconfig]
          653  +			set config ""
          654  +		}
          655  +
          656  +		if {$config != ""} {
          657  +			if {[string match "*.*.*.*" [lindex $config 0]]} {
          658  +				set config [linsert $config 0 "address"]
          659  +			}
          660  +
          661  +			puts [list ::tuapi::ifconfig [lindex $ifacelist 0] {*}$config]
          662  +			return [::tuapi::ifconfig [lindex $ifacelist 0] {*}$config]
          663  +		}
          664  +
          665  +		foreach iface $ifacelist {
          666  +			unset -nocomplain ifaceinfo
          667  +			array set ifaceinfo [tuapi::syscall::ifconfig $iface]
          668  +
          669  +			set secondline ""
          670  +			foreach {label entry} [list inet address netmask netmask broadcast broadcast] {
          671  +				if {![info exists ifaceinfo($entry)]} {
          672  +					continue
          673  +				}
          674  +
          675  +				append secondline " $label $ifaceinfo($entry)"
          676  +			}
          677  +
          678  +			puts "$iface: flags=<[join $ifaceinfo(flags) ,]> mtu $ifaceinfo(mtu) index $ifaceinfo(index)"
          679  +			puts "\t[string trim $secondline]"
          680  +			if {[info exists ifaceinfo(hwaddr)]} {
          681  +				puts "\tether $ifaceinfo(hwaddr)"
          682  +			}
          683  +		}
          684  +	}
   630    685   }