DHCP Option in Qt/C++ - c++

I would like to ask if there is a way to read DHCP option in Qt or c++ (Qt would be better) on linux. I have my own cups backend and would like to read option 9 - LPR Servers (all of the listed IP addresses) and use it as device uri.
So I want to know how to get specific (or all) option(s) informations from the DHCP lease.
I've looked to Qt's documentation but wasn't able to find anything useful and couldn't find any c++ libraries for linux.

I had exactly the same problem. I have found a library called Libcrafter which has a lot of features including DHCP support. There is a good example of DHCP usage in their examples. It is example #8.

This requirement is quite specific. I don't know there's such individual library for mere DHCP options.
So my suggestion is that, down one DHCP implementation(http://en.wikipedia.org/wiki/Comparison_of_DHCP_server_software), study how it handles the options.
Take dnsmasq_2.72 as an example, in file src/dhcp-common.c, there's function lookup_dhcp_opt().

Related

Capture and forwarding of network traffic from a particular application on Windows

I need to capture network traffic that is going in/out of a particular application. The main issue is that I would like to do this in a blocking fashion -- i.e. capture the traffic, perform some analysis and encryption/decryption on it and then forward it along its regular route. So, it must use some sort of a blocking mechanism.
Is there some code or a library that makes this easy to do on Windows (Server 2008 or Win7 will do)? Any C++ (or Python/Java) classes or libraries that already exist?
I intend for the solution to also execute on the same machine as the target app and have administrative privileges.
Any pointers to code samples would be greatly appreciated.
Thanks for your help.
p.s.: I have been looking at WinPcap but from my (limited) understanding, it can't filter/block based on specific applications. Is that right, or did I miss something? Any other solutions out there?
For this you should look at WinDivert. Unlike regular packet sniffers (like winpcap), WinDivert also has the ability to block/filter packets, so it might be what you are looking for. Disclosure: WinDivert is my own project.

Auto-detecting active MYSQL port in C++

I'm working on a Qt/C++ project, and one of its functions is setting up a MySQL database. That particular bit of code works fine, but one of the things that the user must provide to make it work is the port that the MySQL process is currently listening on. This is usually 3306 or 5432, (depending on OS... MySQL usually wants to use 3306 first but I’ve had it try to use the Postgres port on one occasion) but I feel like I need to account for strange configurations. Many users will have no idea what to put in that field unless they know enough about MySQL to know what ports it uses. (most people don't) My target audience for the program is everyone who might want to keep a computerized diary, so it would be nice if the program can find the correct port on its own.
I could have the program run through a list of commonly-used ports until it finds the right one, (which should work in most setups) but it would be better if it could actually figure out which port to use. That way, there won't be any problems if the user has a bizarre configuration for some reason.
Any idea how I would go about doing this? I've tried googling and I found nothing relevant.
I can see of two methods to go about doing this. One: a simple port scanner. Like you said scanning all normally used ports, if nothing is found you can scan all the ports, it shouldn't be that hard to implement, you scan the ports and ask for a response only MYSQL will give to a particular method, this way you know that it is indeed MySQL on that port.
Secondly, you could attempt to figure out what the port is through the registry. Assuming this is a windows OS you could find that in the registry (hopefully), if it were linux OS you'd find it in MySQL's settings files, ect...
But I see no "UNIVERSAL CONSTANT" for this, I think it would be easiest to implement a simple port scanner.
The registry probably won't be needed actually, Searching my MySQL directory on Windows 7 I found a "my.ini" searched for port and its right there "port=theport"
Thus you can probably search for the mySQL directory and the .ini file to find the port.

Where can I find a C++ DNS Library?

