#!/bin/sh FSYSOPTS=/bin/fsysopts DSOCKET=/servers/socket/2 PFINET=/hurd/pfinet DEFAULT_INTERFACE=eth0 # test if there is an pfinet on /servers/socket/2 if ! $FSYSOPTS $DSOCKET | grep -q pfinet; then settrans -fga $DSOCKET $PFINET -i $DEFAULT_INTERFACE -a 0.0.0.0 \ -m 255.255.255.0 $FSYSOPTS $DSOCKET -i $DEFAULT_INTERFACE -6 ${DSOCKET}6 fi usage() { echo "$0 [-6] INTERFACE IP - set the ip (or ipv6) address of this device" echo "$0 [-6] INTERFACE gateway IP - set the default gateway of this device" echo "$0 INTERFACE nm MASK - set the netmask of this device" echo "$0 [-6] INTERFACE down - unset global ip of this device" } ipv4() { echo "$1" | grep -q "^[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*$" } ipv6() { echo "$1" | grep -q "^[0-9a-fA-F]*:[0-9a-fA-F]*" } get_interfaces() { $FSYSOPTS $DSOCKET | tr ' ' '\n' | sed -n 's/--interface=\([^ ]*\)/\1/p' } show_interface() { echo $1 $FSYSOPTS $DSOCKET | tr ' ' '\n' | \ sed -n '/^--interface='"$1"'$/,/--interface/ { s/^--address=\([^ ]*\)/ Address: \1/p s/^--gateway=\([^ ]*\)/ Default Gateway: \1/p s/^--netmask=\([^ ]*\)/ Netmask: \1/p s/^--address6=\(fe80[^ ]*\)/ inet6 address: \1 (link local)/p s/^--address6=\([^ ]*\)/ inet6 address: \1 (global)/p s/^--gateway6=\([^ ]*\)/ inet6 gateway: \1/p } ' } if [ "x$1" = "x--help" -o "x$1" = "x-h" ]; then usage exit 0 fi if [ -z "$1" ]; then for ifname in `get_interfaces`; do show_interface $ifname done else if [ "x$1" = "x-6" ]; then V6=true shift fi ifname="$1" if [ -z "$2" ]; then show_interface $ifname elif [ "x$2" = "xgateway" -o "x$2" = "xgw" ]; then if [ "x$V6" = "xtrue" ]; then if ipv6 "$3"; then $FSYSOPTS $DSOCKET -i $ifname -G$3 else echo "No valid address" fi else if ipv4 "$3"; then $FSYSOPTS $DSOCKET -i $ifname -g$3 else echo "No valid address" fi fi elif [ "x$2" = "xnetmask" -o "x$2" = "xnm" ]; then if ipv4 "$3"; then $FSYSOPTS $DSOCKET -i $ifname -m$3 else if [ "x$V6" = "xtrue" ]; then echo "There are no real netmasks in ipv6" else echo "No valid netmask" fi fi elif [ "x$2" = "xup" ]; then if [ "x$V6" = "xtrue" ]; then $FSYSOPTS $DSOCKET -i $ifname -6 /servers/socket/26 fi elif [ "x$2" = "xdown" ]; then if [ "x$V6" = "xtrue" ]; then $FSYSOPTS $DSOCKET -i $ifname -A else $FSYSOPTS $DSOCKET -i $ifname -a 0.0.0.0 -m 255.255.255.0 fi elif ipv4 "$2"; then $FSYSOPTS $DSOCKET -i $ifname -a$2 elif ipv6 "$2"; then $FSYSOPTS $DSOCKET -i $ifname -A$2 else echo "invalid options" fi fi