Index: uspace/app/pcapcat/doc/doxygroups.h
===================================================================
--- uspace/app/pcapcat/doc/doxygroups.h	(revision caac05282f39a0eb12a799cdc11f53fa8229f95d)
+++ uspace/app/pcapcat/doc/doxygroups.h	(revision caac05282f39a0eb12a799cdc11f53fa8229f95d)
@@ -0,0 +1,4 @@
+/** @addtogroup pcapcat pcapcat
+ * @brief Command-line utility for printing files of PCAP format.
+ * @ingroup apps
+ */
Index: uspace/app/pcapcat/eth_parser.c
===================================================================
--- uspace/app/pcapcat/eth_parser.c	(revision 373dded90dc9bcf4b2a1a0f9262855a26421fe24)
+++ uspace/app/pcapcat/eth_parser.c	(revision caac05282f39a0eb12a799cdc11f53fa8229f95d)
@@ -27,18 +27,21 @@
  */
 
+/** @addtogroup pcapcat
+ * @{
+ */
+/** @file Implementation of functions for parsing PCAP file of LinkType 1 (LINKTYPE_ETHERNET).
+ */
 
 #include <stdint.h>
 #include <stdio.h>
 #include <stdlib.h>
-#include <time.h>
 #include <stdbool.h>
-#include <errno.h>
 #include <str.h>
-#include <io/log.h>
-#include "pcap.h"
+#include <pcap.h>
 #include "eth_parser.h"
 
 #define ETH_ADDR_SIZE       6
 #define IPV4_ADDR_SIZE      4
+#define TCP_PORT_SIZE       2
 
 #define ETHER_TYPE_ARP      0x0806
@@ -47,4 +50,6 @@
 
 #define BYTE_SIZE           8
+#define HDR_SIZE_COEF       4
+#define LOWER_4_BITS        0xf
 
 #define IP_PROTOCOL_TCP     0x06
@@ -58,4 +63,5 @@
 #define IPV4_TEXT           "IPv4"
 #define IPV6_TEXT           "IPv6"
+#define MALFORMED_PACKET    "packet is malformed.\n"
 
 #define PRINT_IP(msg, ip_addr, spaces) printf("%s %s: %d.%d.%d.%d%s", msg, IP_TEXT, ip_addr[0], ip_addr[1], ip_addr[2], ip_addr[3], spaces)
@@ -63,14 +69,32 @@
 #define BIG_END_16(buffer, idx) buffer[idx] << BYTE_SIZE | buffer[idx + 1]
 
