Mike Frysinger | bcb6dd9 | 2008-12-09 23:20:31 -0500 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | usage() { |
| 4 | ( |
Joe Hershberger | 7f51898 | 2012-07-31 06:06:41 +0000 | [diff] [blame] | 5 | echo "Usage: $0 <board-IP> [board-port [board-in-port]]" |
Mike Frysinger | bcb6dd9 | 2008-12-09 23:20:31 -0500 | [diff] [blame] | 6 | 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 | |
| 16 | while [ -n "$1" ] ; do |
| 17 | case $1 in |
| 18 | -h|--help) usage;; |
| 19 | --) break;; |
| 20 | -*) usage "Invalid option $1";; |
| 21 | *) break;; |
| 22 | esac |
| 23 | shift |
| 24 | done |
| 25 | |
| 26 | ip=$1 |
Joe Hershberger | 7f51898 | 2012-07-31 06:06:41 +0000 | [diff] [blame] | 27 | board_out_port=${2:-6666} |
| 28 | board_in_port=${3:-${board_out_port}} |
Mike Frysinger | bcb6dd9 | 2008-12-09 23:20:31 -0500 | [diff] [blame] | 29 | |
Joe Hershberger | 7f51898 | 2012-07-31 06:06:41 +0000 | [diff] [blame] | 30 | echo Board out port: ${board_out_port} |
| 31 | echo Board in port: ${board_in_port} |
| 32 | |
| 33 | if [ -z "${ip}" ] || [ -n "$4" ] ; then |
Mike Frysinger | bcb6dd9 | 2008-12-09 23:20:31 -0500 | [diff] [blame] | 34 | usage "Invalid number of arguments" |
| 35 | fi |
| 36 | |
Andy Shevchenko | f0d4607 | 2021-11-17 20:15:06 +0300 | [diff] [blame^] | 37 | for nc in socat netcat nc ; do |
Mike Frysinger | 7709318 | 2009-09-09 12:20:20 -0400 | [diff] [blame] | 38 | type ${nc} >/dev/null 2>&1 && break |
Mike Frysinger | bcb6dd9 | 2008-12-09 23:20:31 -0500 | [diff] [blame] | 39 | done |
| 40 | |
| 41 | trap "stty icanon echo intr ^C" 0 2 3 5 10 13 15 |
| 42 | echo "NOTE: the interrupt signal (normally ^C) has been remapped to ^T" |
| 43 | |
| 44 | stty -icanon -echo intr ^T |
Mike Frysinger | 7709318 | 2009-09-09 12:20:20 -0400 | [diff] [blame] | 45 | ( |
Mike Frysinger | 1c20e4a | 2009-09-09 12:20:21 -0400 | [diff] [blame] | 46 | if type ncb 2>/dev/null ; then |
| 47 | # see if ncb is in $PATH |
Joe Hershberger | 7f51898 | 2012-07-31 06:06:41 +0000 | [diff] [blame] | 48 | exec ncb ${board_out_port} |
Mike Frysinger | 1c20e4a | 2009-09-09 12:20:21 -0400 | [diff] [blame] | 49 | |
Andy Shevchenko | f0d4607 | 2021-11-17 20:15:06 +0300 | [diff] [blame^] | 50 | elif [ "${nc}" = "socat" ] ; then |
| 51 | # socat does support broadcast |
| 52 | while ${nc} STDIO "UDP4-LISTEN:${board_out_port}"; do :; done |
| 53 | |
Mike Frysinger | 1c20e4a | 2009-09-09 12:20:21 -0400 | [diff] [blame] | 54 | elif [ -x ${0%/*}/ncb ] ; then |
| 55 | # maybe it's in the same dir as the netconsole script |
Joe Hershberger | 7f51898 | 2012-07-31 06:06:41 +0000 | [diff] [blame] | 56 | exec ${0%/*}/ncb ${board_out_port} |
Mike Frysinger | 1c20e4a | 2009-09-09 12:20:21 -0400 | [diff] [blame] | 57 | |
| 58 | else |
| 59 | # blah, just use regular netcat |
Joe Hershberger | 7f51898 | 2012-07-31 06:06:41 +0000 | [diff] [blame] | 60 | while ${nc} -u -l -p ${board_out_port} < /dev/null ; do |
Mike Frysinger | 1c20e4a | 2009-09-09 12:20:21 -0400 | [diff] [blame] | 61 | : |
| 62 | done |
| 63 | fi |
Mike Frysinger | 7709318 | 2009-09-09 12:20:20 -0400 | [diff] [blame] | 64 | ) & |
| 65 | pid=$! |
Andy Shevchenko | f0d4607 | 2021-11-17 20:15:06 +0300 | [diff] [blame^] | 66 | if [ "${nc}" = "socat" ] ; then |
| 67 | ${nc} - "UDP4:${ip}:${board_in_port}" |
| 68 | else |
| 69 | ${nc} -u ${ip} ${board_in_port} |
| 70 | fi |
Mike Frysinger | 7709318 | 2009-09-09 12:20:20 -0400 | [diff] [blame] | 71 | kill ${pid} 2>/dev/null |