blob: 155453320f73c4b5ef741d524e98106f13e36417 [file] [log] [blame]
Mike Frysingerbcb6dd92008-12-09 23:20:31 -05001#!/bin/sh
2
3usage() {
4 (
Joe Hershberger7f518982012-07-31 06:06:41 +00005 echo "Usage: $0 <board-IP> [board-port [board-in-port]]"
Mike Frysingerbcb6dd92008-12-09 23:20:31 -05006 echo ""
7 echo "If port is not specified, '6666' will be used"
8 [ -z "$*" ] && exit 0
9 echo ""
10 echo "ERROR: $*"
11 exit 1
12 ) 1>&2
13 exit $?
14}
15
16while [ -n "$1" ] ; do
17 case $1 in
18 -h|--help) usage;;
19 --) break;;
20 -*) usage "Invalid option $1";;
21 *) break;;
22 esac
23 shift
24done
25
26ip=$1
Joe Hershberger7f518982012-07-31 06:06:41 +000027board_out_port=${2:-6666}
28board_in_port=${3:-${board_out_port}}
Mike Frysingerbcb6dd92008-12-09 23:20:31 -050029
Joe Hershberger7f518982012-07-31 06:06:41 +000030echo Board out port: ${board_out_port}
31echo Board in port: ${board_in_port}
32
33if [ -z "${ip}" ] || [ -n "$4" ] ; then
Mike Frysingerbcb6dd92008-12-09 23:20:31 -050034 usage "Invalid number of arguments"
35fi
36
Andy Shevchenkof0d46072021-11-17 20:15:06 +030037for nc in socat netcat nc ; do
Mike Frysinger77093182009-09-09 12:20:20 -040038 type ${nc} >/dev/null 2>&1 && break
Mike Frysingerbcb6dd92008-12-09 23:20:31 -050039done
40
41trap "stty icanon echo intr ^C" 0 2 3 5 10 13 15
42echo "NOTE: the interrupt signal (normally ^C) has been remapped to ^T"
43
44stty -icanon -echo intr ^T
Mike Frysinger77093182009-09-09 12:20:20 -040045(
Mike Frysinger1c20e4a2009-09-09 12:20:21 -040046if type ncb 2>/dev/null ; then
47 # see if ncb is in $PATH
Joe Hershberger7f518982012-07-31 06:06:41 +000048 exec ncb ${board_out_port}
Mike Frysinger1c20e4a2009-09-09 12:20:21 -040049
Andy Shevchenkof0d46072021-11-17 20:15:06 +030050elif [ "${nc}" = "socat" ] ; then
51 # socat does support broadcast
52 while ${nc} STDIO "UDP4-LISTEN:${board_out_port}"; do :; done
53
Mike Frysinger1c20e4a2009-09-09 12:20:21 -040054elif [ -x ${0%/*}/ncb ] ; then
55 # maybe it's in the same dir as the netconsole script
Joe Hershberger7f518982012-07-31 06:06:41 +000056 exec ${0%/*}/ncb ${board_out_port}
Mike Frysinger1c20e4a2009-09-09 12:20:21 -040057
58else
59 # blah, just use regular netcat
Joe Hershberger7f518982012-07-31 06:06:41 +000060 while ${nc} -u -l -p ${board_out_port} < /dev/null ; do
Mike Frysinger1c20e4a2009-09-09 12:20:21 -040061 :
62 done
63fi
Mike Frysinger77093182009-09-09 12:20:20 -040064) &
65pid=$!
Andy Shevchenkof0d46072021-11-17 20:15:06 +030066if [ "${nc}" = "socat" ] ; then
67 ${nc} - "UDP4:${ip}:${board_in_port}"
68else
69 ${nc} -u ${ip} ${board_in_port}
70fi
Mike Frysinger77093182009-09-09 12:20:20 -040071kill ${pid} 2>/dev/null