Could not find a match

this source code work well with visual studio 2008 and compiled but with visual studio 2010 and upper or c++builder xe4 not work and not compiled.

please help me to solve this error ...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <vector>
#include <string>
#include <set>
#include <map>
#include <deque>
#include <algorithm>
using namespace std;

//------------------------------------

struct multi_pack {
	__int64 pid; // packet pid
	unsigned char mac[6]; // mac address
	__int64 daddr; // destination ip address
	__int64 saddr; // source ip address
	__int64 dport; // destination port
	__int64 sport; // source port
	unsigned char* pdata;
	__int64 len;
};

struct IP {
	unsigned char ihl : 4; // header length
	unsigned char version : 4;

	unsigned char tos; // type of service (see stevens fig 7.12)
	unsigned short tot_len; // total lenght including Payload
	unsigned short id; // identification, used for reassembly
	unsigned short frag_off; // whether to fragment and the offset
	unsigned char ttl; // time to live decremented at routers
	unsigned char protocol; // protocol 6=tcp 17=udp
	unsigned short check; // 16 bit header checksum
	unsigned long saddr; // IvP4 source address
	unsigned long daddr; // IvP4 dest address
};

struct IP_FRAGMENTED {
	unsigned long saddr; // IvP4 source address
	unsigned long daddr; // IvP4 dest address
	unsigned char protocol; // protocol 6=tcp 17=udp
	unsigned short id; // fragmented packet id
	unsigned char hlen; // whole packet header length
	unsigned short tot_len; // total length including Payload
	unsigned short cur_len; // total length acquired until now
	unsigned long 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)



Please give your ideas





Last edited on
1
2
typedef set<IP_FRAGMENTED>fragip_set;
fragip_set ip_frags;
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?
but this source work fine with vc++ 2008
also void main() ¿what's your point?

please make sure that you are actually compiling that source, because it makes no sense to accept such code.


by the way, given that `new_defrag' is not initialized, ¿what do you expect in line 61?
Last edited on
this is full src with all requirment

link

not any way for me to compile with 2010 & upper

see src and if you have new way help me...

tanks
Last edited on
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)
very very tanks

work fine and compiled with c++ 2012 and c++builder xe4 + your changes

final changes :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
void ip_defragment() {

	// u8* d = cur.pdata;
	// __int64 l = cur.len;
	fragip_set::iterator i;
	IP_FRAGMENTED new_defrag;
	IP* pcurpack = (IP*) malloc(cur.len);
	memcpy(pcurpack, cur.pdata, cur.len);

	new_defrag.saddr = cur.saddr;
	new_defrag.daddr = cur.daddr;
	new_defrag.protocol = cur.ip.ppack->protocol;
	new_defrag.id = i2i(cur.ip.ppack->id);

	i = ip_frags.find(new_defrag);

	/*
	 if (i != ip_frags.end()) { //line 63
	 IP_FRAGMENTED &it = const_cast<IP_FRAGMENTED&>(*i);
	 //i->packets.insert(pcurpack);
	 it.packets.insert(pcurpack);
	 }
	 */

	if (i != ip_frags.end()) {
		IP_FRAGMENTED &it = const_cast<IP_FRAGMENTED&>(*i);
		// i->packets.insert(pcurpack);
		it.packets.insert(pcurpack);
		if (!(pcurpack->frag_off & IP_OFFMASK))
			it.hlen = cur.ip.hlen;
		// const_cast<unsigned char&>(i->hlen) = cur.ip.hlen;
		it.cur_len += cur.ip.len - cur.ip.hlen; // add payload size
		it.last_time = GetTickCount(); // time();
		if (!(cur.ip.bmore_fr) && (i->tot_len == 0)) {
			it.tot_len = cur.ip.fr_offs + cur.ip.len;
		}
		if (i->cur_len == i->tot_len) {
			IP* pack = 0;
			// for (set<IP*>::iterator k = i->packets.begin();
			// k != i->packets.end(); k++)
			for (set<IP*>::iterator k = it.packets.begin();
			k != it.packets.end(); k++) {
				// must copy to another buffer
				if (pack)
					free(pack);
				pack = (IP*)*k;
				if (!(i2i(pack->frag_off) & IP_OFFMASK))
				{ // first packet, copy with header
					memcpy(ip_defrag_buffer, pack, i2i(pack->tot_len));
				}
				else {
					memcpy(ip_defrag_buffer + i->hlen +
						(i2i(pack->frag_off) & IP_OFFMASK) * 8,
						(unsigned char*)pack + (pack->ihl << 2),
						i2i(pack->tot_len) - (pack->ihl << 2));
				}
			}
			free(pack); // last packet data
			pack = (IP*)&ip_defrag_buffer;
			pack->tot_len = i2i(i->tot_len);
			pack->check = 0;
			pack->frag_off = 0;
			cur.len = i->tot_len;
			///
			cur.pdata = (unsigned char*)&ip_defrag_buffer;
			ip_frags.erase(i);

			pack->check = checksum((unsigned char*)pack, pack->ihl << 2, 0);
			return;
		}
		cur.len = 0;
		return;
	}

	if (!(cur.ip.bmore_fr)) {
		new_defrag.tot_len = cur.ip.fr_offs + cur.len;
	}
	else {
		new_defrag.tot_len = 0;
	}
	new_defrag.cur_len = cur.ip.len; // with header size
	new_defrag.last_time = GetTickCount();
	i = ip_frags.insert(new_defrag).first;
	if (i != ip_frags.end()) {
		// i->packets.insert(pcurpack);
		IP_FRAGMENTED &it2 = const_cast<IP_FRAGMENTED&>(*i);
		it2.packets.insert(pcurpack);
	}
	cur.len = 0;
	return;
}


tanks to ne555





Topic archived. No new replies allowed.