You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add functionality -N/-q to shutdown connection after stdin is
closed, analogous to the corresponding flags in BSD netcat.
Cleanup logging; use only one logger library, write logs to stderr (not
stdout). Simplify the different log levels, keep only debug or error
messages, and correspondingly only have a -v flag for for debug logs.
Integrate the netcat/modes/ subpackage into the main netcat package to
simplify the structure, and to share helper functions (for logging).
Copy file name to clipboardExpand all lines: netcat/main.go
+97-71Lines changed: 97 additions & 71 deletions
Original file line number
Diff line number
Diff line change
@@ -18,16 +18,12 @@ import (
18
18
"flag"
19
19
"fmt"
20
20
"io"
21
-
golog "log"
21
+
"log"
22
22
"os"
23
23
"os/exec"
24
24
"strconv"
25
25
"sync"
26
-
27
-
"github.com/netsec-ethz/scion-apps/netcat/modes"
28
-
scionlog "github.com/scionproto/scion/go/lib/log"
29
-
30
-
log "github.com/inconshreveable/log15"
26
+
"time"
31
27
)
32
28
33
29
var (
@@ -36,13 +32,14 @@ var (
36
32
37
33
udpModebool
38
34
39
-
repeatAfterbool
40
-
repeatDuringbool
35
+
repeatAfterbool
36
+
repeatDuringbool
37
+
shutdownAfterEOFbool
38
+
shutdownAfterEOFTimeout time.Duration
41
39
42
40
commandStringstring
43
41
44
-
verboseModebool
45
-
veryVerboseModebool
42
+
verboseModebool
46
43
)
47
44
48
45
funcprintUsage() {
@@ -58,74 +55,72 @@ func printUsage() {
58
55
fmt.Println(" -l: Listen mode")
59
56
fmt.Println(" -k: After the connection ended, accept new connections. Requires -l flag. If -u flag is present, requires -c flag. Incompatible with -K flag")
60
57
fmt.Println(" -K: After the connection has been established, accept new connections. Requires -l and -c flags. Incompatible with -k flag")
58
+
fmt.Println(" -N: shutdown the network socket after EOF on the input.")
59
+
fmt.Println(" -q: after EOF on stdin, wait the specified duration and then quit. Implies -N.")
61
60
fmt.Println(" -c: Instead of piping the connection to stdin/stdout, run the given command using /bin/sh")
62
61
fmt.Println(" -u: UDP mode")
63
62
fmt.Println(" -b: Send or expect an extra (throw-away) byte before the actual data")
64
63
fmt.Println(" -v: Enable verbose mode")
65
-
fmt.Println(" -vv: Enable very verbose mode")
66
64
}
67
65
68
66
funcmain() {
69
-
70
67
flag.Usage=printUsage
71
68
flag.BoolVar(&extraByte, "b", false, "Expect extra byte")
72
69
flag.BoolVar(&listen, "l", false, "Listen mode")
73
70
flag.BoolVar(&udpMode, "u", false, "UDP mode")
74
71
flag.BoolVar(&repeatAfter, "k", false, "Accept new connections after connection end")
0 commit comments