Jul 29, 2012 at 12:40pm UTC
please help me for this errors
code:
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
u16 ip_defragment(){
u16 result;
fragip_set::iterator i;
IP_FRAGMENTED new_defrag;
IP* pcurpack = (IP*) malloc(cur.len);
memcpy(pcurpack, cur.data, 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()){
i->packets.insert(pcurpack);
const_cast <u16&>(i->cur_len) += cur.ip.len - cur.ip.hlen;
const_cast <u32&>(i->last_time) = time();
if (!(cur.ip.bmore_fr) && (i->tot_len == 0)){
const_cast <u16&>(i->tot_len) = cur.ip.fr_offs + cur.ip.len;
}
if (i->cur_len == i->tot_len){
for (set<IP*>::iterator k = i->packets.begin(); k != i->packets.end(); k++){
// must copy to another buffer
if (i2i((*k)->frag_off) & IP_OFFMASK){
memcpy(ip_defrag_buffer, *k, (*k)->ihl<<2);
} else {
memcpy(ip_defrag_buffer + (i2i((*k)->frag_off) & IP_OFFMASK) * 8,
*k + ((*k)->ihl<<2), (i2i((*k)->tot_len))-((*k)->ihl<<2));
}
}
IP* defr_ip = (IP*) &ip_defrag_buffer;
defr_ip->tot_len = i2i(i->tot_len);
defr_ip->frag_off = 0;
result = i->tot_len;
ip_frags.erase(i);
return result;
}
return 0;
}
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 = time();
i = ip_frags.insert(new_defrag).first;
if (i != ip_frags.end())
i->packets.insert(pcurpack);
return 0;
}
compiled project and view only 2 errors similar
line 15 & 51 :
i->packets.insert(pcurpack);
error with 2 lines : error C2663: 'std::_Tree<_Traits>::insert' : 4 overloads have no legal conversion for 'this' pointer
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)
Last edited on Jul 29, 2012 at 12:40pm UTC
Jul 29, 2012 at 9:43pm UTC
Can you show the declaration of fragip_set
Jul 30, 2012 at 1:56pm UTC
Your code looks fine as you've presented it to me.
Does that function have all the definitions available to that compiled unit? I mean, do you just have a forward declaration for IP?
I am curious as to why you're using malloc for IP* and not new.
Last edited on Jul 30, 2012 at 1:58pm UTC
Jul 30, 2012 at 2:01pm UTC
The set iterators are read-only.