66 "net"
77 "os"
88 "strings"
9+ "text/tabwriter"
910
1011 ms "github.com/shadowy-pycoder/mshark"
1112)
@@ -31,15 +32,18 @@ Options:
3132`
3233
3334func displayInterfaces () error {
35+ w := new (tabwriter.Writer )
36+ w .Init (os .Stdout , 0 , 0 , 2 , ' ' , tabwriter .TabIndent )
3437 ifaces , err := net .Interfaces ()
3538 if err != nil {
3639 return fmt .Errorf ("failed to get network interfaces: %v" , err )
3740 }
38- fmt .Println ("0. any" )
41+ fmt .Fprintln (w , "Index\t Name\t Flags" )
42+ fmt .Fprintln (w , "0\t any\t UP" )
3943 for _ , iface := range ifaces {
40- fmt .Printf ( "%d. %s %s\n " , iface .Index , iface .Name , strings .ToUpper (iface .Flags .String ()))
44+ fmt .Fprintf ( w , "%d\t %s \t %s\n " , iface .Index , iface .Name , strings .ToUpper (iface .Flags .String ()))
4145 }
42- return nil
46+ return w . Flush ()
4347}
4448
4549func root (args []string ) error {
@@ -48,19 +52,18 @@ func root(args []string) error {
4852 flags := flag .NewFlagSet ("mshark" , flag .ExitOnError )
4953 flags .StringVar (& conf .Iface , "i" , "any" , "The name of the network interface. Example: eth0" )
5054 flags .IntVar (& conf .Snaplen , "s" , 0 , "The maximum length of each packet snapshot. Defaults to 65535." )
51- flags .BoolFunc ("p" , `Promiscuous mode. This setting is ignored for "any" interface.` , func (flagValue string ) error {
55+ flags .BoolFunc ("p" , `Promiscuous mode. This setting is ignored for "any" interface. Defaults to false. ` , func (flagValue string ) error {
5256 conf .Promisc = true
5357 return nil
5458 })
5559 flags .DurationVar (& conf .Timeout , "t" , 0 , "The maximum duration of the packet capture process. Example: 5s" )
5660 flags .IntVar (& conf .PacketCount , "c" , 0 , "The maximum number of packets to capture." )
5761 flags .StringVar (& conf .Expr , "e" , "" , `BPF filter expression. Example: "ip proto tcp"` )
58- flags .StringVar (& conf .Path , "f" , "" , "File path to write captured packet data to. Example: ./captured.txt " )
59- flags .BoolFunc ("pcap" , "Whether to create PCAP file." , func (flagValue string ) error {
62+ flags .StringVar (& conf .File , "f" , "" , "File path to write captured packet data to. Defaults to stdout. " )
63+ flags .BoolFunc ("pcap" , "Create a PCAP file in the current working directory ." , func (flagValue string ) error {
6064 conf .Pcap = true
6165 return nil
6266 })
63- flags .StringVar (& conf .PcapPath , "path" , "" , "Path to a PCAP file. Example: ./captured.pcap" )
6467 flags .BoolFunc ("D" , "Display list of interfaces and exit." , func (flagValue string ) error {
6568 if err := displayInterfaces (); err != nil {
6669 fmt .Fprintf (os .Stderr , "mshark: %v\n " , err )
0 commit comments