Index: uspace/app/pcapctl/main.c
===================================================================
--- uspace/app/pcapctl/main.c	(revision 28ed2d895c391b0a614fa176129126725c0fac4b)
+++ uspace/app/pcapctl/main.c	(revision fb316822bc92404f7ec785477d173721f75b2232)
@@ -44,6 +44,10 @@
 #define NAME "pcapctl"
 #define DEFAULT_DEV_NUM 0
-#define DEFAULT_OPS_NUM 0
 #define DECIMAL_SYSTEM 10
+
+#define DEFAULT_FILE_OPS 0
+#define SHORT_FILE_OPS 1
+#define APPEND_FILE_OPS 2
+#define USB_FILE_OPS 3
 
 static errno_t start_dumping(int *dev_number, const char *name, int *ops_index)
@@ -56,6 +60,5 @@
 
 	rc = pcapctl_is_valid_ops_number(ops_index, sess);
-	if (rc != EOK)
-	{
+	if (rc != EOK) {
 		printf("Wrong number of ops: %d.\n", *ops_index);
 		pcapctl_dump_close(sess);
@@ -65,4 +68,7 @@
 	rc = pcapctl_dump_start(name, ops_index, sess);
 	if (rc != EOK) {
+		if (rc == EBUSY) {
+			printf("Dumping for device %d is in process, stop to start dumping to file %s.\n", *dev_number, name);
+		}
 		printf("Starting the dumping was not successful.\n");
 	}
@@ -95,4 +101,8 @@
  */
 static const struct option opts[] = {
+	{ "append", required_argument, 0, 'A' }, // file as argument and ops 0 if not exist and 2 if exists
+	{ "new", required_argument, 0, 'N' }, // file name as argument
+	{ "truncated", required_argument, 0, 'T' }, // truncated ops
+	{ "usb", required_argument, 0, 'U' }, //??
 	{ "device", required_argument, 0, 'd' },
 	{ "list", no_argument, 0, 'l' },
@@ -102,5 +112,5 @@
 	{ "stop", no_argument, 0, 't' },
 	{ "ops", required_argument, 0, 'p' },
-	{ "force", no_argument, 0, 'f'},
+	{ "force", no_argument, 0, 'f' },
 	{ 0, 0, 0, 0 }
 };
@@ -109,9 +119,9 @@
 {
 	vfs_stat_t stats;
-
-    if (vfs_stat_path(path, &stats) != EOK)
-        return false;
-
-    return true;
+	if (vfs_stat_path(path, &stats) != EOK) {
+		return false;
+	} else {
+		return true;
+	}
 }
 
@@ -121,12 +131,14 @@
 	    NAME " --list | -l \n"
 	    "\tList of devices\n"
-	    NAME " --start | -r --device= | -d <device number from list> --outfile= | -f <outfile>\n"
+	    NAME " --start | -r --device= | -d <device number from list> --outfile= | -o <outfile> --ops= | p <ops index>\n"
 	    "\tPackets dumped from device will be written to <outfile>\n"
-	    NAME " --stop | -t --device= | -d <device>\n"
+	    NAME " --stop | -t --device= | -d <device number from list>\n"
 	    "\tDumping from <device> stops\n"
-	    NAME " --start | -s --outfile= | -f <outfile>\n"
+	    NAME " --start | -r --outfile= | -o <outfile>\n"
 	    "\tPackets dumped from the 0. device from the list will be written to <outfile>\n"
 	    NAME " --help | -h\n"
-	    "\tShow this application help.\n");
+	    "\tShow this application help.\n"
+	    NAME " --force | -f"
+	    "\tTo open existing file and write to it.\n");
 }
 
@@ -136,5 +148,5 @@
 	bool stop = false;
 	int dev_number = DEFAULT_DEV_NUM;
-	int ops_number = DEFAULT_OPS_NUM;
+	int ops_number = DEFAULT_FILE_OPS;
 	bool forced = false;
 	const char *output_file_name = "";
