home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 1999 March B
/
SCO_CASTOR4RRT.iso
/
nwnet
/
root
/
usr
/
lib
/
netcfg
/
bin
/
ipx.fn
/
ipx
Wrap
Text File
|
1998-08-19
|
4KB
|
218 lines
#!/bin/tcl
#
# Copyright (C) 1997, The Santa Cruz Operation, Inc.
# All Rights Reserved.
#
# The information in this file is provided for the exclusive use of
# the licensees of The Santa Cruz Operation, Inc. Such users have the
# right to use, modify, and incorporate this code into other products
# for purposes authorized by the license agreement provided they include
# this notice and the associated copyright notice with any such product.
# The information in this file is provided "AS IS" without warranty.
#
#ident "@(#)ipx.fn 1.3"
#
# Generic functions related to ipx/spx netconfig
#
#
set NCFG_DIR /usr/lib/netcfg
set NWCM /usr/sbin/nwcm.be
set IPX_TMPDIR /usr/lib/ipxrt/tmp
set IPX_NEWCFG $IPX_TMPDIR/config
loadlibindex /usr/lib/sysadm.tlib
# The minimum and maximum Lan numbers.
#
set MINLAN 1
set MAXLAN 8
#
# IsValidNwcmParam use nwcm to check that the parameter param value val
# is valid
#
# return values
# 0: valid
# 1: invalid
#
proc IsValidNwcmParam {param val} {
global NWCM
set arg "-q -t $param=$val"
if [catch {eval exec $NWCM $arg} ret] {
return 0
} else {
return 1
}
}
#
# SetNwcmParam uses nwcm to set the parameter param to the value val
# Note that the special val case of "_default" is checked for which
# used to reset a parameter to its default value.
#
# return values
# 0: success
# 1: failure
#
proc SetNwcmParam {param val} {
global NWCM
if { [ cequal $val "_default" ] } {
set arg "-r $param"
} else {
set arg "-s $param=$val"
}
if [catch {eval exec $NWCM $arg} ret] {
puts "nwcm error:$NWCM $arg"
puts $ret
return 1
} else {
return 0
}
}
#
# GetNwcmParam uses nwcm to extract the parameter param
# value from the netware config database.
# The return string is the result of the call stripped of enclosing "s
#
# eg GetNwcmParam net_3_adapter might retiurn /dev/nwip
#
#
# On error the routine returns the string "_NWCMERR"
#
proc GetNwcmParam {param} {
global NWCM
if [catch {exec $NWCM -v $param} val] {
puts "nwcm error:$NWCM -v $param"
puts $val
return "_NWCMERR"
} else {
ctoken val =
set tok [join [ctoken val =]]
return $tok
}
}
# GetFreeLanNumber {}
#
# scans the nwconfig file via nwcm to find the first interface
# which does not have an associated adapter
#
# return: free lan number
#
proc GetFreeLanNumber {} {
global NWCM MAXLAN
set try 1
while { $try <= $MAXLAN } {
set nwcm_arg lan_${try}_adapter
set adap [GetNwcmParam $nwcm_arg]
if { [cequal $adap "_NWCMERR" ] } {
exit 1
} else {
if { [ cequal $adap "" ] } {
return $try
}
incr try +1
}
}
#
# you should never get here as the init script should
# have caught anyone trying to add more than MAXLAN interfaces
#
return 0
}
# FindIpxLanNumber{}
#
# scans the nwconfig file via nwcm to find the lan number
# for which the part_param is set to val
#
# eg
#
# lan_1_adapter=/dev/3C59X_0
# lan_2_adapter=/dev/nwip
#
# FindIpxLanNumber adapter /dev/nwip will return 2
# FindIpxLanNumber adapter /dev/NE2000_1 will return 0
#
proc FindIpxLanNumber {part_param val} {
global NWCM MAXLAN
set try 1
while { $try <= $MAXLAN } {
set nwcm_arg lan_${try}_${part_param}
set rval [GetNwcmParam $nwcm_arg]
if { [cequal $rval "_NWCMERR" ] } {
return 0
}
if { [ cequal $rval $val ] } {
return $try
}
incr try +1
}
return 0
}
# AutoDiscover{adapter}
#
# Attempts to use nwdiscover to set the frame type
# and network number for the nominated adapter
#
proc AutoDiscover { adapter } {
global FRAME_TYPE LAN_NETWORK
set IPX_AD /tmp/ipx.ad
# nwdiscover is a bit difficult, it can
# report an error even though it detects something
# useful
# - so send output to a file and scan the
# file for useful output
catch {exec /usr/sbin/nwdiscover -d $adapter > $IPX_AD } nwd
if { [set ad_fd [open $IPX_AD r]] == -1 } {
return
}
while { [ gets $ad_fd line ] != -1 } {
set found [ lindex $line 5 ]
set frame_type [ lindex $line 2 ]
set address 0x[ lindex $line 8 ]
if { [ cequal $found "found" ] } {
set FRAME_TYPE $frame_type
set LAN_NETWORK $address
break
}
}
close $ad_fd
exec rm $IPX_AD
}
# IpxProcLan returns the number of configured Ipx Lans
#
proc IpxNumLan {} {
global NWCM MAXLAN
set found 0
for { set try 1 } { $try <= $MAXLAN } { incr try +1 } {
set nwcm_arg lan_${try}_adapter
set rval [GetNwcmParam $nwcm_arg]
if { ! [cequal $rval "" ] } {
incr found
}
}
return $found
}