Index: uspace/app/pcapctl/main.c
===================================================================
--- uspace/app/pcapctl/main.c	(revision 2ebbe9ba6bf8e1d1f1d39270fe8a4831f8dc9d9e)
+++ uspace/app/pcapctl/main.c	(revision 9e26790315ede55ef39bed61bf7491e61e392b37)
@@ -36,4 +36,6 @@
 #include <str.h>
 #include <errno.h>
+#include <arg_parse.h>
+#include <getopt.h>
 
 #include "pcapctl_dump.h"
@@ -42,10 +44,8 @@
 #define DEFAULT_DEV_NUM 0
 
-//pcapctl_sess_t* sess = NULL;
-
-static errno_t start_dumping(const char *svc_name, const char *name)
+static errno_t start_dumping(int *dev_number, const char *name)
 {
 	pcapctl_sess_t *sess = NULL;
-	errno_t rc = pcapctl_dump_open(svc_name, &sess);
+	errno_t rc = pcapctl_dump_open(dev_number, &sess);
 	if (rc != EOK) {
 		return 1;
@@ -57,9 +57,8 @@
 }
 
-/** Session might */
-static errno_t stop_dumping(const char *svc_name)
+static errno_t stop_dumping(int *dev_number)
 {
 	pcapctl_sess_t *sess = NULL;
-	errno_t rc = pcapctl_dump_open(svc_name, &sess);
+	errno_t rc = pcapctl_dump_open(dev_number, &sess);
 	if (rc != EOK) {
 		return 1;
@@ -75,10 +74,23 @@
 }
 
+/**
+ * Array of supported commandline options
+ */
+static const struct option opts[] = {
+	{ "device", required_argument, 0, 'd' },
+	{ "list", no_argument, 0, 'l' },
+	{ "help", no_argument, 0, 'h' },
+	{ "outfile", required_argument, 0, 'f' },
+	{ "start", no_argument, 0, 'r' },
+	{ "stop", no_argument, 0, 't' },
+	{ 0, 0, 0, 0 }
+};
+
 static void usage(void)
 {
 	printf("Usage:\n"
-	    NAME " list \n"
+	    NAME " --list | -l \n"
 	    "\tList of devices\n"
-	    NAME " start --device= | -d <device number from list> <outfile>\n"
+	    NAME " start --device= | -d <device number from list> --outfile | -f <outfile>\n"
 	    "\tPackets dumped from device will be written to <outfile>\n"
 	    NAME " stop --device= | -d <device>\n"
@@ -92,46 +104,53 @@
 int main(int argc, char *argv[])
 {
-	if (argc < 2) {
+	bool start = false;
+	bool stop = false;
+	int dev_number = DEFAULT_DEV_NUM;
+	const char *output_file_name;
+	int idx = 0;
+	int ret = 0;
+	if (argc == 1) {
 		usage();
-		return 1;
-	} else {
-		/** help */
-		if (str_cmp(argv[1], "--help") == 0 || str_cmp(argv[1], "-h") == 0) {
+		return 0;
+	}
+	while (ret != -1) {
+		ret = getopt_long(argc, argv, "d:lhf:rt", opts, &idx);
+		switch (ret) {
+		case 'd':
+			char *rest;
+			long result = strtol(optarg, &rest, 10);
+			dev_number = (int)result;
+			errno_t rc = pcapctl_is_valid_device(&dev_number);
+			if (rc != EOK) {
+				printf("Device with index %d not found\n", dev_number);
+				return 1;
+			}
+			break;
+		case 'l':
+			list_devs();
+			return 0;
+		case 'h':
 			usage();
 			return 0;
-			/** list */
-		} else if (str_cmp(argv[1], "list") == 0) {
-			list_devs();
-			return 0;
-			/** start with/out devnum */
-		} else if (str_cmp(argv[1], "start") == 0) {
-			if (argc == 3) {
-				start_dumping((char *)"0", argv[2]);
-				return 0;
-			} else if (argc == 4) {
-				start_dumping(argv[2], argv[3]);
-				return 0;
-			} else {
-				usage();
-				return 1;
-			}
-			/** Stop with/out devnum */
-		} else if (str_cmp(argv[1], "stop") == 0) {
-			if (argc == 2) {
-				stop_dumping((char *)"0");
-				fprintf(stdout, "Dumping was stopped\n");
-				return 0;
-			} else if (argc == 3) {
+		case 'f':
+			output_file_name = optarg;
+			break;
+		case 'r':
+			start = true;
+			break;
+		case 't':
+			stop = true;
+			break;
+		}
+	}
 
-				stop_dumping(argv[2]);
-				fprintf(stdout, "Dumping was stopped\n");
-			} else {
-				usage();
-				return 1;
-			}
-		} else {
-			usage();
-			return 1;
-		}
+	printf("%s: HelenOS Packet Dumping utility: device - %d\n", NAME, dev_number);
+
+	if (start) {
+		// start with dev number and optional..name
+		start_dumping(&dev_number, output_file_name);
+	} else if (stop) {
+		//stop with dev number
+		stop_dumping(&dev_number);
 	}
 	return 0;
Index: uspace/lib/pcap/include/pcapctl_dump.h
===================================================================
--- uspace/lib/pcap/include/pcapctl_dump.h	(revision 2ebbe9ba6bf8e1d1f1d39270fe8a4831f8dc9d9e)
+++ uspace/lib/pcap/include/pcapctl_dump.h	(revision 9e26790315ede55ef39bed61bf7491e61e392b37)
@@ -49,9 +49,10 @@
 } pcapctl_sess_t;
 
-extern errno_t pcapctl_dump_open(const char *svcname, pcapctl_sess_t **rsess);
+extern errno_t pcapctl_dump_open(int *, pcapctl_sess_t **rsess);
 extern errno_t pcapctl_dump_close(pcapctl_sess_t *sess);
 extern errno_t pcapctl_dump_start(const char *, pcapctl_sess_t *);
 extern errno_t pcapctl_dump_stop(pcapctl_sess_t *);
 extern errno_t pcapctl_list(void);
+extern errno_t pcapctl_is_valid_device(int *);
 
 #endif
Index: uspace/lib/pcap/src/pcapctl_dump.c
===================================================================
--- uspace/lib/pcap/src/pcapctl_dump.c	(revision 2ebbe9ba6bf8e1d1f1d39270fe8a4831f8dc9d9e)
+++ uspace/lib/pcap/src/pcapctl_dump.c	(revision 9e26790315ede55ef39bed61bf7491e61e392b37)
@@ -43,21 +43,4 @@
 #include "pcapdump_iface.h"
 
-//static service_id_t *pcap_svcs = NULL; ??
-
-static errno_t str2num(const char *str, size_t *number)
-{
-	size_t num = 0;
-	if (*str == 0)
-		return ELIMIT;
-	if (!isdigit(*str))
-		return EINVAL;
-	while (isdigit(*str)) {
-		num = num * 10 + ((*str) - '0');
-		str++;
-	}
-
-	*number = num;
-	return EOK;
-}
 /** Finish an async exchange on the pcapctl session
  *
@@ -69,5 +52,5 @@
 }
 
-static errno_t pcapctl_cat_get_svc(const char *drv_name, service_id_t *svc)
+static errno_t pcapctl_cat_get_svc(int *index, service_id_t *svc)
 {
 	errno_t rc;
@@ -85,19 +68,44 @@
 	if (rc != EOK) {
 		printf("Error resolving list of pcap services.\n");
-		return rc;
-	}
-
-	for (unsigned i = 0; i < count; ++i) {
-		char *name = NULL;
-		loc_service_get_name(pcap_svcs[i], &name);
-		if (!str_cmp(drv_name, name)) {
-			*svc =  pcap_svcs[i];
-			return EOK;
-		}
-	}
-	free(pcap_svcs);
-	return 1;
-}
-
+		free(pcap_svcs);
+		return rc;
+	}
+	if (*index < (int)count) {
+		*svc =  pcap_svcs[*index];
+		free(pcap_svcs);
+		return EOK;
+	}
+
+	return ENOENT;
+}
+
+errno_t pcapctl_is_valid_device(int *index)
+{
+	errno_t rc;
+	category_id_t pcap_cat;
+	size_t count;
+	service_id_t *pcap_svcs = NULL;
+
+	rc = loc_category_get_id("pcap", &pcap_cat, 0);
+	if (rc != EOK) {
+		printf("Error resolving category pcap.\n");
+		return rc;
+	}
+
+	rc = loc_category_get_svcs(pcap_cat, &pcap_svcs, &count);
+	if (rc != EOK) {
+		printf("Error resolving list of pcap services.\n");
+		free(pcap_svcs);
+		return rc;
+	}
+	if (*index + 1 > (int)count || *index < 0) {
+		return EINVAL;
+	}
+	return EOK;
+}
+
+/**
+ *
+ */
 errno_t pcapctl_list(void)
 {
@@ -130,51 +138,8 @@
 }
 
-static errno_t pcapctl_get_name_from_number(const char *svcnum, const char **svcname)
-{
-	errno_t rc;
-	category_id_t pcap_cat;
-	size_t count;
-	service_id_t *pcap_svcs = NULL;
-
-	rc = loc_category_get_id("pcap", &pcap_cat, 0);
-	if (rc != EOK) {
-		printf("Error resolving category pcap.\n");
-		return rc;
-	}
-	size_t num;
-	rc = str2num(svcnum, &num);
-	if (rc != EOK) {
-		printf("Error converting char* to size_t.\n");
-		free(pcap_svcs);
-		return rc;
-	}
-
-	rc = loc_category_get_svcs(pcap_cat, &pcap_svcs, &count);
-	if (rc != EOK) {
-		printf("Error resolving list of pcap services.\n");
-		free(pcap_svcs);
-		return rc;
-	}
-
-	if (num >= count) {
-		printf("Error finding device: no device with such number\n");
-		free(pcap_svcs);
-		return EINVAL;
-	}
-	char *name = NULL;
-	rc = loc_service_get_name(pcap_svcs[num], &name);
-	if (rc != EOK) {
-		printf("Error resolving name");
-	}
-
-	*svcname = name;
-	printf("%s\n", *svcname);
-	return EOK;
-}
-
 /**
  *
  */
-errno_t pcapctl_dump_open(const char *svcnum, pcapctl_sess_t **rsess)
+errno_t pcapctl_dump_open(int *index, pcapctl_sess_t **rsess)
 {
 	errno_t rc;
@@ -184,15 +149,10 @@
 		return ENOMEM;
 
-	const char *svcname;
-
-	rc = pcapctl_get_name_from_number(svcnum, &svcname);
-	if (rc != EOK) {
-		return rc;
-	}
-
-	rc  = pcapctl_cat_get_svc(svcname, &svc);
-	if (rc != EOK) {
+	rc  = pcapctl_cat_get_svc(index, &svc);
+	if (rc != EOK) {
+		printf("Error finding the device with index: %d\n", *index);
 		goto error;
 	}
+
 	async_sess_t *new_session = loc_service_connect(svc, INTERFACE_PCAP_CONTROL, 0);
 	if (new_session == NULL) {
