summaryrefslogtreecommitdiffstats
path: root/wrappers/lft
blob: a6cb08989b28afc18e5fccc93b2cd65280be248b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#!/bin/sh
#
#   Copyright (c)  2007             Dmitry K. Butskoy
#                                   <dmitry@butskoy.name>
#   License:  GPL v2 or any later
#
#   See COPYING for the status of this software.
#

#
#  Shell wrapper providing lft(8) command line interface.
#
#  The original implementation of lft(8) can be obtained
#  from http://pwhois.org/lft/
#


prgname=$0
opts=""
length=""
method="-T"

dport=""
sport=""
queries=2
ahead=5
scatter=20
timeout=1000


usage () {
    echo "Usage: $prgname [-ACEFINRSTUVbehinpruvz] [-d dport] [-s sport]
	[-m retry min] [-M retry max] [-a ahead] [-c scatter ms] [-t timeout ms]
	[-l min ttl] [-H max ttl] [-L length] [-q ISN] [-D device] [--help]
	[gateway ...]  target:dport" >&2
}

warning () {
    echo "$prgname: Option '$1' is not implemented in this wrapper" >&2
}
 

PARSED=`getopt -o 'ACEFINRSTUVbehinpruvzd:s:m:M:a:c:t:l:H:L:q:D:' -l help -- "$@"`
[ $? != 0 ] && exit 2

eval set -- "$PARSED"

while [ $# -gt 0 ]
do
    case "$1" in
	-d)  dport=$2; shift 2 ;;
	-s)  sport=$2; shift 2 ;;
	-z)  sport=""; shift ;;
	-m)  queries=$2; shift 2 ;;
	-a)  ahead=$2; shift 2 ;;
	-c)  scatter=$2; shift 2 ;;
	-t)  timeout=$2; shift 2 ;;
	-l)  opts="$opts -f $2"; shift 2 ;;
	-L)  length=$2; shift 2 ;;
	-D)  case "$2" in
		[0-9]*)  opts="$opts -s $2" ;;
		*)  opts="$opts -i $2" ;;
	     esac
	     shift 2
	     ;;
	-H)  opts="$opts -m $2"; shift 2 ;;
	-I)  opts="$opts -t 0x10"; shift ;;
	-n)  opts="$opts -n"; shift ;;
	-h)  shift ;;
	-F)  opts="$opts -O fin"; shift ;;
	-u)  method="-U"; shift ;;
	-N)  opts="$opts -A"; shift ;;
	-p)  method="-I"; shift ;;
	-b)  shift ;;
	-A)  opts="$opts -A"; shift ;;
	-[ieErCTUV])  warning $1; shift ;;
	-[Mq])  warning $1; shift 2 ;;
	-[RS])  shift ;;
	--help)  usage; exit 0 ;;
	-v)  echo "\"lft\"-compatible wrapper for new Linux Traceroute" >&2;
	     exit 0 ;;
	--)  shift; break ;;
	*)  echo "$prgname: Internal parsing error" >&2; exit 2 ;;
    esac
done

while [ $# -gt 1 ]
do
    opts="$opts -g $1"
    shift
done

[ $# -eq 0 ] && {
    usage
    exit 2
}

case "$1" in
	*:*:*)  host=$1 ;;
	*:*)  dport=${1##*:}; host=${1%:*} ;;
	*)  host=$1 ;;
esac

[ -n "$dport" ] && opts="$opts -p $dport"
[ -n "$sport" ] && opts="$opts --sport=$sport"
opts="$opts -q $queries"
opts="$opts -N $(($ahead * $queries))"
opts="$opts -z $scatter"

timeout=`printf "%04d" $timeout`
sec=${timeout%???}
opts="$opts -w $sec.${timeout#$sec}"

opts="$method $opts"

exec traceroute $opts $host $length