Skip to content
Browse files

added command line options and help message

  • Loading branch information...
1 parent dd258c9 commit cdf12f5b97b37b2ab38e424bd6afc0954e2a6dbc @seuffert committed
Showing with 61 additions and 5 deletions.
  1. +61 −5 XBSlink/CommandLine.cs
View
66 XBSlink/CommandLine.cs
@@ -2,6 +2,8 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
+using System.Net;
+using System.Net.NetworkInformation;
using SharpPcap;
using SharpPcap.LibPcap;
@@ -29,15 +31,63 @@ public xbs_console_app(xbs_settings settings, String[] args)
AllocConsole();
xbs_settings = settings;
- output_version_info();
- switch (args[0])
+ bool cmd_help = false;
+ bool cmd_list_devices = false;
+ String option_nickname = null;
+ String option_cloudserver = null;
+ String option_cloudname = null;
+ bool option_upnp = false;
+ bool option_advanced_broadcast = false;
+ int option_local_port = 0;
+ IPAddress option_local_ip = null;
+ String option_capture_device = null;
+ OptionSet command_line_option_set = new OptionSet() {
+ { "h|help", "show this help message", v => cmd_help = v!=null },
+ { "l|list-devices", "list all available network packet capture devices", v => cmd_list_devices = v != null },
+ { "n|nickname=", "set the nickname", v => option_nickname=v },
+ { "s|cloudserver=", "set cloudserver URL", v => option_cloudserver=v },
+ { "c|cloudname=", "connect to this cloud", v => option_cloudname=v },
+ { "u|upnp", "use UPnP to forward incoming port", v => option_upnp = v!=null },
+ { "a|advanced-broadcast", "enable advanced forwarding of broadcasts", v => option_advanced_broadcast = v!=null },
+ { "p|port=", "set the incoming port number. default is 31415", (UInt16 v) => option_local_port = v },
+ { "o|source-ip=", "bind to this local ip address.", (String v) => option_local_ip=IPAddress.Parse(v) },
+ { "i|capture-device=", "name of network device for capturing packets", v => option_capture_device = v },
+ };
+ try
+ {
+ command_line_option_set.Parse(args);
+ }
+ catch (OptionException e)
+ {
+ command_line_parser_error(command_line_option_set, e);
+ return;
+ }
+ catch (System.FormatException e)
+ {
+ command_line_parser_error(command_line_option_set, e);
+ return;
+ }
+ if (!cmd_help && !cmd_list_devices && option_capture_device == null)
{
- case "--list-devices":
- list_Devices(args);
- break;
+ command_line_parser_error(command_line_option_set, new OptionException("you need to specify a capture device", "capture-device"));
+ return;
}
+ output_version_info();
+ if (cmd_help)
+ ShowHelp(command_line_option_set);
+ else if (cmd_list_devices)
+ list_Devices(args);
+
+ Console.ReadLine();
+ }
+
+ private void command_line_parser_error(OptionSet command_line_option_set, Exception e)
+ {
+ Console.WriteLine("!! Error parsing command line:");
+ Console.WriteLine("!! " + e.Message + Environment.NewLine);
+ ShowHelp(command_line_option_set);
Console.ReadLine();
}
@@ -61,5 +111,11 @@ private void output_version_info()
Console.WriteLine( Environment.NewLine+"XBSlink Version " + xbs_settings.xbslink_version);
}
+ private void ShowHelp(OptionSet command_line_option_set)
+ {
+ Console.WriteLine("Usage: XBSlink.exe [-h] [-l] [-n NICKNAME] [-s CLOUDSERVER] [-c CLOUDNAME] [-u] [-p PORT] [-o IP] -i CAPTURE_DEVICE_NAME");
+ command_line_option_set.WriteOptionDescriptions(Console.Out);
+ }
+
}
}

0 comments on commit cdf12f5

Please sign in to comment.
Something went wrong with that request. Please try again.