-
-static void read_from_buffer(unsigned char *buffer, int start_idx, int count, uint8_t *dst)
-{
-    for (int i = start_idx; i < start_idx + count; ++i) {
+/** Read count bytes from char buffer.
+ *  @param buffer       of bytes to read from.
+ *  @param start_idx    index of the first byte to read.
+ *  @param count        number of byte to read.
+ *  @param dst          destination buffer.
+ */
+static void read_from_buffer(unsigned char *buffer, size_t start_idx, size_t count, uint8_t *dst)
+{
+    for (size_t i = start_idx; i < start_idx + count; ++i) {
         dst[i - start_idx] = buffer[i];
     }
 }
 
-static void parse_arp(unsigned char *byte_source, size_t size)
-{
+/** Parse ARP packet and print out addresses.
+ *  @param buffer   ARP packet.
+ *  @param size     Size of the packet.
+ */
+static void parse_arp(unsigned char *buffer, size_t size)
+{
+    size_t sender_mac_offset = 22;
+    size_t sender_ip_offset = 28;
+    size_t target_mac_offset = 32;
+    size_t target_ip_offset = 38;
+    if (size < target_ip_offset + IPV4_ADDR_SIZE) {
+        printf("%s %s", ARP_TEXT, MALFORMED_PACKET);
+        return;
+    }
+
     uint8_t sender_mac[ETH_ADDR_SIZE];
     uint8_t sender_ip[IPV4_ADDR_SIZE];
@@ -78,8 +102,8 @@
     uint8_t target_ip[IPV4_ADDR_SIZE];
 
-    read_from_buffer(byte_source, 22, ETH_ADDR_SIZE, sender_mac);
-    read_from_buffer(byte_source, 28, IPV4_ADDR_SIZE, sender_ip);
-    read_from_buffer(byte_source, 32, ETH_ADDR_SIZE, target_mac);
-    read_from_buffer(byte_source, 36, IPV4_ADDR_SIZE, target_ip);
+    read_from_buffer(buffer, sender_mac_offset, ETH_ADDR_SIZE, sender_mac);
+    read_from_buffer(buffer, sender_ip_offset, IPV4_ADDR_SIZE, sender_ip);
+    read_from_buffer(buffer, target_mac_offset, ETH_ADDR_SIZE, target_mac);
+    read_from_buffer(buffer, target_ip_offset, IPV4_ADDR_SIZE, target_ip);
 
     PRINT_MAC("Sender", sender_mac, ", ");
@@ -87,15 +111,31 @@
     PRINT_MAC("Target", target_mac, ", ");
     PRINT_IP("Target", target_ip, "\n");
-
-}
-
-static void parse_tcp(unsigned char *byte_source, size_t size)
-{
-    uint16_t src_port = BIG_END_16(byte_source, 34);
-    uint16_t dst_port = BIG_END_16(byte_source, 36);
+}
+
+/** Parce TCP and print ports.
+ *  @param buffer   TCP segment.
+ *  @param size     of the buffer.
+ */
+static void parse_tcp(unsigned char *buffer, size_t size)
+{
+    size_t src_port_offset = 34;
+    size_t dst_port_offset = 36;
+
+    if (size < dst_port_offset + TCP_PORT_SIZE) {
+        printf("%s %s\n", TCP_TEXT, MALFORMED_PACKET);
+        return;
+    }
+
+    uint16_t src_port = BIG_END_16(buffer, src_port_offset);
+    uint16_t dst_port = BIG_END_16(buffer, dst_port_offset);
     printf("      [%s] source port: %d, destination port: %d\n", TCP_TEXT, src_port, dst_port);
 }
 
-static void parse_ip(unsigned char *byte_source, size_t size, bool verbose)
+/** Parse IP and print interesting parts.
+ *  @param buffer   IP packet.
+ *  @param size     size of the buffer.
+ *  @param verbose  verbosity flag.
+ */
+static void parse_ip(unsigned char *buffer, size_t size, bool verbose)
 {
     uint16_t total_length;
@@ -106,11 +146,22 @@
     uint8_t dst_ip[IPV4_ADDR_SIZE];
 
-    header_length = (byte_source[14] & 0xf) * 4;
-    total_length = BIG_END_16(byte_source, 16);
+    size_t hdr_length_offset = 14;
+    size_t total_len_offset = 16;
+    size_t protocol_offset = 23;
+    size_t src_ip_offset = 26;
+    size_t dst_ip_offset = 30;
+
+    if (size < dst_ip_offset + IPV4_ADDR_SIZE) {
+        printf("%s %s", IP_TEXT, MALFORMED_PACKET);
+        return;
+    }
+
+    header_length = (buffer[hdr_length_offset] & LOWER_4_BITS) * HDR_SIZE_COEF;
+    total_length = BIG_END_16(buffer, total_len_offset);
     payload_length = total_length - header_length;
-    ip_protocol = byte_source[23];
-
-    read_from_buffer(byte_source, 26, IPV4_ADDR_SIZE, src_ip);
-    read_from_buffer(byte_source, 28, IPV4_ADDR_SIZE, dst_ip);
+    ip_protocol = buffer[protocol_offset];
+
+    read_from_buffer(buffer, src_ip_offset, IPV4_ADDR_SIZE, src_ip);
+    read_from_buffer(buffer, dst_ip_offset, IPV4_ADDR_SIZE, dst_ip);
 
     printf("%s header: %dB, payload: %dB, protocol: 0x%x, ", IP_TEXT, header_length, payload_length, ip_protocol);
@@ -119,22 +170,28 @@
 
     if (verbose && ip_protocol == IP_PROTOCOL_TCP) {
-        parse_tcp(byte_source, size);
-    }
-}
-
-static void parse_eth_packet(void *data, size_t size, bool verbose_flag)
-{
-    unsigned char* byte_source = (unsigned char*)data;
-
-    uint16_t protocol = BIG_END_16(byte_source, 12);
+        parse_tcp(buffer, size);
+    }
+}
+
+/** Parse ethernnet frame based on eth_type of the frame.
+ *  @param data         Ethernet frame.
+ *  @param size         Size of the frame.
+ *  @param verbose_flag Verbosity flag.
+ */
+static void parse_eth_frame(void *data, size_t size, bool verbose_flag)
+{
+    unsigned char* buffer = (unsigned char*)data;
+
+    size_t eth_type_offset = 12;
+    uint16_t protocol = BIG_END_16(buffer, eth_type_offset);
 
     switch (protocol){
         case ETHER_TYPE_ARP:
             printf("[%s] ", ARP_TEXT);
-            parse_arp(byte_source, size);
+            parse_arp(buffer, size);
             break;
         case ETHER_TYPE_IP4:
             printf("[%s] ", IPV4_TEXT);
-            parse_ip(byte_source, size, verbose_flag);
+            parse_ip(buffer, size, verbose_flag);
             break;
         case ETHER_TYPE_IP6:
@@ -147,4 +204,7 @@
 }
 
+/** Parse file header of PCAP file.
+ *  @param hdr  PCAP header structure.
+ */
 void eth_parse_header(pcap_file_header_t *hdr)
 {
@@ -153,9 +213,14 @@
 }
 
-void eth_parse_packets(FILE *f, int count, bool verbose_flag)
+/** Parse PCAP file.
+ *  @param pcap_file    file of PCAP format with dumped packets.
+ *  @param count        number of packets to be parsed and printed from file (if -1 all packets are printed).
+ *  @param verbose_flag verbosity flag.
+ */
+void eth_parse_frames(FILE *pcap_file, int count, bool verbose_flag)
 {
     pcap_packet_header_t hdr;
 
-    size_t read_bytes = fread(&hdr, 1, sizeof(pcap_packet_header_t), f);
+    size_t read_bytes = fread(&hdr, 1, sizeof(pcap_packet_header_t), pcap_file);
     int packet_index = 1;
     while (read_bytes > 0)
@@ -169,13 +234,13 @@
 
         void *data = malloc(hdr.captured_length);
-        read_bytes = fread(data, 1, (size_t)hdr.captured_length, f);
+        read_bytes = fread(data, 1, (size_t)hdr.captured_length, pcap_file);
         if (read_bytes < (size_t)hdr.captured_length) {
             printf("Error: Could not read enough bytes (read %zu bytes)\n", read_bytes);
             return;
         }
-        parse_eth_packet(data, (size_t)hdr.captured_length, verbose_flag);
+        parse_eth_frame(data, (size_t)hdr.captured_length, verbose_flag);
         free(data);
 
-        //Read first count packets
+        //Read first count packets from file.
         if (count != -1 && count == packet_index - 1) {
             return;
@@ -183,7 +248,10 @@
 
         memset(&hdr, 0, sizeof(pcap_packet_header_t));
-        read_bytes = fread(&hdr, 1, sizeof(pcap_packet_header_t), f);
-    }
-
-    fclose(f);
-}
+        read_bytes = fread(&hdr, 1, sizeof(pcap_packet_header_t), pcap_file);
+    }
+
+    fclose(pcap_file);
+}
+
+/** @}
+ */
Index: uspace/app/pcapcat/eth_parser.h
===================================================================
--- uspace/app/pcapcat/eth_parser.h	(revision 373dded90dc9bcf4b2a1a0f9262855a26421fe24)
+++ uspace/app/pcapcat/eth_parser.h	(revision caac05282f39a0eb12a799cdc11f53fa8229f95d)
@@ -27,4 +27,9 @@
  */
 
+/** @addtogroup pcapcat
+ * @{
+ */
+/** @file Functions for parsing PCAP file of LinkType 1 (LINKTYPE_ETHERNET).
+ */
 
 #include <stdint.h>
@@ -35,7 +40,9 @@
 #include <errno.h>
 #include <str.h>
-#include <io/log.h>
 #include <pcap.h>
 
-extern void eth_parse_packets(FILE *, int, bool);
+extern void eth_parse_frames(FILE *, int, bool);
 extern void eth_parse_header(pcap_file_header_t *);
+
+/** @}
+ */
Index: uspace/app/pcapcat/linktype_parser.h
===================================================================
--- uspace/app/pcapcat/linktype_parser.h	(revision 373dded90dc9bcf4b2a1a0f9262855a26421fe24)
+++ uspace/app/pcapcat/linktype_parser.h	(revision caac05282f39a0eb12a799cdc11f53fa8229f95d)
@@ -27,14 +27,14 @@
  */
 
-#include <stdint.h>
-#include <stdio.h>
+/** @addtogroup pcapcat
+ * @{
+ */
+/** @file Structure for parsing PCAP file.
+ */
+
 #include <stdlib.h>
-#include <time.h>
 #include <stdbool.h>
-#include <errno.h>
 #include <str.h>
-#include <io/log.h>
 #include <pcap.h>
-
 
 typedef struct {
@@ -43,2 +43,5 @@
     void (*parse_packets)(FILE *, int, bool);
 } linktype_parser_t;
+
+/** @}
+ */
Index: uspace/app/pcapcat/main.c
===================================================================
--- uspace/app/pcapcat/main.c	(revision 373dded90dc9bcf4b2a1a0f9262855a26421fe24)
+++ uspace/app/pcapcat/main.c	(revision caac05282f39a0eb12a799cdc11f53fa8229f95d)
@@ -45,5 +45,5 @@
 
 static const linktype_parser_t eth_parser = {
-    .parse_packets = &eth_parse_packets,
+    .parse_packets = &eth_parse_frames,
     .parse_file_header = &eth_parse_header,
     .linktype = PCAP_LINKTYPE_ETHERNET
Index: uspace/app/pcapctl/doc/doxygroups.h
===================================================================
--- uspace/app/pcapctl/doc/doxygroups.h	(revision 373dded90dc9bcf4b2a1a0f9262855a26421fe24)
+++ uspace/app/pcapctl/doc/doxygroups.h	(revision caac05282f39a0eb12a799cdc11f53fa8229f95d)
@@ -1,4 +1,4 @@
 /** @addtogroup pcapctl pcapctl
- * @brief Dump network packets
+ * @brief Command-line utility for dumping packets.
  * @ingroup apps
  */
Index: uspace/lib/pcap/include/pcap.h
===================================================================
--- uspace/lib/pcap/include/pcap.h	(revision 373dded90dc9bcf4b2a1a0f9262855a26421fe24)
+++ uspace/lib/pcap/include/pcap.h	(revision caac05282f39a0eb12a799cdc11f53fa8229f95d)
@@ -95,5 +95,5 @@
 };
 
-extern void pcap_writer_add_header(pcap_writer_t *writer, uint32_t linktype, bool nano);
+extern void pcap_writer_add_header(pcap_writer_t *writer, uint32_t linktype);
 extern void pcap_writer_add_packet(pcap_writer_t *writer, const void *captured_packet, size_t size);
 extern void pcap_set_time(pcap_packet_header_t *header);
Index: uspace/lib/pcap/src/pcap.c
===================================================================
--- uspace/lib/pcap/src/pcap.c	(revision 373dded90dc9bcf4b2a1a0f9262855a26421fe24)
+++ uspace/lib/pcap/src/pcap.c	(revision caac05282f39a0eb12a799cdc11f53fa8229f95d)
@@ -48,5 +48,5 @@
 	getrealtime(&ts);
 	header->seconds_stamp = (uint32_t)ts.tv_sec;
-	header->magic_stamp = (uint32_t)ts.tv_nsec;
+	header->magic_stamp = (uint32_t)ts.tv_sec / 1000;
 }
 
