-
Notifications
You must be signed in to change notification settings - Fork 411
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Dup2() is not available on these platforms
Fall-back to lesser implementations.
- Loading branch information
Showing
3 changed files
with
80 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Copyright 2019-2020 Graham Clark. All rights reserved. Use of this source | ||
// code is governed by the MIT license that can be found in the LICENSE | ||
// file. | ||
|
||
package system | ||
|
||
import ( | ||
"os" | ||
"os/exec" | ||
"syscall" | ||
|
||
log "github.com/sirupsen/logrus" | ||
) | ||
|
||
//====================================================================== | ||
|
||
// DumpcapExt will run dumpcap first, but if it fails, run tshark. Intended as | ||
// a special case to allow termshark -i <iface> to use dumpcap if possible, | ||
// but if it fails (e.g. iface==randpkt), fall back to tshark. dumpcap is more | ||
// efficient than tshark at just capturing, and will drop fewer packets, but | ||
// tshark supports extcap interfaces. | ||
func DumpcapExt(dumpcapBin string, tsharkBin string, args ...string) error { | ||
var err error | ||
|
||
dumpcapCmd := exec.Command(dumpcapBin, args...) | ||
log.Infof("Starting dumpcap command %v", dumpcapCmd) | ||
dumpcapCmd.Stdin = os.Stdin | ||
dumpcapCmd.Stdout = os.Stdout | ||
dumpcapCmd.Stderr = os.Stderr | ||
if dumpcapCmd.Run() != nil { | ||
var tshark string | ||
tshark, err = exec.LookPath(tsharkBin) | ||
if err == nil { | ||
log.Infof("Retrying with dumpcap command %v", append([]string{tshark}, args...)) | ||
err = syscall.Exec(tshark, append([]string{tshark}, args...), os.Environ()) | ||
} | ||
} | ||
|
||
return err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// Copyright 2019-2020 Graham Clark. All rights reserved. Use of this source | ||
// code is governed by the MIT license that can be found in the LICENSE | ||
// file. | ||
|
||
package system | ||
|
||
import ( | ||
"os" | ||
"os/exec" | ||
|
||
log "github.com/sirupsen/logrus" | ||
) | ||
|
||
//====================================================================== | ||
|
||
// DumpcapExt will run dumpcap first, but if it fails, run tshark. Intended as | ||
// a special case to allow termshark -i <iface> to use dumpcap if possible, | ||
// but if it fails (e.g. iface==randpkt), fall back to tshark. dumpcap is more | ||
// efficient than tshark at just capturing, and will drop fewer packets, but | ||
// tshark supports extcap interfaces. | ||
func DumpcapExt(dumpcapBin string, tsharkBin string, args ...string) error { | ||
dumpcapCmd := exec.Command(dumpcapBin, args...) | ||
log.Infof("Starting dumpcap command %v", dumpcapCmd) | ||
dumpcapCmd.Stdin = os.Stdin | ||
dumpcapCmd.Stdout = os.Stdout | ||
dumpcapCmd.Stderr = os.Stderr | ||
if dumpcapCmd.Run() == nil { | ||
return nil | ||
} | ||
|
||
tsharkCmd := exec.Command(tsharkBin, args...) | ||
log.Infof("Retrying with dumpcap command %v", tsharkCmd) | ||
tsharkCmd.Stdin = os.Stdin | ||
tsharkCmd.Stdout = os.Stdout | ||
tsharkCmd.Stderr = os.Stderr | ||
return tsharkCmd.Run() | ||
} |