I know DNS is typically handled by the operating system, but I'm working under the assumption that DNS has been broken on the target system (this is a tool to diagnose DNS misconfiguration). I therefore need to implement DNS myself, to check the results I get back from the system against a known good DNS server.
You can do this with the NSLookup or Dig tools, specifying a DNS server address manually, but it appears the Windows API calls for doing this (e.g. GetAddressByName) don't allow me to specify a server to query, and use the system's configured target instead.
I tried to look for the RFCs on DNS, but unfortunately they are clear as mud to me -- they make the HTTP spec look like the clearest and most well written spec ever produced.
I also don't want to reinvent something that someone else has already done several times before.
You might try: http://25thandclement.com/~william/projects/dns.c.html . Also, see Need To Build Simple DNS Resolver in C
Actually, a Google search of "DNS resolver C" reveals several possibilities.
Try the c-ares library, which as I understand it does implement its own DNS stack. I've used it successfully on linux, and they say that it supports Windows, though I haven't tried it myself. It isn't C++, just plain C, but you can easily enough write a C++ wrapper for it.
It gets bonus points for being asynchronous, and providing hooks by which you can integrate it with an existing event loop.
I know that the question is old, but I haven't found good answer for me here.
I have found poslib as the best dns library with very easy interface.
http://www.vantage-points.org/libvdns.html
http://directory.fsf.org/project/FireDNS/
Did never use this, but maybe that helps you?
I'd suggest libunbound which (together with ldns) is a standalone library included with the Unbound recursive resolver.
It has DNSSEC validation support too, which will become useful as DNSSEC continues to get deployed.
See http://unbound.net/
djbdns contains a DNS client library which you could use:
http://cr.yp.to/djbdns/dns.html
This is independent of the system DNS resolver libraries and will generate the right UDP packets. If you really wanted to get clever, you could combine it with dnscache, or look at the dnstrace utility to resolve names from root servers and see what is really going on.
You'd need to make it work on Windows, of course. Shouldn't be that hard.

Scanning Local Windows System for Attached USB Devices Using C++

What is the best way to scan the local Windows system for attached USB devices using C++? I need to get a list of Vendor and Product IDs to match against the my device's IDs. If there is a way to scan for a specific VID/PID combination, that would be even better. My end goal is to retrieve the virtual COM port Windows has assigned to the device. If there's a way to do all that, it would be fantastic. As always, examples are much appreciated. Thanks.
This is pretty much an MSDN example of what you want:
http://msdn.microsoft.com/en-us/library/ff558728%28VS.85%29.aspx
It seems you'll need the WDK if you want to access this kind of functionality (every MSDN search I can think of suggests this).
I was able to resolve this by querying WMI for the needed information. Basically, I was able to start with Microsoft's example code, modify it a bit, and finally build it into my own class that does what I need.
http://msdn.microsoft.com/en-us/library/aa390423%28v=VS.85%29.aspx
This list of Computer System Hardware Classes was also helpful:
http://msdn.microsoft.com/en-us/library/aa389273%28v=VS.85%29.aspx
I used the WMI Code Creator to preview the results of what looked to be promising classes.
In the end I used the following:
Namespace: root\CIMV2
Class: Win32_SerialPort
Property: PNPDeviceID and DeviceID

GUIDs in a C++ Linux GCC app

I've got a bunch of servers running this Linux app. I'd like for them to be able to generate a GUID with a low probability of collision. I'm sure I could just pull 128 bytes out of /dev/urandom and that would probably be fine, but is there a simple & easy way to generate a GUID that is more equivalent to the Win32 one? Specifically, one that takes into account space (well, MAC address), time, and randomness? I don't want to call off the box for it, I just want something like CreateGuid()
This Internet Draft describes one type of UUID in great details and I have used a similar approach with great success when I needed a UUID implementation and could not link to an existing library for architectural reasons.
This article provides a good overview.
There is libuuid.
If you are going to use something then an Internet standard would be a good idea:
Check out RFC (Request For Comment).
The one I know that is specific to GUID is:
RFC 4122
There is a Boost version available.
http://www.boostpro.com/vault/index.php?action=downloadfile&filename=uuid_v11.zip&directory=&PHPSESSID=69e18b945f686398b963710fd52f143a