Ethereal-dev: [Ethereal-dev] DSR,ICMP and dissector_try_port

Note: This archive is from the project's previous web site, ethereal.com. This list is no longer active.

From: david martinez <davidmfcg@xxxxxxxx>
Date: Tue, 21 Mar 2006 15:26:32 +0100 (CET)
Hi,i have the next problem when a DSR protocol
dissector,in my captures sometimes i have to call icmp
dissector after dsr dissector, but the ICMP dissector
tell me malformed packet.I use the function
dissecotr_try_port to find what dissector i have to
call(it is indicated by nextheader field). It dissect
correctly all types of pdus. I don`t know why it tell
me malformed, becouse i believe that i use funcitons
correctly(maybe in the function dissect_try_port). I
put here my code with the types of pdus that i have
problem:


nextheader=tvb_get_guint8(tvb,0);
reserved=tvb_get_guint8(tvb,1);
payloadlength=tvb_get_ntohs(tvb,2);
tp=proto_tree_add_protocol_format(tree,proto_dsr,tvb,0,4,"DynamicSourceRoute");
dsr_tree=proto_item_add_subtree(tp,ett_dsr);
t0=proto_tree_add_uint(dsr_tree,hf_dsr_nextheader,tvb,0,1,nextheader);
t1=proto_tree_add_uint(dsr_tree,hf_dsr_reserved,tvb,1,1,reserved);
t2=proto_tree_add_uint(dsr_tree,hf_dsr_payloadlength,tvb,2,2,payloadlength);

TRY {

pdu_type=(tvb_get_guint8(tvb,4)&0xFF)>>0;
}

CATCH2(BoundsError,ReportedBoundsError) {
;
}

ENDTRY;

offset=4;

cuenta=payloadlength;

		while(payloadlength!=0)
{
	switch(pdu_type)	{
			
			case 0x07:

t4=proto_tree_add_uint(dsr_tree,hf_dsr_optiontype6,tvb,offset+0,1,pdu_type);
pdutype_tree=proto_item_add_subtree(t4,ett_pdutype);
optdatalen6=tvb_get_guint8(tvb,offset+1);
proto_tree_add_uint(pdutype_tree,hf_dsr_optdatalen6,tvb,offset+1,1,optdatalen6);
f=tvb_get_guint8(tvb,offset+2);
proto_tree_add_uint(pdutype_tree,hf_dsr_f,tvb,offset+2,1,f);
l=tvb_get_guint8(tvb,offset+2);
proto_tree_add_uint(pdutype_tree,hf_dsr_l,tvb,offset+2,1,l);
reserved6=tvb_get_guint8(tvb,offset+2);
proto_tree_add_uint(pdutype_tree,hf_dsr_reserved6,tvb,offset+2,1,reserved6);
salvage=tvb_get_guint8(tvb,offset+3);
proto_tree_add_uint(pdutype_tree,hf_dsr_salvage,tvb,offset+3,1,salvage);
segsleft=tvb_get_guint8(tvb,offset+3);
proto_tree_add_uint(pdutype_tree,hf_dsr_segsleft,tvb,offset+3,1,segsleft);


payloadlength=payloadlength-optdatalen6+2-4;
optdatalen6=optdatalen6-2;
offset=offset+4;
while(optdatalen6>=4) {
address6=tvb_get_ipv4(tvb,offset);
proto_tree_add_ipv4(pdutype_tree,hf_dsr_address6,tvb,offset,4,address6);
optdatalen6=optdatalen6-4;
offset=offset+4;
}

TRY {

pdu_type=(tvb_get_guint8(tvb,offset+0)&0xFF)>>0;

}
CATCH2(BoundsError,ReportedBoundsError) {
;
}

ENDTRY;
break;
			case 0x05:

t4=proto_tree_add_uint(dsr_tree,hf_dsr_optiontype4,tvb,offset+0,1,pdu_type);
pdutype_tree=proto_item_add_subtree(t4,ett_pdutype);
optdatalen4=tvb_get_guint8(tvb,offset+1);
proto_tree_add_uint(pdutype_tree,hf_dsr_optdatalen4,tvb,offset+1,1,optdatalen4);
identification4=tvb_get_ntohs(tvb,offset+2);
proto_tree_add_uint(pdutype_tree,hf_dsr_identification4,tvb,offset+2,2,identification4);


payloadlength=payloadlength-optdatalen4+2-4;
optdatalen4=optdatalen4-2;
offset=offset+4;
while(optdatalen4>=4) {
addresackro=tvb_get_ipv4(tvb,offset);
proto_tree_add_ipv4(pdutype_tree,hf_dsr_addresackro,tvb,offset,4,addresackro);
optdatalen4=optdatalen4-4;
offset=offset+4;
}

TRY {

pdu_type=(tvb_get_guint8(tvb,offset+0)&0xFF)>>0;

}
CATCH2(BoundsError,ReportedBoundsError) {
;
}

ENDTRY;
break;
			

}
}

tvb_set_reported_length(tvb,4+cuenta);

next_tvb=tvb_new_subset(tvb,offset,-1,-1);

dissector_try_port(table_var,nextheader,next_tvb,pinfo,tree);

}
...............

void proto_reg_handoff_dsr(void)
{           
dissector_handle_t dsr_handle;
dsr_handle=create_dissector_handle(dissect_dsr,proto_dsr);
dissector_add("ip.proto",IP_PROTO_DSR,dsr_handle);
 table_var=find_dissector_table("ip.proto");

}



		
______________________________________________ 
LLama Gratis a cualquier PC del Mundo. 
Llamadas a fijos y m�viles desde 1 c�ntimo por minuto. 
http://es.voice.yahoo.com