Posts

Programmatic Analysis of Wireshark Log Files using C#

Image
The other day, I wanted to perform some Wireshark filtering on a .pcap file to obtain a count of the packets found for a large number of IP addresses. I wanted to find out the number of tcp retransmissions for a specified IP address, as well as the count of TCP resets for each IP address. And finally, I wanted to get a count of the number of "keep alive" packets for each IP address. Okay, so this is pretty easy to perform in Wireshark . Just filter the traffic with the following filters: tcp.analysis.retransmission && ip.addr == 1.2.3.4 tcp.flags.reset == 1 && ip.addr == 1.2.3.4 tcp.analysis.keep_alive && ip.addr == 1.2.3.4 But I didn't want to go through the user interface for hundreds of different IP addresses. I wanted to do this programatically, in code. Now, there are a couple of different approaches you can take here depending on your requirements. At first I used PcapDotNet . This is a great library and you can walk the packets...

Using Redis as a Data Caching Server

Image
Everyone knows how important caching is in computing. We are surrounded by caching managers here, there and everywhere. You've got your CPU caching in the form of L1 and L2 cache which stores the next bit of data the CPU needs. GPUs have a cache. All hard drives come equipped with an on-board cache. Database servers heavily cache your most used queries and query plans, web servers cache the most used data and web clients (browsers) cache client side data. Basically, caching is everywhere. Why am I mentioning this? Well, recently I have been redesigning a framework that plans to make use of cached data to save trips to the database and Redis looks very enticing. But what's the cost/impact of not using a cache? Well, I found this great link "Latency Numbers Every Programmer Should Know" , which orders the latency numbers of accessing the "CPU cache" all the way up to connecting to a computer over the open internet. The numbers shouldn't s...

Code and Music

Do you listen to music when you code? I do. For me, there is no better experience of falling into a code-hole while being wisked away by a backing track of your liking. I find the two compliment each other. If you have a sufficiently meaty problem and an inkling of how you're going to solve it, music can sweep away time. You tumble down that code-hole and before you know it, you look up and a couple of hours have passed. Something happens in our brains, where your logic and reasoning about a problem develops to the point where you get a nice flow going. It's hard to explain but it happens. I am in no way precious about what type of music I listen to. In fact I listen to a lot of different genres but I find nothing compliments coding better than a DJ set. I love music (who doesn't). I collect music. I grew up being fed and watered on all types of dance music genres and back in the day, listening to the BBC Essential Mix was a staple! - In today's landscape ...

SeriLog & Application Diagnostic Logging

Image
Show me an application that doesn't log anything and i'll show you an application which is hard to debug. Every application we write should have a healthy sprinkling of diagnostic logging embedded throughout its logic. A trace to show us what's happening on the inside from the outside. In the past, I've hand-rolled my own bespoke logging classes to output either to file, database or simply console. Not any more! The problem has been solved. It's been done. There are libraries out there like Log4Net or Nlog But from now on, I intend to standardise all my C# code to use SeriLog . SeriLog is an example of a library where so many developers have poured in so much time that any home grown library cannot compete. Why waste your time? Just "nuget" it into your project and be done. Move on. Why is it so cool? Because it's simple. And because it supports many, many outputs. They call them sinks and there is a sink for everything as you ca...

Data Modelling and Diagramming Database Schemas

Image
So, I have recently been designing a schema for a new database system. As everyone knows, this is a technical process and requires a good understanding of the problem domain to make sure you collect all the business concepts and relationships. For these kind of things, you can't beat a good entity relationship diagram to visually see the makeup of your database tables and the relationships between them. This post is about the "Toad Data Modeller" application which is what I've been using to model my database design. It's such a great tool that I think it should be present in the toolbox of any DBA. Now, I know Microsoft includes a rudimentary diagramming tool in SQL server. Just right-click on "Database Diagrams" and add the tables you want to include. But this feature hasn't been shown any love since SQL Server 2000 and the diagrams are very simple. Microsoft Visio is another tool I've previously used and it allows you to create an ERD ...

Another Year. Another Year's Checklist!

Ahhh yes… Another year! Another fresh start and set of goals for the year. So many good intentions. On this blog I try to detail my meandering adventures in technology, so I thought I'd write up the tech-subjects I've had in the back of my mind but never got around to looking into. You never know, maybe this is the year I can tick some of them off!! Truth be told, I have had this laundry list of things-to-do-and-learn swirling around my head from last year. And maybe the year before as well. C++ 17 will be released this year. I've been keeping up with all the new toys that have been added to the language since C++11. Even though I don't code in C++ anymore (C# is my daily driver) I still have a fondness for C++. It would be good to have a refresher on some of the newer language features. Although, it seems like C++20 is going to be the BIG release with modules (finally) and async/await billed as features! Install and play with .NET Core on Linux and...

.NET Concurrent Collections

Oh ConcurrentQueue , where have you been all my life! - Why have I only just found out that you exist? I know, I know… It seems I’m late to the party. But it turns out that the new System.Collections.Concurrent namespace was only introduced in .NET Version 4.0 It’s no secret that when it comes to data processing, adding more threads mean you can process data faster. But adding multiple threads means data races. It means you need to make sure you have a mutex/lock setup around the shared data structure. This ensures that all access to this central data is tightly controlled. Essentially, it means only one thread at any one time should be able to access the data. Now, I have previously rolled my own thread-safe locking queue which is always a scary concept (due to data-race conditions). I have used it in multiple projects and have many variations. I have written a Blocking Queue which doesn’t spin on a thread. Essentially all threads will wait on a queue instead of having to Th...