I'm trying to make an homemade system for exchanging packets, especially on layer 2 without anything above, on CentOS...
I use
The thing is, as my program receives and sends packets (and thus uses pcap++ and libcrafter), there is a conflict with the class Packet
, defined both in libcrafter
and in Pcap++
...
Here's my header :
#include <stdio.h>
#include <iostream>
#include <getopt.h>
#include <stdlib.h>
#include <fstream>
#include <memory>
#include <pthread.h>
#include <errno.h>
#include <vector>
#include <string>
#include <sstream>
/**** LIBCRAFTER ******/
#include <MacAddress.h>
#include <IpAddress.h>
#include <PlatformSpecificUtils.h>
#include <PcapLiveDeviceList.h>
#include <PcapLiveDevice.h>
#include <EthLayer.h>
#include <PayloadLayer.h>
#include <Logger.h>
#include <in.h>
#include <PointerVector.h>
#include <crafter.h>
using namespace Crafter;
using namespace std;
And here is the first error I get :
server_resp.cpp: In function ‘int main(int, char**)’:
server_resp.cpp:74:3: error: reference to ‘Packet’ is ambiguous
Packet pack_decod(capturedPackets.getAndRemoveFromVector(position));
^
In file included from /home/myself/Downloads/PcapPlusPlus-master/Dist/header/PcapLiveDevice.h:9:0,
from /home/myself/Downloads/PcapPlusPlus-master/Dist/header/PcapLiveDeviceList.h:5,
from server_resp.cpp:16:
/home/myself/Downloads/PcapPlusPlus-master/Dist/header/Packet.h:19:7: note: candidates are: class Packet
class Packet {
^
In file included from /usr/local/include/crafter/Crafter.h:104:0,
from /usr/local/include/crafter.h:33,
from server_resp.cpp:23:
/usr/local/include/crafter/Packet.h:44:8: note: class Crafter::Packet
class Packet {
^
I can provide a MME, but it's quite long (150 lines), and I wanted to keep the question simple...
Edit : I also have the problem with the class Ethernet
With name conflicts such as this one there are only two things you can practically do:
Change the source code and wrap the library in its own namespace. That way you can do something like Crafter::Packet.
- Or -
I'm partial to wrapping the library in its own namespace. As it's the least effort thing to do.
Lastly, I suggest making a patch of this and mailing it to the authors of the libraries. It probably won't be the first time this happens, nor will it be the last.