#include <vector>
#include <string>
#include <set>
#include <map>
#include <deque>
#include <algorithm>
usingnamespace std;
//------------------------------------
struct multi_pack {
__int64 pid; // packet pid
unsignedchar mac[6]; // mac address
__int64 daddr; // destination ip address
__int64 saddr; // source ip address
__int64 dport; // destination port
__int64 sport; // source port
unsignedchar* pdata;
__int64 len;
};
struct IP {
unsignedchar ihl : 4; // header length
unsignedchar version : 4;
unsignedchar tos; // type of service (see stevens fig 7.12)
unsignedshort tot_len; // total lenght including Payload
unsignedshort id; // identification, used for reassembly
unsignedshort frag_off; // whether to fragment and the offset
unsignedchar ttl; // time to live decremented at routers
unsignedchar protocol; // protocol 6=tcp 17=udp
unsignedshort check; // 16 bit header checksum
unsignedlong saddr; // IvP4 source address
unsignedlong daddr; // IvP4 dest address
};
struct IP_FRAGMENTED {
unsignedlong saddr; // IvP4 source address
unsignedlong daddr; // IvP4 dest address
unsignedchar protocol; // protocol 6=tcp 17=udp
unsignedshort id; // fragmented packet id
unsignedchar hlen; // whole packet header length
unsignedshort tot_len; // total length including Payload
unsignedshort cur_len; // total length acquired until now
unsignedlong last_time; // last time updated
set<IP*>packets; // ip fragments from this packet
};
// ----------------------------------
typedef set<IP_FRAGMENTED>fragip_set; // repository for ip fragments
fragip_set ip_frags;
static multi_pack cur;
void ip_defragment() {
fragip_set::iterator i;
IP_FRAGMENTED new_defrag;
IP* pcurpack = (IP*) malloc(cur.len);
memcpy(pcurpack, cur.pdata, cur.len);
i = ip_frags.find(new_defrag);
if (i != ip_frags.end()) {
i->packets.insert(pcurpack);
}
}
error:line is bold
[bcc32 Error] Unit1.cpp(78): E2285 Could not find a match for '_Tree<_Tset_traits<IP *,less<IP *>,allocator<IP *>,0> >::insert(IP *)'
visual studio 2012:
IntelliSense: no instance of overloaded function "std::set<_Kty, _Pr, _Alloc>::insert [with _Kty=IP *, _Pr=std::less<IP *>, _Alloc=std::allocator<IP *>]" matches the argument list and object (the object has type qualifiers that prevent a match)
can't be created because there is no way to order IP_FRAGMENTED objects. You need to provide a comparison function.
i->packets.insert(pcurpack); because `i' is a set iterator, it is not allowed to modify the object that refers to, as it would fuck up the internal order.
I suppose that you could const_cast, provided that it does not affect the comparison function.
set<IP*>packets;
¿is there a good reason to use a pointer there?
That source is too windows specific for me to work on.
However, I do see that IP_FRAGMENTED does implement a comparison function (operator<)
Working on your snip
1 2 3 4 5
if (i != ip_frags.end()) { //line 63
IP_FRAGMENTED &it = const_cast<IP_FRAGMENTED&>(*i);
//i->packets.insert(pcurpack);
it.packets.insert(pcurpack);
}
so prepare for a lot of refactoring.
Another way is simply tell the compiler to shut up
man gcc wrote:
-fpermissive
Downgrade some diagnostics about nonconformant code from errors to warnings.
Thus, using -fpermissive allows some nonconforming code to compile.
RTFM to known for an equivalent flag in vs2010
PS: I suspect a memory leak in `ip_deframent()', as it never `free()' the `malloc()' it gives to `pcurpack'.
It would really benefit of constructor, assignment operators and destructors (but that may be too much of a change now)