@@ -146,5 +158,5 @@
 	}
 	while (ret != -1) {
-		ret = getopt_long(argc, argv, "d:lho:rtp:f", opts, &idx);
+		ret = getopt_long(argc, argv, "A:N:T:U:d:lho:rtp:f", opts, &idx);
 		switch (ret) {
 		case 'd':
@@ -158,4 +170,21 @@
 			}
 			break;
+		case 'A':
+			output_file_name = optarg;
+			if (file_exists(output_file_name)) {
+				ops_number = APPEND_FILE_OPS;
+			}
+			break;
+		case 'N':
+			output_file_name = optarg;
+			break;
+		case 'T':
+			output_file_name = optarg;
+			ops_number = SHORT_FILE_OPS;
+			break;
+		case 'U':
+			output_file_name = optarg;
+			ops_number = USB_FILE_OPS;
+			break;
 		case 'l':
 			list_devs();
@@ -174,5 +203,5 @@
 			break;
 		case 'p':
-			char* ops_inval;
+			char *ops_inval;
 			long ops_result = strtol(optarg, &ops_inval, DECIMAL_SYSTEM);
 			ops_number = (int)ops_result;
@@ -184,11 +213,15 @@
 	}
 
-	printf("%s: HelenOS Packet Dumping utility: device - %d.\n", NAME, dev_number);
+	if (!str_cmp(output_file_name, "") && start) {
+		printf("Dumping destination was not specified. Specify with --outfile | -o\n");
+		return 1;
+	}
+
+	printf("%s: HelenOS Packet Dumping utility: device - %d, ops - %d.\n", NAME, dev_number, ops_number);
 
 	if (start) {
 
-		if (file_exists(output_file_name) && !forced)
-		{
-			printf("File %s already exists. If you want to write to it, then use flag --force.\n", output_file_name);
+		if (file_exists(output_file_name) && !forced && ops_number != 2) {
+			printf("File %s already exists. If you want to overwrite to it, then use flag --force.\n", output_file_name);
 			return 0;
 		}
@@ -201,4 +234,5 @@
 	} else {
 		usage();
+		return 1;
 	}
 	return 0;
Index: uspace/lib/pcap/include/pcap_dumper.h
===================================================================
--- uspace/lib/pcap/include/pcap_dumper.h	(revision 28ed2d895c391b0a614fa176129126725c0fac4b)
+++ uspace/lib/pcap/include/pcap_dumper.h	(revision fb316822bc92404f7ec785477d173721f75b2232)
@@ -46,8 +46,8 @@
 } pcap_dumper_t;
 
+extern errno_t pcap_dumper_start(pcap_dumper_t *, const char *);
 extern void pcap_dumper_stop(pcap_dumper_t *);
 extern int pcap_dumper_get_ops_number(void);
 extern errno_t pcap_dumper_set_ops(pcap_dumper_t *, int);
-extern errno_t pcap_dumper_start(pcap_dumper_t *, const char *);
 extern void pcap_dumper_add_packet(pcap_dumper_t *, const void *data, size_t size);
 
Index: uspace/lib/pcap/include/pcapdump_client.h
===================================================================
--- uspace/lib/pcap/include/pcapdump_client.h	(revision 28ed2d895c391b0a614fa176129126725c0fac4b)
+++ uspace/lib/pcap/include/pcapdump_client.h	(revision fb316822bc92404f7ec785477d173721f75b2232)
@@ -56,6 +56,5 @@
 extern errno_t pcapctl_list(void);
 extern errno_t pcapctl_is_valid_device(int *);
-extern errno_t pcapctl_is_valid_ops_number(int *index, pcapctl_sess_t* sess);
-
+extern errno_t pcapctl_is_valid_ops_number(int *, pcapctl_sess_t *);
 
 #endif
