SNMP C++ client implementation

Working with SNMP under QT

Four years ago I worked on a multi-platform desktop application, which main purpose was to observe and control various devices on the local network using SNMP. The main questions that had to be solved were :

How to write an application that can run on multiple platforms (like Windows, Linux, Mac OS)

How to communicate with the SNMP devices

The client didn't want a web app, so I had to think of other variants. And because I'm a big C++ fan, I decided to utilize a C++ based solution.

What is QT ?

For those of you you have never heard of it, QT is an intuitive, easy to use cross-platform library written entirely in C++, developed by Trolltech but later bought by Nokia with the idea of using QT in platforms like Maemo (which later morphed into MeeGo). It's available on Window, Linux, Mac OS, along with some mobile platforms. You can use it for game development and even create browser plugins with it. But that was few years ago, for a complete list of the currently supported platforms check this link.

At the time I was working on the project, there weren't so many SNMP libraries available for C++ (and I think this is still the case). So I was left with more or less two options :

SNMP++ (An object-oriented C++ library, which sounded like a good option)

NetSNMP (Library written entirely in C, which I really didn't want to wrap at that time)

Unfortunately, it turned out that SNMP++ was not designed to work under MinGW (which is the GCC port that QT uses on Windows).

So I decided to create my own class to operate the SNMP packets. It uses the QT network module, creating a UDP packet and manually including all the bytes necessary from the Application layer according to the correct SNMP format.

SNMPv1 QT/C++ implementation

I know there are not so many choices when it comes to SNMP management in C++, so I decided to share this code.

The following is a simple class used to communicate using SNMPv1 devices :

I should warn you that the code should not be used as an example of best coding practices, but it has a clear and understandable interface. And, honestly, sometimes you just need something that works, even if it's not the most clever implementation.

And since I need to set a license here (because if I don't, you'll have practically no rights over the code), I decided to share it under LGPL.

Hi there ! My name is Kosta Hristov and I currently live in London, England. I've been working as a software engineer for the past 6 years on different mobile, desktop and web IT projects. I started this blog almost one year ago with the idea of helping developers from all around the world in their day to day programming tasks, sharing knowledge on various topics. If you find my articles interesting and you want to know more about me, feel free to contact me via the social links below. ;)