| 1 |
// This file is part of pluggable-discovery-protocol-handler. |
| 2 |
// |
| 3 |
// SPDX-FileCopyrightText: Arduino s.r.l. and/or its affiliated companies |
| 4 |
// SPDX-License-Identifier: GPL-3.0-or-later |
| 5 |
|
| 6 |
// Proxy stdin/stdout through a TCP socket. |
| 7 |
// This program is used for testing purposes, to make it available on all |
| 8 |
// OS a tool equivalent to UNIX "nc". |
| 9 |
package main |
| 10 |
|
| 11 |
import ( |
| 12 |
"io" |
| 13 |
"net" |
| 14 |
"os" |
| 15 |
) |
| 16 |
|
| 17 |
func main() { |
| 18 |
tcpAddr, err := net.ResolveTCPAddr("tcp", os.Args[1]) |
| 19 |
if err != nil { |
| 20 |
println("ResolveTCPAddr failed:", err.Error()) |
| 21 |
os.Exit(1) |
| 22 |
} |
| 23 |
|
| 24 |
conn, err := net.DialTCP("tcp", nil, tcpAddr) |
| 25 |
if err != nil { |
| 26 |
println("Dial failed:", err.Error()) |
| 27 |
os.Exit(1) |
| 28 |
} |
| 29 |
|
| 30 |
go func() { |
| 31 |
io.Copy(os.Stdout, conn) |
| 32 |
os.Exit(0) |
| 33 |
}() |
| 34 |
io.Copy(conn, os.Stdin) |
| 35 |
os.Exit(0) |
| 36 |
} |