client: Additional counters for the statistics

Add more counters and start counting them when reading from the
PCAP library and when trying to write to the socket.

Change-Id: I52d3064a265b402ac849d8578a14f718156c0805
diff --git a/include/osmo-pcap/osmo_pcap_client.h b/include/osmo-pcap/osmo_pcap_client.h
index 3cc3080..90cd5ad 100644
--- a/include/osmo-pcap/osmo_pcap_client.h
+++ b/include/osmo-pcap/osmo_pcap_client.h
@@ -36,6 +36,8 @@
 	CLIENT_CTR_2BIG,
 	CLIENT_CTR_NOMEM,
 	CLIENT_CTR_QERR,
+	CLIENT_CTR_PERR,
+	CLIENT_CTR_WERR,
 };
 
 struct osmo_pcap_client {
diff --git a/src/osmo_client_core.c b/src/osmo_client_core.c
index 653d310..4455c95 100644
--- a/src/osmo_client_core.c
+++ b/src/osmo_client_core.c
@@ -1,7 +1,7 @@
 /*
  * osmo-pcap-client code
  *
- * (C) 2011 by Holger Hans Peter Freyther <zecke@selfish.org>
+ * (C) 2011-2016 by Holger Hans Peter Freyther <holger@moiji-mobile.com>
  * (C) 2011 by On-Waves
  * All Rights Reserved
  *
@@ -28,6 +28,7 @@
 #include <osmocom/gprs/protocol/gsm_08_16.h>
 #include <osmocom/gprs/protocol/gsm_08_18.h>
 
+#include <osmocom/core/rate_ctr.h>
 #include <osmocom/core/talloc.h>
 
 #include <netinet/in.h>
@@ -158,8 +159,10 @@
 	const u_char *data;
 
 	data = pcap_next(client->handle, &hdr);
-	if (!data)
+	if (!data) {
+		rate_ctr_inc(&client->ctrg->ctr[CLIENT_CTR_PERR]);
 		return -1;
+	}
 
 	if (!forward_packet(client, &hdr, data))
 		return 0;
diff --git a/src/osmo_client_main.c b/src/osmo_client_main.c
index 945a871..0b53939 100644
--- a/src/osmo_client_main.c
+++ b/src/osmo_client_main.c
@@ -60,6 +60,8 @@
 	[CLIENT_CTR_2BIG]		= { "bpf.too_big",		"Captured data too big " },
 	[CLIENT_CTR_NOMEM]		= { "client.no_mem",		"No memory available   " },
 	[CLIENT_CTR_QERR]		= { "client.queue_err",		"Can not queue data    " },
+	[CLIENT_CTR_PERR]		= { "client.pcap_err",		"libpcap error         " },
+	[CLIENT_CTR_WERR]		= { "client.write_err",		"Write error           " },
 };
 
 static const struct rate_ctr_group_desc pcap_client_ctr_group_desc = {
diff --git a/src/osmo_client_network.c b/src/osmo_client_network.c
index 7812ff6..2400f3a 100644
--- a/src/osmo_client_network.c
+++ b/src/osmo_client_network.c
@@ -92,6 +92,7 @@
 	if (rc < 0) {
 		struct osmo_pcap_client *client = fd->data;
 		LOGP(DCLIENT, LOGL_ERROR, "Lost connection on write.\n");
+		rate_ctr_inc(&client->ctrg->ctr[CLIENT_CTR_WERR]);
 		lost_connection(client);
 		return -1;
 	}