#!/bin/bash

# NOTE: This script is hard-coded to only work with ethernet device eth0
NETDEV="eth0"


if [ "$#" -ne 2 ]; then
    echo "Usage: $0 {0-255} command"
    echo "Runs command with IP addres 10.0.0.n, where n is specified"
    echo "(Put the command in quotes)"
    exit 1
fi
POSTFIX=$1
COMMAND=$2

# verify they provided an OK IP address ...
if [ ! `echo $POSTFIX | grep -e ^[[:digit:]]*$` ]; then
    echo "Bad format for IP postfix"
    exit 1
fi


if [ ! $LIBIPADDR ]; then
    LIBIPADDR="./libipaddr.so"
fi

if [ ! -f $LIBIPADDR ]; then
    echo "Could not locate libipaddr.  Please put in same directory or set environment variable libipaddr"
    exit 1
fi



# export necessary environment variables
export SRCIP="10.0.0."$POSTFIX
export LD_PRELOAD=$LIBIPADDR


$COMMAND
