@@ -539,6 +539,12 @@ class IP(ctypes.Structure):
539539 ('daddr' , ctypes .c_uint32 ),
540540 ]
541541
542+ class IPV6 (ctypes .Structure ):
543+ _fields_ = [
544+ ('saddr' , ctypes .c_uint16 * 8 ),
545+ ('daddr' , ctypes .c_uint16 * 8 ),
546+ ]
547+
542548 class ArpExt (ctypes .Structure ):
543549 _fields_ = [
544550 ('op' , ctypes .c_uint16 )
@@ -570,6 +576,7 @@ class Icmp(ctypes.Structure):
570576 class FieldL3 (ctypes .Union ):
571577 _fields_ = [
572578 ('ip' , IP ),
579+ ('ipv6' , IPV6 ),
573580 ]
574581
575582 class FieldL4 (ctypes .Union ):
@@ -644,26 +651,34 @@ def _print_stack(stack_id, tgid):
644651 show_module = True , show_offset = True ))
645652
646653 @staticmethod
647- def _generate_ip_info (ctx ):
648- ip = ctx .field_l3 .ip
654+ def _generate_ip_info (ctx , is_ipv6 = False ):
649655 output_str = ''
650656
657+ if not is_ipv6 :
658+ ip = ctx .field_l3 .ip
659+ saddr = NetUtils .int2ip (socket .ntohl (ip .saddr ))
660+ daddr = NetUtils .int2ip (socket .ntohl (ip .daddr ))
661+ else :
662+ ip = ctx .field_l3 .ipv6
663+ saddr = NetUtils .int2ipv6 (ip .saddr )
664+ daddr = NetUtils .int2ipv6 (ip .daddr )
665+
651666 if ctx .proto_l4 == socket .IPPROTO_TCP :
652667 tcp = ctx .field_l4 .tcp
653668 output_str += 'TCP: %s:%d -> %s:%d, seq:%d, ack:%d %s' % (
654- NetUtils . int2ip ( socket . ntohl ( ip . saddr )) ,
669+ saddr ,
655670 socket .ntohs (tcp .sport ),
656- NetUtils . int2ip ( socket . ntohl ( ip . daddr )) ,
671+ daddr ,
657672 socket .ntohs (tcp .dport ),
658673 socket .ntohl (tcp .seq ),
659674 socket .ntohl (tcp .ack ),
660675 NetUtils .int2tcp_flags (tcp .flags ))
661676 elif ctx .proto_l4 == socket .IPPROTO_UDP :
662677 udp = ctx .field_l4 .udp
663678 output_str += 'UDP: %s:%d -> %s:%d' % (
664- NetUtils . int2ip ( socket . ntohl ( ip . saddr )) ,
679+ saddr ,
665680 socket .ntohs (udp .sport ),
666- NetUtils . int2ip ( socket . ntohl ( ip . daddr )) ,
681+ daddr ,
667682 socket .ntohs (udp .dport ))
668683 elif ctx .proto_l4 == socket .IPPROTO_ICMP :
669684 icmp = ctx .field_l4 .icmp
@@ -674,17 +689,15 @@ def _generate_ip_info(ctx):
674689 else :
675690 icmp_info = 'type: %d, code: %d' % (icmp .type , icmp .code )
676691 output_str += 'ICMP: %s -> %s, %-15s, seq: %d' % (
677- NetUtils .int2ip (
678- socket .ntohl (ip .saddr )),
679- NetUtils .int2ip (
680- socket .ntohl (ip .daddr )),
692+ saddr ,
693+ daddr ,
681694 icmp_info ,
682695 socket .ntohs (icmp .seq ))
683696 else :
684697 fmt = '%s: %s -> %s'
685- output_str += fmt % (NetUtils .int2proto (socket .ntohs (ctx .proto_l3 )),
686- NetUtils . int2ip ( socket . ntohl ( ip . saddr )) ,
687- NetUtils . int2ip ( socket . ntohl ( ip . daddr )) )
698+ output_str += fmt % (NetUtils .int2proto (socket .ntohs (ctx .proto_l3 ), 4 ),
699+ saddr ,
700+ daddr )
688701 return output_str
689702
690703 @staticmethod
@@ -712,6 +725,9 @@ def _generate_proto_info(ctx):
712725 if proto_l3 == NetUtils .PROTO_L3 ['IP' ]:
713726 return Output ._generate_ip_info (ctx )
714727
728+ if proto_l3 == NetUtils .PROTO_L3 ['IPV6' ]:
729+ return Output ._generate_ip_info (ctx , True )
730+
715731 if proto_l3 == NetUtils .PROTO_L3 ['ARP' ]:
716732 return Output ._generate_arp_info (ctx )
717733
0 commit comments