#!/bin/bash

modprobe pg3 >& /dev/null
modprobe pktgen >& /dev/null

PGDEV=/proc/net/pg
if [[ ! -e ${PGDEV} ]] ; then
	PGDEV=/proc/net/pktgen/pg0
	if [[ ! -e ${PGDEV} ]] ; then
		echo "Couldn't not locate pg in /proc/net :("
		exit 1
	fi
fi

function pgset() {
    local result

    echo $1 > ${PGDEV}

    result=`cat ${PGDEV} | fgrep "Result: OK:"`
    if [ "$result" = "" ]; then
         cat ${PGDEV} | fgrep Result:
    fi
}

function pg() {
    echo inject > ${PGDEV}
    cat ${PGDEV}
}

pgset "odev eth0"
pgset "dst 0.0.0.0"