@@ -55,13 +55,8 @@
  * @param writer 	Writer that has destination buffer and ops to write to destination buffer.
  * @param linktype 	Linktype for the file header.
- * @param nano 		True for nanoseconds, false for microseconds in timestamp.
  */
-void pcap_writer_add_header(pcap_writer_t *writer, uint32_t linktype, bool nano)
+void pcap_writer_add_header(pcap_writer_t *writer, uint32_t linktype)
 {
-	uint32_t magic_version = PCAP_MAGIC_MICRO;
-	if (nano) {
-		magic_version = PCAP_MAGIC_NANO;
-	}
-	pcap_file_header_t file_header = { magic_version, PCAP_MAJOR_VERSION, PCAP_MINOR_VERSION,
+	pcap_file_header_t file_header = { (uint32_t)PCAP_MAGIC_MICRO, PCAP_MAJOR_VERSION, PCAP_MINOR_VERSION,
 		0x00000000, 0x00000000, (uint32_t)PCAP_SNAP_LEN, linktype };
 	writer->ops->write_buffer(writer, &file_header, sizeof(file_header));
Index: uspace/lib/pcap/src/pcap_dumper.c
===================================================================
--- uspace/lib/pcap/src/pcap_dumper.c	(revision 373dded90dc9bcf4b2a1a0f9262855a26421fe24)
+++ uspace/lib/pcap/src/pcap_dumper.c	(revision caac05282f39a0eb12a799cdc11f53fa8229f95d)
@@ -60,5 +60,5 @@
 		return EINVAL;
 	}
-	pcap_writer_add_header(writer, (uint32_t)PCAP_LINKTYPE_ETHERNET, false);
+	pcap_writer_add_header(writer, (uint32_t)PCAP_LINKTYPE_ETHERNET);
 
 	return EOK;
@@ -98,5 +98,5 @@
 		return EINVAL;
 	}
-	pcap_writer_add_header(writer, (uint32_t)PCAP_LINKTYPE_USB_LINUX_MMAPPED, false);
+	pcap_writer_add_header(writer, (uint32_t)PCAP_LINKTYPE_USB_LINUX_MMAPPED);
 
 	return EOK;
