30
30
#include <stdio.h>
31
31
#include <string.h>
32
32
33
+ #define ND_LONGJMP_FROM_TCHECK
33
34
#include "netdissect.h"
34
35
#include "addrtoname.h"
35
36
#include "extract.h"
@@ -333,7 +334,6 @@ struct icmp_interface_identification_ifname_subobject_t {
333
334
nd_byte if_name [63 ];
334
335
};
335
336
336
-
337
337
/* prototypes */
338
338
const char * icmp_tstamp_print (u_int );
339
339
@@ -354,34 +354,21 @@ icmp_tstamp_print(u_int tstamp)
354
354
}
355
355
356
356
void
357
- icmp_print (netdissect_options * ndo , const u_char * bp , u_int plen , const u_char * bp2 ,
357
+ icmp_print (netdissect_options * ndo , const u_char * bp , u_int plen ,
358
358
int fragmented )
359
359
{
360
- char * cp ;
361
360
const struct icmp * dp ;
362
361
uint8_t icmp_type , icmp_code ;
363
- const struct icmp_ext_t * ext_dp ;
364
- const struct ip * ip ;
362
+ const struct icmp_ext_t * ext_dp ;
365
363
const char * str ;
366
- const struct ip * oip ;
367
- uint8_t ip_proto ;
368
- const struct udphdr * ouh ;
369
- const uint8_t * obj_tptr ;
370
- uint32_t raw_label ;
371
- const struct icmp_multipart_ext_object_header_t * icmp_multipart_ext_object_header ;
372
- u_int interface_role , if_index_flag , ipaddr_flag , name_flag , mtu_flag ;
373
- const uint8_t * offset ;
374
- const struct icmp_interface_identification_ipaddr_subobject_t * ipaddr_subobj ;
375
- const struct icmp_interface_identification_ifname_subobject_t * ifname_subobj ;
376
- u_int hlen , mtu , obj_tlen , obj_class_num , obj_ctype ;
377
- uint16_t dport ;
364
+ const uint8_t * obj_tptr ;
365
+ u_int hlen ;
378
366
char buf [MAXHOSTNAMELEN + 100 ];
379
367
struct cksum_vec vec [1 ];
380
368
381
369
ndo -> ndo_protocol = "icmp" ;
382
370
dp = (const struct icmp * )bp ;
383
- ext_dp = (const struct icmp_ext_t * )bp ;
384
- ip = (const struct ip * )bp2 ;
371
+ ext_dp = (const struct icmp_ext_t * )bp ;
385
372
str = buf ;
386
373
387
374
icmp_type = GET_U_1 (dp -> icmp_type );
@@ -420,7 +407,12 @@ icmp_print(netdissect_options *ndo, const u_char *bp, u_int plen, const u_char *
420
407
break ;
421
408
422
409
case ICMP_UNREACH_PORT :
423
- ND_TCHECK_1 (dp -> icmp_ip .ip_p );
410
+ {
411
+ const struct ip * oip ;
412
+ const struct udphdr * ouh ;
413
+ uint8_t ip_proto ;
414
+ uint16_t dport ;
415
+
424
416
oip = & dp -> icmp_ip ;
425
417
hlen = IP_HL (oip ) * 4 ;
426
418
ouh = (const struct udphdr * )(((const u_char * )oip ) + hlen );
@@ -450,10 +442,13 @@ icmp_print(netdissect_options *ndo, const u_char *bp, u_int plen, const u_char *
450
442
break ;
451
443
}
452
444
break ;
445
+ }
453
446
454
447
case ICMP_UNREACH_NEEDFRAG :
455
448
{
456
449
const struct mtu_discovery * mp ;
450
+ u_int mtu ;
451
+
457
452
mp = (const struct mtu_discovery * )(const u_char * )& dp -> icmp_void ;
458
453
mtu = GET_BE_U_2 (mp -> nexthopmtu );
459
454
if (mtu ) {
@@ -585,6 +580,7 @@ icmp_print(netdissect_options *ndo, const u_char *bp, u_int plen, const u_char *
585
580
586
581
case ICMP_ROUTERADVERT :
587
582
{
583
+ char * cp ;
588
584
const struct ih_rdiscovery * ihp ;
589
585
const struct id_rdiscovery * idp ;
590
586
u_int lifetime , num , size ;
@@ -593,7 +589,6 @@ icmp_print(netdissect_options *ndo, const u_char *bp, u_int plen, const u_char *
593
589
cp = buf + strlen (buf );
594
590
595
591
ihp = (const struct ih_rdiscovery * )& dp -> icmp_void ;
596
- ND_TCHECK_SIZE (ihp );
597
592
(void )strncpy (cp , " lifetime " , sizeof (buf ) - (cp - buf ));
598
593
cp = buf + strlen (buf );
599
594
lifetime = GET_BE_U_2 (ihp -> ird_lifetime );
@@ -624,13 +619,12 @@ icmp_print(netdissect_options *ndo, const u_char *bp, u_int plen, const u_char *
624
619
}
625
620
idp = (const struct id_rdiscovery * )& dp -> icmp_data ;
626
621
while (num > 0 ) {
627
- ND_TCHECK_SIZE (idp );
628
622
(void )snprintf (cp , sizeof (buf ) - (cp - buf ), " {%s %u}" ,
629
623
GET_IPADDR_STRING (idp -> ird_addr ),
630
624
GET_BE_U_4 (idp -> ird_pref ));
631
625
cp = buf + strlen (buf );
632
626
++ idp ;
633
- num -- ;
627
+ num -- ;
634
628
}
635
629
}
636
630
break ;
@@ -678,7 +672,6 @@ icmp_print(netdissect_options *ndo, const u_char *bp, u_int plen, const u_char *
678
672
break ;
679
673
680
674
case ICMP_TSTAMPREPLY :
681
- ND_TCHECK_4 (dp -> icmp_ttime );
682
675
(void )snprintf (buf , sizeof (buf ),
683
676
"time stamp reply id %u seq %u: org %s" ,
684
677
GET_BE_U_2 (dp -> icmp_id ),
@@ -717,6 +710,7 @@ icmp_print(netdissect_options *ndo, const u_char *bp, u_int plen, const u_char *
717
710
* save the snaplength as this may get overridden in the IP printer.
718
711
*/
719
712
if (ndo -> ndo_vflag >= 1 && ICMP_ERRTYPE (icmp_type )) {
713
+ const struct ip * ip ;
720
714
const u_char * snapend_save ;
721
715
722
716
bp += 8 ;
@@ -745,7 +739,6 @@ icmp_print(netdissect_options *ndo, const u_char *bp, u_int plen, const u_char *
745
739
* Attempt to decode multi-part message extensions (rfc4884) only for some ICMP types.
746
740
*/
747
741
if (ndo -> ndo_vflag >= 1 && plen > ICMP_EXTD_MINLEN && ICMP_MULTIPART_EXT_TYPE (icmp_type )) {
748
-
749
742
ND_TCHECK_SIZE (ext_dp );
750
743
751
744
/*
@@ -789,9 +782,10 @@ icmp_print(netdissect_options *ndo, const u_char *bp, u_int plen, const u_char *
789
782
obj_tptr = (const uint8_t * )ext_dp -> icmp_ext_data ;
790
783
791
784
while (hlen > sizeof (struct icmp_multipart_ext_object_header_t )) {
785
+ u_int obj_tlen , obj_class_num , obj_ctype ;
786
+ const struct icmp_multipart_ext_object_header_t * icmp_multipart_ext_object_header ;
792
787
793
788
icmp_multipart_ext_object_header = (const struct icmp_multipart_ext_object_header_t * )obj_tptr ;
794
- ND_TCHECK_SIZE (icmp_multipart_ext_object_header );
795
789
obj_tlen = GET_BE_U_2 (icmp_multipart_ext_object_header -> length );
796
790
obj_class_num = GET_U_1 (icmp_multipart_ext_object_header -> class_num );
797
791
obj_ctype = GET_U_1 (icmp_multipart_ext_object_header -> ctype );
@@ -816,18 +810,23 @@ icmp_print(netdissect_options *ndo, const u_char *bp, u_int plen, const u_char *
816
810
case MPLS_STACK_ENTRY_OBJECT_CLASS :
817
811
switch (obj_ctype ) {
818
812
case 1 :
813
+ {
814
+ uint32_t raw_label ;
815
+
819
816
raw_label = GET_BE_U_4 (obj_tptr );
820
817
ND_PRINT ("\n\t label %u, tc %u" , MPLS_LABEL (raw_label ), MPLS_TC (raw_label ));
821
818
if (MPLS_STACK (raw_label ))
822
819
ND_PRINT (", [S]" );
823
820
ND_PRINT (", ttl %u" , MPLS_TTL (raw_label ));
824
821
break ;
822
+ }
825
823
default :
826
824
print_unknown_data (ndo , obj_tptr , "\n\t " , obj_tlen );
827
825
}
828
826
break ;
829
827
830
828
case INTERFACE_INFORMATION_OBJECT_CLASS :
829
+ {
831
830
/*
832
831
Ctype in a INTERFACE_INFORMATION_OBJECT_CLASS object:
833
832
@@ -836,6 +835,9 @@ icmp_print(netdissect_options *ndo, const u_char *bp, u_int plen, const u_char *
836
835
| Interface Role| Rsvd1 | Rsvd2 |ifIndex| IPAddr| name | MTU |
837
836
+-------+-------+-------+-------+-------+-------+-------+-------+
838
837
*/
838
+ const uint8_t * offset ;
839
+ u_int interface_role , if_index_flag , ipaddr_flag , name_flag , mtu_flag ;
840
+
839
841
interface_role = (obj_ctype & 0xc0 ) >> 6 ;
840
842
if_index_flag = (obj_ctype & 0x8 ) >> 3 ;
841
843
ipaddr_flag = (obj_ctype & 0x4 ) >> 2 ;
@@ -853,6 +855,8 @@ icmp_print(netdissect_options *ndo, const u_char *bp, u_int plen, const u_char *
853
855
offset += 4 ;
854
856
}
855
857
if (ipaddr_flag ) {
858
+ const struct icmp_interface_identification_ipaddr_subobject_t * ipaddr_subobj ;
859
+
856
860
ND_PRINT ("\n\t\t IP Address sub-object: " );
857
861
ipaddr_subobj = (const struct icmp_interface_identification_ipaddr_subobject_t * ) offset ;
858
862
switch (GET_BE_U_2 (ipaddr_subobj -> afi )) {
@@ -872,6 +876,7 @@ icmp_print(netdissect_options *ndo, const u_char *bp, u_int plen, const u_char *
872
876
}
873
877
if (name_flag ) {
874
878
uint8_t inft_name_length_field ;
879
+ const struct icmp_interface_identification_ifname_subobject_t * ifname_subobj ;
875
880
876
881
ifname_subobj = (const struct icmp_interface_identification_ifname_subobject_t * ) offset ;
877
882
inft_name_length_field = GET_U_1 (ifname_subobj -> length );
@@ -903,6 +908,7 @@ icmp_print(netdissect_options *ndo, const u_char *bp, u_int plen, const u_char *
903
908
offset += 4 ;
904
909
}
905
910
break ;
911
+ }
906
912
907
913
default :
908
914
print_unknown_data (ndo , obj_tptr , "\n\t " , obj_tlen );
@@ -914,8 +920,4 @@ icmp_print(netdissect_options *ndo, const u_char *bp, u_int plen, const u_char *
914
920
obj_tptr += obj_tlen ;
915
921
}
916
922
}
917
-
918
- return ;
919
- trunc :
920
- nd_print_trunc (ndo );
921
923
}
0 commit comments