Index: uspace/lib/pcap/src/pcap.c
===================================================================
--- uspace/lib/pcap/src/pcap.c	(revision 28ed2d895c391b0a614fa176129126725c0fac4b)
+++ uspace/lib/pcap/src/pcap.c	(revision fb316822bc92404f7ec785477d173721f75b2232)
@@ -59,6 +59,5 @@
 {
 	uint32_t magic_version = PCAP_MAGIC_MICRO;
-	if (nano)
-	{
+	if (nano) {
 		magic_version = PCAP_MAGIC_NANO;
 	}
Index: uspace/lib/pcap/src/pcap_dumper.c
===================================================================
--- uspace/lib/pcap/src/pcap_dumper.c	(revision 28ed2d895c391b0a614fa176129126725c0fac4b)
+++ uspace/lib/pcap/src/pcap_dumper.c	(revision fb316822bc92404f7ec785477d173721f75b2232)
@@ -39,5 +39,5 @@
 #include "pcap_dumper.h"
 
-#define SHORT_OPS_BYTE_COUNT 60
+#define SHORT_OPS_BYTE_COUNT 0x3C
 
 /** Initialize writing to .pcap file.
@@ -50,4 +50,11 @@
 static errno_t pcap_writer_to_file_init(pcap_writer_t *writer, const char *filename)
 {
+	/** For overwriting file if already exists. */
+	writer->data = fopen(filename, "w");
+	if (writer->data == NULL) {
+		return EINVAL;
+	}
+	fclose(writer->data);
+
 	writer->data = fopen(filename, "a");
 	if (writer->data == NULL) {
@@ -71,4 +78,11 @@
 static errno_t pcap_writer_to_file_usb_init(pcap_writer_t *writer, const char *filename)
 {
+	/** For overwriting file if already exists. */
+	writer->data = fopen(filename, "w");
+	if (writer->data == NULL) {
+		return EINVAL;
+	}
+	fclose(writer->data);
+
 	writer->data = fopen(filename, "a");
 	if (writer->data == NULL) {
@@ -140,5 +154,5 @@
 };
 
-static pcap_writer_ops_t ops[4] = {file_ops, short_file_ops, append_file_ops, usb_file_ops};
+static pcap_writer_ops_t ops[4] = { file_ops, short_file_ops, append_file_ops, usb_file_ops };
 
 int pcap_dumper_get_ops_number(void)
@@ -150,9 +164,4 @@
 {
 	fibril_mutex_lock(&dumper->mutex);
-
-	/** When try to start when already started, close current and starts new */
-	if (dumper->to_dump) {
-		pcap_dumper_stop(dumper);
-	}
 
 	errno_t rc = dumper->writer.ops->open(&dumper->writer, name);
@@ -201,6 +210,4 @@
 }
 
-
-
 /** @}
  */
Index: uspace/lib/pcap/src/pcapdump_client.c
===================================================================
--- uspace/lib/pcap/src/pcapdump_client.c	(revision 28ed2d895c391b0a614fa176129126725c0fac4b)
+++ uspace/lib/pcap/src/pcapdump_client.c	(revision fb316822bc92404f7ec785477d173721f75b2232)
@@ -105,6 +105,5 @@
 }
 
-
-errno_t pcapctl_is_valid_ops_number(int *index, pcapctl_sess_t* sess)
+errno_t pcapctl_is_valid_ops_number(int *index, pcapctl_sess_t *sess)
 {
 	async_exch_t *exch = async_exchange_begin(sess->sess);
@@ -122,6 +121,5 @@
 
 	int ops_count = (int)ipc_get_arg1(&answer);
-	if (*index + 1 > ops_count || *index < 0)
-	{
+	if (*index + 1 > ops_count || *index < 0) {
 		return EINVAL;
 	}
@@ -250,5 +248,4 @@
 }
 
-
 /** @}
  */
Index: uspace/lib/pcap/src/pcapdump_drv_iface.c
===================================================================
--- uspace/lib/pcap/src/pcapdump_drv_iface.c	(revision 28ed2d895c391b0a614fa176129126725c0fac4b)
+++ uspace/lib/pcap/src/pcapdump_drv_iface.c	(revision fb316822bc92404f7ec785477d173721f75b2232)
Index: uspace/lib/pcap/src/pcapdump_srv.c
===================================================================
--- uspace/lib/pcap/src/pcapdump_srv.c	(revision 28ed2d895c391b0a614fa176129126725c0fac4b)
+++ uspace/lib/pcap/src/pcapdump_srv.c	(revision fb316822bc92404f7ec785477d173721f75b2232)
@@ -60,7 +60,14 @@
 	assert(str_length(data) == size && "Data were damaged during transmission.\n");
 
+	// Deadlock solution when trying to start dump while dumping (to the same device)
+	if (dumper->to_dump) {
+		free(data);
+		log_msg(LOG_DEFAULT, LVL_ERROR, "Trying to start dumping while dumping.\n");
+		async_answer_0(icall, EBUSY);
+		return;
+	}
+
 	rc = pcap_dumper_set_ops(dumper, ops_index);
-	if (rc != EOK)
-	{
+	if (rc != EOK) {
 		log_msg(LOG_DEFAULT, LVL_DEBUG, "Setting ops for dumper was not successful.\n");
 		free(data);
@@ -82,5 +89,4 @@
 	async_answer_0(icall, EOK);
 }
-
 
 static void pcapdump_get_ops_num_srv(ipc_call_t *icall)
@@ -128,6 +134,4 @@
 }
 
-
-
 /** @}
  */
