2 """ Please make sure you read the README COMPLETELY BEFORE reading anything below. 
   3     It is very critical that you read coding guidelines in Section E in README file.  
  12 from netdefines 
import * 
  13 from routedefines 
import * 
  15 def GetIfFlagsAsString(if_flags
): 
  16     """ Return a formatted string description of the interface flags 
  19     flags 
= (unsigned
)(if_flags 
& 0xffff) 
  24             out_string 
+= if_flags_strings
[i
] + ","  
  27     return rstrip(out_string
, ",") 
  30 def ShowIfConfiguration(ifnet
): 
  31     """ Display ifconfig-like output for the ifnet 
  33     iface 
= Cast(ifnet
, 'ifnet *') 
  35     format_string 
= "{0: <s}: flags={1: <x} <{2: <s}> index {3: <d} mtu {4: <d}" 
  37         out_string 
+= format_string
.format(iface
.if_xname
, (iface
.if_flags 
& 0xffff), GetIfFlagsAsString(iface
.if_flags
), iface
.if_index
, iface
.if_data
.ifi_mtu
) 
  38         out_string 
+= "\n\t(struct ifnet *)" + hex(ifnet
) 
  41 def GetIfConfiguration(ifname
): 
  42     """ Return ifnet structure corresponding to the ifname passed in 
  45     ifnets 
= kern
.globals.ifnet_head
 
  46     for ifnet 
in IterateTAILQ_HEAD(ifnets
, "if_link") : 
  47         if str(ifnet
.if_xname
) == ifname 
: 
  52 @lldb_command('ifconfig') 
  53 def ShowIfconfig(cmd_args
=None) : 
  54     """ Display ifconfig-like output, and print the (struct ifnet *) pointers for further inspection 
  56     if cmd_args 
!= None and len(cmd_args
) > 0: 
  61     ifnets 
= kern
.globals.ifnet_head
 
  62     for ifnet 
in IterateTAILQ_HEAD(ifnets
, "if_link"): 
  63         ShowIfConfiguration(ifnet
) 
  65             print GetIfaddrs(ifnet
) 
  68 def GetAddressAsStringColonHex(addr
, count
): 
  71     addr_format_string 
= "{0:02x}" 
  74             out_string 
+= addr_format_string
.format(addr
[i
])[-2:] 
  76             out_string 
+= ":" + addr_format_string
.format(addr
[i
])[-2:] 
  80 def GetSocketAddrAsStringUnspec(sockaddr
): 
  82     out_string 
+= GetAddressAsStringColonHex(sockaddr
.sa_data
, sockaddr
.sa_len 
- 2) 
  85 def GetSocketAddrAsStringUnix(sockaddr
): 
  86     sock_unix 
= Cast(sockaddr
, 'sockaddr_un *') 
  90         if (len(str(sock_unix
.sun_path
)) > 0):  
  91             return str(sock_unix
.sun_path
) 
  95 def GetInAddrAsString(ia
): 
  97     inaddr 
= Cast(ia
, 'in_addr *') 
  99     packed_value 
= struct
.pack('I', unsigned(ia
.s_addr
)) 
 100     out_string 
= inet_ntoa(packed_value
) 
 103 def GetIn6AddrAsString(ia
): 
 107     addr_format_string 
= "{0:02x}:{1:02x}:{2:02x}:{3:02x}{4:02x}:{5:02x}:{6:02x}:{7:02x}{8:02x}:{9:02x}:{10:02x}:{11:02x}{12:02x}:{13:02x}:{14:02x}:{15:02x}" 
 108     out_string 
+= addr_format_string
.format(unsigned(addr
[0]), unsigned(addr
[1]), unsigned(addr
[2]), unsigned(addr
[3]), unsigned(addr
[4]), unsigned(addr
[5]), unsigned(addr
[6]), unsigned(addr
[7]), unsigned(addr
[8]), unsigned(addr
[9]), unsigned(addr
[10]), unsigned(addr
[11]), unsigned(addr
[12]), unsigned(addr
[13]), unsigned(addr
[14]), unsigned(addr
[15])) 
 111 def GetSocketAddrAsStringInet(sockaddr
): 
 112     sock_in 
= Cast(sockaddr
, 'sockaddr_in *') 
 113     return GetInAddrAsString(sock_in
.sin_addr
) 
 115 def GetSocketAddrAsStringInet6(sockaddr
): 
 116     sock_in6 
= Cast(sockaddr
, 'sockaddr_in6 *') 
 117     return GetIn6AddrAsString(sock_in6
.sin6_addr
.__u6_addr
.__u6_addr
8) 
 119 def GetSocketAddrAsStringLink(sockaddr
): 
 120     sock_link 
= Cast(sockaddr
, 'sockaddr_dl *') 
 121     if sock_link 
is None: 
 125         if (sock_link
.sdl_nlen 
== 0 and sock_link
.sdl_alen 
== 0 and sock_link
.sdl_slen 
== 0): 
 126             out_string 
= "link#" + str(int(sock_link
.sdl_index
)) 
 128             out_string 
+= GetAddressAsStringColonHex(addressof(sock_link
.sdl_data
[sock_link
.sdl_nlen
]), sock_link
.sdl_alen
) 
 131 def GetSocketAddrAsStringAT(sockaddr
): 
 133     sock_addr 
= Cast(sockaddr
, 'sockaddr *') 
 134     out_string 
+= GetAddressAsStringColonHex(sockaddr
.sa_data
, sockaddr
.sa_len 
- 2) 
 137 def GetSocketAddrAsString(sockaddr
): 
 138     if sockaddr 
is None : 
 141     if (sockaddr
.sa_family 
== 0): 
 142         out_string 
+= "UNSPC " 
 143         GetSocketAddrAsStringUnspec(sockaddr
) 
 144     elif (sockaddr
.sa_family 
== 1): 
 145         out_string 
+= "UNIX " 
 146         out_string 
+= GetSocketAddrAsStringUnix(sockaddr
) 
 147     elif (sockaddr
.sa_family 
== 2): 
 148         out_string 
+= "INET " 
 149         out_string 
+= GetSocketAddrAsStringInet(sockaddr
) 
 150     elif (sockaddr
.sa_family 
== 30): 
 151         out_string 
+= "INET6 " 
 152         out_string 
+= GetSocketAddrAsStringInet6(sockaddr
) 
 153     elif (sockaddr
.sa_family 
== 18): 
 154         out_string 
+= "LINK " 
 155         out_string 
+= GetSocketAddrAsStringLink(sockaddr
) 
 156     elif (sockaddr
.sa_family 
== 16): 
 157         out_string 
+= "ATLK " 
 158         out_string 
+= GetSocketAddrAsStringAT(sockaddr
) 
 160         out_string 
+= "FAM " + str(sockaddr
.sa_family
) 
 161         out_string 
+= GetAddressAsStringColonHex(sockaddr
.sa_data
, sockaddr
.sa_len
) 
 165 @lldb_command('showifaddrs') 
 166 def ShowIfaddrs(cmd_args
=None): 
 167     """ Show the (struct ifnet).if_addrhead list of addresses for the given ifp 
 169     if cmd_args 
!= None and len(cmd_args
) > 0 : 
 170         ifp 
= kern
.GetValueFromAddress(cmd_args
[0], 'ifnet *') 
 172             print "Unknown value passed as argument." 
 175         for ifaddr 
in IterateTAILQ_HEAD(ifp
.if_addrhead
, "ifa_link"): 
 176             format_string 
= "\t{0: <d}: 0x{1: <x} {2: <s} [{3: <d}]" 
 177             print format_string
.format(i
, ifaddr
, GetSocketAddrAsString(ifaddr
.ifa_addr
), ifaddr
.ifa_refcnt
) 
 180         print "Missing argument 0 in user function." 
 181 # EndMacro: showifaddrs 
 187         for ifaddr 
in IterateTAILQ_HEAD(ifp
.if_addrhead
, "ifa_link"): 
 188             format_string 
= "\t{0: <d}: 0x{1: <x} {2: <s} [{3: <d}]" 
 189             out_string 
+= format_string
.format(i
, ifaddr
, GetSocketAddrAsString(ifaddr
.ifa_addr
), ifaddr
.ifa_refcnt
) + "\n" 
 192         out_string 
+= "Missing argument 0 in user function." 
 196 def GetCapabilitiesAsString(flags
): 
 197     """ Return a formatted string description of the interface flags 
 204             out_string 
+= if_capenable_strings
[i
] + ","  
 207     return rstrip(out_string
, ",") 
 209 def GetIfEflagsAsString(if_eflags
): 
 210     """ Return a formatted string description of the interface flags 
 213     flags 
= unsigned(if_eflags
) 
 218             out_string 
+= if_eflags_strings
[i
] + "," 
 221     return rstrip(out_string
, ",") 
 223 def ShowDlilIfnetConfiguration(dlil_ifnet
, show_all
) : 
 224     """ Formatted display of dlil_ifnet structures 
 229     if dlil_ifnet 
is None : 
 232     dlil_iface 
= Cast(dlil_ifnet
, 'dlil_ifnet *') 
 233     iface 
= Cast(dlil_ifnet
, 'ifnet *') 
 235     if (dlil_iface
.dl_if_flags 
& DLIF_REUSE
) : 
 237     format_string 
= "{0: <s}: flags={1: <x} <{2: <s}> index {3: <d} mtu {4: <d}" 
 238     extended_flags_format_string 
= "\n\teflags={0: <x} <{1: <s}>" 
 239     capenabled_format_string 
= "\n\toptions={0: <x} <{1: <s}>" 
 240     if (dlil_iface
.dl_if_flags 
& DLIF_INUSE
) : 
 241         out_string 
+= format_string
.format(iface
.if_xname
, (iface
.if_flags 
& 0xffff), GetIfFlagsAsString(iface
.if_flags
), iface
.if_index
, iface
.if_data
.ifi_mtu
) 
 243         out_string 
+= format_string
.format("[" + str(iface
.if_name
) + str(int(iface
.if_unit
)) + "]", (iface
.if_flags 
& 0xffff), GetIfFlagsAsString(iface
.if_flags
), iface
.if_index
, iface
.if_data
.ifi_mtu
) 
 244     if (iface
.if_eflags
) : 
 245         out_string 
+= extended_flags_format_string
.format(iface
.if_eflags
, GetIfEflagsAsString(iface
.if_eflags
)) 
 246     if (iface
.if_capenable
) : 
 247         out_string 
+= capenabled_format_string
.format(iface
.if_capenable
, GetCapabilitiesAsString(iface
.if_capenable
)) 
 248     out_string 
+= "\n\t(struct ifnet *)" + hex(dlil_ifnet
) + "\n" 
 250         out_string 
+= GetIfaddrs(iface
) 
 255 @lldb_command('showifnets') 
 256 def ShowIfnets(cmd_args
=None) : 
 257     """ Display ifconfig-like output for all attached and detached interfaces 
 260     if cmd_args 
!= None and len(cmd_args
) > 0 : 
 262     dlil_ifnets 
= kern
.globals.dlil_ifnet_head
 
 263     for dlil_ifnet 
in IterateTAILQ_HEAD(dlil_ifnets
, "dl_if_link"): 
 264         ShowDlilIfnetConfiguration(dlil_ifnet
, showall
) 
 265 # EndMacro: showifnets 
 267 # Macro: showifmultiaddrs 
 268 @lldb_command('showifmultiaddrs') 
 269 def ShowIfMultiAddrs(cmd_args
=None) : 
 270     """ Show the list of multicast addresses for the given ifp 
 273     if cmd_args 
!= None and len(cmd_args
) > 0 : 
 274         ifp 
= kern
.GetValueFromAddress(cmd_args
[0], 'ifnet *') 
 276             print "Unknown value passed as argument." 
 278         ifmulti 
= cast(ifp
.if_multiaddrs
.lh_first
, 'ifmultiaddr *') 
 281             ifma_format_string 
= "\t{0: <d}: 0x{1: <x} " 
 282             out_string 
+= (ifma_format_string
.format(i 
+ 1, ifmulti
)) 
 283             if (ifmulti
.ifma_addr
.sa_family 
== 2): 
 284                 if (ifmulti
.ifma_ll 
!= 0): 
 285                     out_string 
+= GetSocketAddrAsStringLink(ifmulti
.ifma_ll
.ifma_addr
) + " " 
 286                 out_string 
+= GetSocketAddrAsStringInet(ifmulti
.ifma_addr
) 
 287             if (ifmulti
.ifma_addr
.sa_family 
== 30): 
 288                 if (ifmulti
.ifma_ll 
!= 0): 
 289                     out_string 
+= GetSocketAddrAsStringLink(ifmulti
.ifma_ll
.ifma_addr
) + " " 
 290                 out_string 
+= GetSocketAddrAsStringInet6(ifmulti
.ifma_addr
) + " " 
 291             if (ifmulti
.ifma_addr
.sa_family 
== 18): 
 292                 out_string 
+= GetSocketAddrAsStringLink(ifmulti
.ifma_addr
) + " " 
 293             if (ifmulti
.ifma_addr
.sa_family 
== 0): 
 294                 out_string 
+= GetSocketAddrAsStringUnspec(ifmulti
.ifma_addr
) + " " 
 295             out_string 
+= "[" + str(int(ifmulti
.ifma_refcount
)) + "]\n" 
 296             ifmulti 
= cast(ifmulti
.ifma_link
.le_next
, 'ifmultiaddr *') 
 300         print "Missing argument 0 in user function." 
 301 # EndMacro: showifmultiaddrs 
 303 # Macro: showinmultiaddrs 
 304 @lldb_command('showinmultiaddrs') 
 305 def ShowInMultiAddrs(cmd_args
=None) : 
 306     """ Show the contents of IPv4 multicast address records 
 309     inmultihead 
= kern
.globals.in_multihead
 
 310     inmulti 
= cast(inmultihead
.lh_first
, 'in_multi *') 
 313         ifp 
= inmulti
.inm_ifp
 
 314         inma_format_string 
= "\t{0: <d}: 0x{1: <x} " 
 315         out_string 
+= inma_format_string
.format(i 
+ 1, inmulti
) + " " 
 316         out_string 
+= GetInAddrAsString(addressof(inmulti
.inm_addr
)) + " " 
 317         ifma_format_string 
= "(ifp 0x{0: <x} [{1: <s}] ifma {2: <x})" 
 318         out_string 
+= ifma_format_string
.format(ifp
, ifp
.if_xname
, inmulti
.inm_ifma
) + "\n" 
 319         inmulti 
= cast(inmulti
.inm_link
.le_next
, 'in_multi *') 
 322 # EndMacro: showinmultiaddrs 
 324 # Macro: showin6multiaddrs 
 325 @lldb_command('showin6multiaddrs') 
 326 def ShowIn6MultiAddrs(cmd_args
=None) : 
 327     """ Show the contents of IPv6 multicast address records 
 330     in6multihead 
= kern
.globals.in6_multihead
 
 331     in6multi 
= cast(in6multihead
.lh_first
, 'in6_multi *') 
 334         ifp 
= in6multi
.in6m_ifp
 
 335         inma_format_string 
= "\t{0: <d}: 0x{1: <x} " 
 336         out_string 
+= inma_format_string
.format(i 
+ 1, in6multi
) + " " 
 337         out_string 
+= GetIn6AddrAsString((in6multi
.in6m_addr
.__u6_addr
.__u6_addr
8)) + " " 
 338         ifma_format_string 
= "(ifp 0x{0: <x} [{1: <s}] ifma {2: <x})" 
 339         out_string 
+= ifma_format_string
.format(ifp
, ifp
.if_xname
, in6multi
.in6m_ifma
) + "\n" 
 340         in6multi 
= cast(in6multi
.in6m_entry
.le_next
, 'in6_multi *') 
 343 # EndMacro: showin6multiaddrs 
 345 def GetTcpState(tcpcb
): 
 347     tp 
= Cast(tcpcb
, 'tcpcb *') 
 350             out_string 
+= "CLOSED\t" 
 352             out_string 
+= "LISTEN\t" 
 354             out_string 
+= "SYN_SENT\t" 
 356             out_string 
+= "SYN_RCVD\t" 
 358             out_string 
+= "ESTABLISHED\t" 
 360             out_string 
+= "CLOSE_WAIT\t" 
 362             out_string 
+= "FIN_WAIT_1\t" 
 364             out_string 
+= "CLOSING\t" 
 366             out_string 
+= "LAST_ACK\t" 
 368             out_string 
+= "FIN_WAIT_2\t" 
 370             out_string 
+= "TIME_WAIT\t" 
 373 def GetSocketProtocolAsString(sock
): 
 375     inpcb 
= Cast(sock
.so_pcb
, 'inpcb *') 
 376     if sock
.so_proto
.pr_protocol 
== 6: 
 377         out_string 
+= " TCP " 
 378         out_string 
+= GetTcpState(inpcb
.inp_ppcb
) 
 379     if sock
.so_proto
.pr_protocol 
== 17: 
 380         out_string 
+= " UDP " 
 381     if sock
.so_proto
.pr_protocol 
== 1: 
 382         out_string 
+= " ICMP " 
 383     if sock
.so_proto
.pr_protocol 
== 254: 
 384         out_string 
+= " DIVERT " 
 385     if sock
.so_proto
.pr_protocol 
== 255: 
 386         out_string 
+= " RAW " 
 389 def GetInAddr4to6AsString(inaddr
): 
 391     if (inaddr 
is not None): 
 392         ia 
= Cast(inaddr
, 'char *') 
 393         inaddr_format_string 
= "{0: <d}.{1: <d}.{2: <d}.{3: <d}" 
 394         out_string 
+= inaddr_format_string
.format(ia
[0], ia
[1], ia
[2], ia
[3]) 
 397 def GetInPortAsString(port
): 
 399     port_string 
= Cast(port
, 'char *') 
 400     port_unsigned 
= dereference(Cast(port
, 'unsigned short *')) 
 402     if ((((port_unsigned 
& 0xff00) >> 8) == port_string
[0])) and (((port_unsigned 
& 0x00ff) == port_string
[1])): 
 403         out_string 
+= ":" + str(int(port_unsigned
)) 
 405         out_string 
+= ":" + str(int(((port_unsigned 
& 0xff00) >> 8) | 
((port_unsigned 
& 0x00ff) << 8))) 
 409 def GetIPv4SocketAsString(sock
) : 
 411     pcb 
= Cast(sock
.so_pcb
, 'inpcb *') 
 413         out_string 
+= "inpcb: (null) " 
 415         out_string 
+= "inpcb: " + hex(pcb
) 
 416         out_string 
+= GetSocketProtocolAsString(sock
) 
 418         out_string 
+= GetInAddr4to6AsString(addressof(pcb
.inp_dependladdr
.inp46_local
)) 
 419         out_string 
+= GetInPortAsString(addressof(pcb
.inp_lport
)) 
 421         out_string 
+= GetInAddr4to6AsString(addressof(pcb
.inp_dependfaddr
.inp46_foreign
)) 
 422         out_string 
+= GetInPortAsString(addressof(pcb
.inp_fport
)) 
 425 def GetIPv6SocketAsString(sock
) : 
 427     pcb 
= Cast(sock
.so_pcb
, 'inpcb *') 
 429         out_string 
+= "inpcb: (null) " 
 431         out_string 
+= "inpcb: " + hex(pcb
) + " " 
 432         out_string 
+= GetSocketProtocolAsString(sock
) 
 434         out_string 
+= GetIn6AddrAsString((pcb
.inp_dependladdr
.inp6_local
.__u6_addr
.__u6_addr
8)) 
 435         out_string 
+= GetInPortAsString(addressof(pcb
.inp_lport
)) 
 437         out_string 
+= GetIn6AddrAsString((pcb
.inp_dependfaddr
.inp6_foreign
.__u6_addr
.__u6_addr
8)) 
 438         out_string 
+= GetInPortAsString(addressof(pcb
.inp_fport
)) 
 441 def GetUnixDomainSocketAsString(sock
) : 
 443     pcb 
= Cast(sock
.so_pcb
, 'unpcb *') 
 445         out_string 
+= "unpcb: (null) " 
 447         out_string 
+= "unpcb: " + hex(pcb
)  + " " 
 448         out_string 
+= "unp_vnode: " + hex(pcb
.unp_vnode
) + " " 
 449         out_string 
+= "unp_conn: " + hex(pcb
.unp_conn
) + " " 
 450         out_string 
+= "unp_addr: " + GetSocketAddrAsStringUnix(pcb
.unp_addr
) 
 453 def GetSocket(socket
) : 
 454     """ Show the contents of a socket 
 456     so 
= kern
.GetValueFromAddress(unsigned(socket
), 'socket *') 
 459         sock_format_string 
= "so: 0x{0:<x}" 
 460         out_string 
+= sock_format_string
.format(so
) 
 461         domain 
= so
.so_proto
.pr_domain
 
 462         domain_name_format_string 
= " {0:<s} " 
 463         out_string 
+= domain_name_format_string
.format(domain
.dom_name
) 
 464         if (domain
.dom_family 
== 1): 
 465             out_string 
+= GetUnixDomainSocketAsString(so
) 
 466         if (domain
.dom_family 
== 2): 
 467             out_string 
+= GetIPv4SocketAsString(so
) 
 468         if (domain
.dom_family 
== 30): 
 469             out_string 
+= GetIPv6SocketAsString(so
) 
 471         out_string 
+= "(null)" 
 473 # EndMacro: showsocket 
 477 @lldb_command('showsocket') 
 478 def ShowSocket(cmd_args
=None) : 
 479     """ Show the contents of a socket 
 481     if (cmd_args 
== None or len(cmd_args
) == 0): 
 482             print "Missing argument 0 in user function." 
 484     so 
= kern
.GetValueFromAddress(cmd_args
[0], 'socket *') 
 485     if (len(str(cmd_args
[0])) > 0): 
 487         sock_format_string 
= "so: 0x{0:<x}" 
 488         out_string 
+= sock_format_string
.format(so
) 
 489         domain 
= so
.so_proto
.pr_domain
 
 490         domain_name_format_string 
= " {0:<s} " 
 491         out_string 
+= domain_name_format_string
.format(domain
.dom_name
) 
 492         if (domain
.dom_family 
== 1): 
 493             out_string 
+= GetUnixDomainSocketAsString(so
) 
 494         if (domain
.dom_family 
== 2): 
 495             out_string 
+= GetIPv4SocketAsString(so
) 
 496         if (domain
.dom_family 
== 30): 
 497             out_string 
+= GetIPv6SocketAsString(so
) 
 500         print "Unknown value passed as argument." 
 502 # EndMacro: showsocket 
 504 # Macro: showprocsockets 
 505 @lldb_command('showprocsockets') 
 506 def ShowProcSockets(cmd_args
=None): 
 507     """ Given a proc_t pointer, display information about its sockets 
 511     if cmd_args 
!= None and len(cmd_args
) > 0 : 
 512         proc 
= kern
.GetValueFromAddress(cmd_args
[0], 'proc *') 
 516             print "Unknown value passed as argument." 
 520             fpp 
= Cast(proc_fd
.fd_ofiles
, 'fileproc **') 
 521             while (count 
< proc_fd
.fd_nfiles
): 
 522                 fp 
= Cast(dereference(fpp
), 'fileproc *') 
 524                     fg 
= Cast(fp
.f_fglob
, 'fileglob *') 
 525                     if (int(fg
.fg_ops
.fo_type
) == 2): 
 526                         if (proc_fd
.fd_ofileflags
[count
] & 4): 
 530                         out_string 
+= "fd = " + str(count
) + " "  
 531                         if (fg
.fg_data 
!= 0): 
 532                             out_string 
+= GetSocket(unsigned(fg
.fg_data
)) 
 536                 fpp 
= kern
.GetValueFromAddress(unsigned(fpp 
+ 8), 'fileproc **') 
 540         print "Missing argument 0 in user function." 
 541 # EndMacro: showprocsockets 
 543 def GetProcSockets(proc
): 
 544     """ Given a proc_t pointer, display information about its sockets 
 550         out_string 
+= "Unknown value passed as argument." 
 553         fpp 
= Cast(proc_fd
.fd_ofiles
, 'fileproc **') 
 554         while (count 
< proc_fd
.fd_nfiles
): 
 555             fp 
= Cast(dereference(fpp
), 'fileproc *') 
 557                 fg 
= Cast(fp
.f_fglob
, 'fileglob *') 
 558                 if (int(fg
.fg_ops
.fo_type
) == 2): 
 559                     if (proc_fd
.fd_ofileflags
[count
] & 4): 
 563                     out_string 
+= "fd = " + str(count
) + " "  
 564                     if (fg
.fg_data 
!= 0): 
 565                         out_string 
+= GetSocket(unsigned(fg
.fg_data
)) 
 569             fpp 
= kern
.GetValueFromAddress(unsigned(fpp 
+ 8), 'fileproc **') 
 574 # Macro: showallprocsockets 
 575 @lldb_command('showallprocsockets') 
 576 def ShowAllProcSockets(cmd_args
=None): 
 577     """Display information about the sockets of all the processes 
 579     for proc 
in kern
.procs
: 
 580         print "================================================================================" 
 581         print GetProcInfo(proc
) 
 582         print GetProcSockets(proc
) 
 583 # EndMacro: showallprocsockets 
 586 def GetRtEntryPrDetailsAsString(rte
): 
 588     rt 
= Cast(rte
, 'rtentry *') 
 589     dst 
= Cast(rt
.rt_nodes
[0].rn_u
.rn_leaf
.rn_Key
, 'sockaddr *') 
 591     dst_string_format 
= "{0:<18s}" 
 592     if (dst
.sa_family 
== AF_INET
): 
 593         out_string 
+= dst_string_format
.format(GetSocketAddrAsStringInet(dst
)) + " " 
 595         if (dst
.sa_family 
== AF_INET6
): 
 596             out_string 
+= dst_string_format
.format(GetSocketAddrAsStringInet6(dst
)) + " " 
 599             if (dst
.sa_family 
== AF_LINK
): 
 600                 out_string 
+= dst_string_format
.format(GetSocketAddrAsStringLink(dst
)) 
 606                 out_string 
+= dst_string_format
.format(GetSocketAddrAsStringUnspec(dst
)) + " " 
 608     gw 
= Cast(rt
.rt_gateway
, 'sockaddr *') 
 609     if (gw
.sa_family 
== AF_INET
): 
 610         out_string 
+= dst_string_format
.format(GetSocketAddrAsStringInet(gw
)) + " " 
 612         if (gw
.sa_family 
== 30): 
 613             out_string 
+= dst_string_format
.format(GetSocketAddrAsStringInet6(gw
)) + " " 
 616             if (gw
.sa_family 
== 18): 
 617                 out_string 
+= dst_string_format
.format(GetSocketAddrAsStringLink(gw
)) + " " 
 623                 dst_string_format
.format(GetSocketAddrAsStringUnspec(gw
)) 
 625     if (rt
.rt_flags 
& RTF_WASCLONED
): 
 626         if (kern
.ptrsize 
== 8): 
 627             rt_flags_string_format 
= "0x{0:<16x}" 
 628             out_string 
+= rt_flags_string_format
.format(rt
.rt_parent
) + " " 
 630             rt_flags_string_format 
= "0x{0:<8x}" 
 631             out_string 
+= rt_flags_string_format
.format(rt
.rt_parent
) + " " 
 633         if (kern
.ptrsize 
== 8): 
 638     rt_refcnt_rmx_string_format 
= "{0:<d} {1:>10d}  " 
 639     out_string 
+= rt_refcnt_rmx_string_format
.format(rt
.rt_refcnt
, rt
.rt_rmx
.rmx_pksent
) + "   " 
 641     rtf_string_format 
= "{0:>s}" 
 642     if (rt
.rt_flags 
& RTF_UP
): 
 643         out_string 
+= rtf_string_format
.format("U") 
 644     if (rt
.rt_flags 
& RTF_GATEWAY
): 
 645         out_string 
+= rtf_string_format
.format("G") 
 646     if (rt
.rt_flags 
& RTF_HOST
): 
 647         out_string 
+= rtf_string_format
.format("H") 
 648     if (rt
.rt_flags 
& RTF_REJECT
): 
 649         out_string 
+= rtf_string_format
.format("R") 
 650     if (rt
.rt_flags 
& RTF_DYNAMIC
): 
 651         out_string 
+= rtf_string_format
.format("D") 
 652     if (rt
.rt_flags 
& RTF_MODIFIED
): 
 653         out_string 
+= rtf_string_format
.format("M") 
 654     if (rt
.rt_flags 
& RTF_CLONING
): 
 655         out_string 
+= rtf_string_format
.format("C") 
 656     if (rt
.rt_flags 
& RTF_PRCLONING
): 
 657         out_string 
+= rtf_string_format
.format("c") 
 658     if (rt
.rt_flags 
& RTF_LLINFO
): 
 659         out_string 
+= rtf_string_format
.format("L") 
 660     if (rt
.rt_flags 
& RTF_STATIC
): 
 661         out_string 
+= rtf_string_format
.format("S") 
 662     if (rt
.rt_flags 
& RTF_PROTO1
): 
 663         out_string 
+= rtf_string_format
.format("1") 
 664     if (rt
.rt_flags 
& RTF_PROTO2
): 
 665         out_string 
+= rtf_string_format
.format("2") 
 666     if (rt
.rt_flags 
& RTF_PROTO3
): 
 667         out_string 
+= rtf_string_format
.format("3") 
 668     if (rt
.rt_flags 
& RTF_WASCLONED
): 
 669         out_string 
+= rtf_string_format
.format("W") 
 670     if (rt
.rt_flags 
& RTF_BROADCAST
): 
 671         out_string 
+= rtf_string_format
.format("b") 
 672     if (rt
.rt_flags 
& RTF_MULTICAST
): 
 673         out_string 
+= rtf_string_format
.format("m") 
 674     if (rt
.rt_flags 
& RTF_XRESOLVE
): 
 675         out_string 
+= rtf_string_format
.format("X") 
 676     if (rt
.rt_flags 
& RTF_BLACKHOLE
): 
 677         out_string 
+= rtf_string_format
.format("B") 
 678     if (rt
.rt_flags 
& RTF_IFSCOPE
): 
 679         out_string 
+= rtf_string_format
.format("I") 
 680     if (rt
.rt_flags 
& RTF_CONDEMNED
): 
 681         out_string 
+= rtf_string_format
.format("Z") 
 682     if (rt
.rt_flags 
& RTF_IFREF
): 
 683         out_string 
+= rtf_string_format
.format("i") 
 684     if (rt
.rt_flags 
& RTF_PROXY
): 
 685         out_string 
+= rtf_string_format
.format("Y") 
 686     if (rt
.rt_flags 
& RTF_ROUTER
): 
 687         out_string 
+= rtf_string_format
.format("r") 
 690     out_string 
+= str(rt
.rt_ifp
.if_name
) 
 691     out_string 
+= str(int(rt
.rt_ifp
.if_unit
)) 
 697 def GetRtTableAsString(rt_tables
): 
 699     rn 
= Cast(rt_tables
.rnh_treetop
, 'radix_node *') 
 700     rnh_cnt 
= rt_tables
.rnh_cnt
 
 702     while (rn
.rn_bit 
>= 0): 
 703         rn 
= rn
.rn_u
.rn_node
.rn_L
 
 706         base 
= Cast(rn
, 'radix_node *') 
 707         while ((rn
.rn_parent
.rn_u
.rn_node
.rn_R 
== rn
) and (rn
.rn_flags 
& RNF_ROOT 
== 0)): 
 709         rn 
= rn
.rn_parent
.rn_u
.rn_node
.rn_R
 
 710         while (rn
.rn_bit 
>= 0): 
 711             rn 
= rn
.rn_u
.rn_node
.rn_L
 
 715             base 
= rn
.rn_u
.rn_leaf
.rn_Dupedkey
 
 716             if ((rn
.rn_flags 
& RNF_ROOT
) == 0): 
 717                 rt 
= Cast(rn
, 'rtentry *') 
 718                 if (kern
.ptrsize 
== 8): 
 719                     rtentry_string_format 
= "0x{0:<18x}" 
 720                     out_string 
+= rtentry_string_format
.format(rt
) + " " 
 722                     rtentry_string_format 
= "0x{0:<10x}" 
 723                     out_string 
+= rtentry_string_format
.format(rt
) + " " 
 724                 out_string 
+= GetRtEntryPrDetailsAsString(rt
) + " " 
 727         if ((rn
.rn_flags 
& RNF_ROOT
) != 0): 
 731 def GetRtInetAsString(): 
 732     rt_tables 
= kern
.globals.rt_tables
[2] 
 733     if (kern
.ptrsize 
== 8): 
 734         rt_table_header_format_string 
= "{0:<18s} {1: <16s} {2:<20s} {3:<16s} {4:<8s} {5:<8s} {6:<8s}" 
 735         print rt_table_header_format_string
.format("rtentry", " dst", "gw", "parent", "Refs", "Use", "flags/if")  
 736         print rt_table_header_format_string
.format("-" * 18, "-" * 16, "-" * 16, "-" * 16, "-" * 8, "-" * 8, "-" * 8) 
 737         print GetRtTableAsString(rt_tables
) 
 739         rt_table_header_format_string 
= "{0:<8s} {1:<16s} {2:<18s} {3:<8s} {4:<8s} {5:<8s} {6:<8s}" 
 740         print rt_table_header_format_string
.format("rtentry", "dst", "gw", "parent", "Refs", "Use", "flags/if")  
 741         print rt_table_header_format_string
.format("-" * 8, "-" * 16, "-" * 16, "-" * 8, "-" * 8, "-" * 8, "-" * 8)  
 742         print GetRtTableAsString(rt_tables
) 
 744 def GetRtInet6AsString(): 
 745     rt_tables 
= kern
.globals.rt_tables
[30] 
 746     if (kern
.ptrsize 
== 8): 
 747         rt_table_header_format_string 
= "{0:<18s} {1: <16s} {2:<20s} {3:<16s} {4:<8s} {5:<8s} {6:<8s}" 
 748         print rt_table_header_format_string
.format("rtentry", " dst", "gw", "parent", "Refs", "Use", "flags/if")  
 749         print rt_table_header_format_string
.format("-" * 18, "-" * 16, "-" * 16, "-" * 16, "-" * 8, "-" * 8, "-" * 8) 
 750         print GetRtTableAsString(rt_tables
) 
 752         rt_table_header_format_string 
= "{0:<8s} {1:<16s} {2:<18s} {3:<8s} {4:<8s} {5:<8s} {6:<8s}" 
 753         print rt_table_header_format_string
.format("rtentry", "dst", "gw", "parent", "Refs", "Use", "flags/if")  
 754         print rt_table_header_format_string
.format("-" * 8, "-" * 16, "-" * 18, "-" * 8, "-" * 8, "-" * 8, "-" * 8)  
 755         print GetRtTableAsString(rt_tables
) 
 757 # Macro: show_rt_inet 
 758 @lldb_command('show_rt_inet') 
 759 def ShowRtInet(cmd_args
=None): 
 760     """ Display the IPv4 routing table 
 762     print GetRtInetAsString()  
 763 # EndMacro: show_rt_inet 
 765 # Macro: show_rt_inet6 
 766 @lldb_command('show_rt_inet6') 
 767 def ShowRtInet6(cmd_args
=None): 
 768     """ Display the IPv6 routing table 
 770     print GetRtInet6AsString() 
 771 # EndMacro: show_rt_inet6 
 773 # Macro: rtentry_showdbg 
 774 @lldb_command('rtentry_showdbg') 
 775 def ShowRtEntryDebug(cmd_args
=None): 
 776     """ Print the debug information of a route entry 
 778     if (cmd_args 
== None or len(cmd_args
) == 0): 
 779             print "Missing argument 0 in user function." 
 783     rtd 
= kern
.GetValueFromAddress(cmd_args
[0], 'rtentry_dbg *') 
 784     rtd_summary_format_string 
= "{0:s} {1:d}" 
 785     out_string 
+= rtd_summary_format_string
.format("Total holds : ", rtd
.rtd_refhold_cnt
) + "\n" 
 786     out_string 
+= rtd_summary_format_string
.format("Total releases : ", rtd
.rtd_refrele_cnt
) + "\n" 
 789     while (ix 
< CTRACE_STACK_SIZE
): 
 790         kgm_pc 
= rtd
.rtd_alloc
.pc
[ix
] 
 793                 out_string 
+= "\nAlloc: (thread " + hex(rtd
.rtd_alloc
.th
) + "):\n" 
 794             out_string 
+= str(int(ix 
+ 1)) + ": " 
 795             out_string 
+= GetSourceInformationForAddress(kgm_pc
) 
 800     while (ix 
< CTRACE_STACK_SIZE
): 
 801         kgm_pc 
= rtd
.rtd_free
.pc
[ix
] 
 804                 out_string 
+= "\nFree: (thread " + hex(rtd
.rtd_free
.th
) + "):\n" 
 805             out_string 
+= str(int(ix 
+ 1)) + ": " 
 806             out_string 
+= GetSourceInformationForAddress(kgm_pc
) 
 810     while (cnt 
< RTD_TRACE_HIST_SIZE
): 
 812         while (ix 
< CTRACE_STACK_SIZE
): 
 813             kgm_pc 
= rtd
.rtd_refhold
[cnt
].pc
[ix
] 
 816                     out_string 
+= "\nHold [" + str(int(cnt
)) + "] (thread " + hex(rtd
.rtd_refhold
[cnt
].th
) + "):\n" 
 817                 out_string 
+= str(int(ix 
+ 1)) + ": " 
 818                 out_string 
+= GetSourceInformationForAddress(kgm_pc
) 
 824     while (cnt 
< RTD_TRACE_HIST_SIZE
): 
 826         while (ix 
< CTRACE_STACK_SIZE
): 
 827             kgm_pc 
= rtd
.rtd_refrele
[cnt
].pc
[ix
] 
 830                     out_string 
+= "\nRelease [" + str(int(cnt
)) + "] (thread " + hex(rtd
.rtd_refrele
[cnt
].th
) + "):\n" 
 831                 out_string 
+= str(int(ix 
+ 1)) + ": " 
 832                 out_string 
+= GetSourceInformationForAddress(kgm_pc
) 
 837     out_string 
+= "\nTotal locks : " + str(int(rtd
.rtd_lock_cnt
)) 
 838     out_string 
+= "\nTotal unlocks : " + str(int(rtd
.rtd_unlock_cnt
)) 
 841     while (cnt 
< RTD_TRACE_HIST_SIZE
): 
 843         while (ix 
< CTRACE_STACK_SIZE
): 
 844             kgm_pc 
= rtd
.rtd_lock
[cnt
].pc
[ix
] 
 847                     out_string 
+= "\nLock [" + str(int(cnt
)) + "] (thread " + hex(rtd
.rtd_lock
[cnt
].th
) + "):\n" 
 848                 out_string 
+= str(int(ix 
+ 1)) + ": " 
 849                 out_string 
+= GetSourceInformationForAddress(kgm_pc
) 
 855     while (cnt 
< RTD_TRACE_HIST_SIZE
): 
 857         while (ix 
< CTRACE_STACK_SIZE
): 
 858             kgm_pc 
= rtd
.rtd_unlock
[cnt
].pc
[ix
] 
 861                     out_string 
+= "\nUnlock [" + str(int(cnt
)) + "] (thread " + hex(rtd
.rtd_unlock
[cnt
].th
) + "):\n" 
 862                 out_string 
+= str(int(ix 
+ 1)) + ": " 
 863                 out_string 
+= GetSourceInformationForAddress(kgm_pc
) 
 869 # EndMacro: rtentry_showdbg 
 871 # Macro: inifa_showdbg 
 872 @lldb_command('inifa_showdbg') 
 873 def InIfaShowDebug(cmd_args
=None): 
 874     """ Print the debug information of an IPv4 interface address 
 876     if (cmd_args 
== None or len(cmd_args
) == 0): 
 877             print "Missing argument 0 in user function." 
 881     inifa 
= kern
.GetValueFromAddress(cmd_args
[0], 'in_ifaddr_dbg *') 
 882     in_ifaddr_summary_format_string 
= "{0:s} {1:d}" 
 883     out_string 
+= in_ifaddr_summary_format_string
.format("Total holds : ", inifa
.inifa_refhold_cnt
) + "\n" 
 884     out_string 
+= in_ifaddr_summary_format_string
.format("Total releases : ", inifa
.inifa_refrele_cnt
) + "\n" 
 887     while (ix 
< CTRACE_STACK_SIZE
): 
 888         kgm_pc 
= inifa
.inifa_alloc
.pc
[ix
] 
 891                 out_string 
+= "\nAlloc: (thread " + hex(inifa
.inifa_alloc
.th
) + "):\n" 
 892             out_string 
+= str(int(ix 
+ 1)) + ": " 
 893             out_string 
+= GetSourceInformationForAddress(kgm_pc
) 
 898     while (ix 
< CTRACE_STACK_SIZE
): 
 899         kgm_pc 
= inifa
.inifa_free
.pc
[ix
] 
 902                 out_string 
+= "\nFree: (thread " + hex(inifa
.inifa_free
.th
) + "):\n" 
 903             out_string 
+= str(int(ix 
+ 1)) + ": " 
 904             out_string 
+= GetSourceInformationForAddress(kgm_pc
) 
 908     while (cnt 
< INIFA_TRACE_HIST_SIZE
): 
 910         while (ix 
< CTRACE_STACK_SIZE
): 
 911             kgm_pc 
= inifa
.inifa_refhold
[cnt
].pc
[ix
] 
 914                     out_string 
+= "\nHold [" + str(int(cnt
)) + "] (thread " + hex(inifa
.inifa_refhold
[cnt
].th
) + "):\n" 
 915                 out_string 
+= str(int(ix 
+ 1)) + ": " 
 916                 out_string 
+= GetSourceInformationForAddress(kgm_pc
) 
 922     while (cnt 
< INIFA_TRACE_HIST_SIZE
): 
 924         while (ix 
< CTRACE_STACK_SIZE
): 
 925             kgm_pc 
= inifa
.inifa_refrele
[cnt
].pc
[ix
] 
 928                     out_string 
+= "\nRelease [" + str(int(cnt
)) + "] (thread " + hex(inifa
.inifa_refrele
[cnt
].th
) + "):\n" 
 929                 out_string 
+= str(int(ix 
+ 1)) + ": " 
 930                 out_string 
+= GetSourceInformationForAddress(kgm_pc
) 
 935 # EndMacro: inifa_showdbg 
 937 # Macro: in6ifa_showdbg 
 938 @lldb_command('in6ifa_showdbg') 
 939 def In6IfaShowDebug(cmd_args
=None): 
 940     """ Print the debug information of an IPv6 interface address 
 942     if (cmd_args 
== None or len(cmd_args
) == 0): 
 943             print "Missing argument 0 in user function." 
 947     in6ifa 
= kern
.GetValueFromAddress(cmd_args
[0], 'in6_ifaddr_dbg *') 
 948     in6_ifaddr_summary_format_string 
= "{0:s} {1:d}" 
 949     print in6_ifaddr_summary_format_string
.format("Total holds : ", in6ifa
.in6ifa_refhold_cnt
) 
 950     print in6_ifaddr_summary_format_string
.format("Total releases : ", in6ifa
.in6ifa_refrele_cnt
) 
 953     while (ix 
< CTRACE_STACK_SIZE
): 
 954         kgm_pc 
= in6ifa
.in6ifa_alloc
.pc
[ix
] 
 957                 out_string 
+= "\nAlloc: (thread " + hex(in6ifa
.in6ifa_alloc
.th
) + "):\n" 
 958             out_string 
+= str(int(ix 
+ 1)) + ": " 
 959             out_string 
+= GetSourceInformationForAddress(kgm_pc
) 
 964     while (ix 
< CTRACE_STACK_SIZE
): 
 965         kgm_pc 
= in6ifa
.in6ifa_free
.pc
[ix
] 
 968                 out_string 
+= "\nFree: (thread " + hex(in6ifa
.in6ifa_free
.th
) + "):\n" 
 969             out_string 
+= str(int(ix 
+ 1)) + ": " 
 970             out_string 
+= GetSourceInformationForAddress(kgm_pc
) 
 974     while (cnt 
< IN6IFA_TRACE_HIST_SIZE
): 
 976         while (ix 
< CTRACE_STACK_SIZE
): 
 977             kgm_pc 
= in6ifa
.in6ifa_refhold
[cnt
].pc
[ix
] 
 980                     out_string 
+= "\nHold [" + str(int(cnt
)) + "] (thread " + hex(in6ifa
.in6ifa_refhold
[cnt
].th
) + "):\n" 
 981                 out_string 
+= str(int(ix 
+ 1)) + ": " 
 982                 out_string 
+= GetSourceInformationForAddress(kgm_pc
) 
 988     while (cnt 
< IN6IFA_TRACE_HIST_SIZE
): 
 990         while (ix 
< CTRACE_STACK_SIZE
): 
 991             kgm_pc 
= in6ifa
.in6ifa_refrele
[cnt
].pc
[ix
] 
 994                     out_string 
+= "\nRelease [" + str(int(cnt
)) + "] (thread " + hex(in6ifa
.in6ifa_refrele
[cnt
].th
) + "):\n" 
 995                 out_string 
+= str(int(ix 
+ 1)) + ": " 
 996                 out_string 
+= GetSourceInformationForAddress(kgm_pc
) 
1001 # EndMacro: in6ifa_showdbg 
1003 # Macro: inm_showdbg 
1004 @lldb_command('inm_showdbg') 
1005 def InmShowDebug(cmd_args
=None): 
1006     """ Print the debug information of an IPv4 multicast address 
1008     if (cmd_args 
== None or len(cmd_args
) == 0): 
1009             print "Missing argument 0 in user function." 
1013     inm 
= kern
.GetValueFromAddress(cmd_args
[0], 'in_multi_dbg *') 
1014     in_multi_summary_format_string 
= "{0:s} {1:d}" 
1015     out_string 
+= in_multi_summary_format_string
.format("Total holds : ", inm
.inm_refhold_cnt
) 
1016     out_string 
+= in_multi_summary_format_string
.format("Total releases : ", inm
.inm_refrele_cnt
) 
1018     while (cnt 
< INM_TRACE_HIST_SIZE
): 
1020         while (ix 
< CTRACE_STACK_SIZE
): 
1021             kgm_pc 
= inm
.inm_refhold
[cnt
].pc
[ix
] 
1024                     out_string 
+= "\nHold [" + str(int(cnt
)) + "] (thread " + hex(inm
.inm_refhold
[cnt
].th
) + "):\n" 
1025                 out_string 
+= str(int(ix 
+ 1)) + ": " 
1026                 out_string 
+= GetSourceInformationForAddress(kgm_pc
) 
1031     while (cnt 
< INM_TRACE_HIST_SIZE
): 
1033         while (ix 
< CTRACE_STACK_SIZE
): 
1034             kgm_pc 
= inm
.inm_refrele
[cnt
].pc
[ix
] 
1037                     out_string 
+= "\nRelease [" + str(int(cnt
)) + "] (thread " + hex(inm
.inm_refrele
[cnt
].th
) + "):\n" 
1038                 out_string 
+= str(int(ix 
+ 1)) + ": " 
1039                 out_string 
+= GetSourceInformationForAddress(kgm_pc
) 
1044 # EndMacro: inm_showdbg 
1046 # Macro: ifma_showdbg 
1047 @lldb_command('ifma_showdbg') 
1048 def IfmaShowDebug(cmd_args
=None): 
1049     """ Print the debug information of a link multicast address 
1051     if (cmd_args 
== None or len(cmd_args
) == 0): 
1052             print "Missing argument 0 in user function." 
1056     ifma 
= kern
.GetValueFromAddress(cmd_args
[0], 'ifmultiaddr_dbg *') 
1057     link_multi_summary_format_string 
= "{0:s} {1:d}" 
1058     out_string 
+= link_multi_summary_format_string
.format("Total holds : ", ifma
.ifma_refhold_cnt
) + "\n" 
1059     out_string 
+= link_multi_summary_format_string
.format("Total releases : ", ifma
.ifma_refrele_cnt
) + "\n" 
1061     while (cnt 
< IFMA_TRACE_HIST_SIZE
): 
1063         while (ix 
< CTRACE_STACK_SIZE
): 
1064             kgm_pc 
= ifma
.ifma_refhold
[cnt
].pc
[ix
] 
1067                     out_string 
+= "\nHold [" + str(int(cnt
)) + "] (thread " + hex(ifma
.ifma_refhold
[cnt
].th
) + "):\n" 
1068                 out_string 
+= str(int(ix 
+ 1)) + ": " 
1069                 out_string 
+= GetSourceInformationForAddress(kgm_pc
) 
1074     while (cnt 
< IFMA_TRACE_HIST_SIZE
): 
1076         while (ix 
< CTRACE_STACK_SIZE
): 
1077             kgm_pc 
= ifma
.ifma_refrele
[cnt
].pc
[ix
] 
1080                     out_string 
+= "\nRelease [" + str(int(cnt
)) + "] (thread " + hex(ifma
.ifma_refrele
[cnt
].th
) + "):\n" 
1081                 out_string 
+= str(int(ix 
+ 1)) + ": " 
1082                 out_string 
+= GetSourceInformationForAddress(kgm_pc
) 
1087 # EndMacro: ifma_showdbg 
1089 # Macro: ifpref_showdbg 
1090 @lldb_command('ifpref_showdbg') 
1091 def IfpRefShowDebug(cmd_args
=None): 
1092     """ Print the debug information of an interface ref count 
1094     if (cmd_args 
== None or len(cmd_args
) == 0): 
1095             print "Missing argument 0 in user function." 
1099     dl_if 
= kern
.GetValueFromAddress(cmd_args
[0], 'dlil_ifnet_dbg *') 
1100     dl_if_summary_format_string 
= "{0:s} {1:d}" 
1101     out_string 
+=  dl_if_summary_format_string
.format("Total holds : ", dl_if
.dldbg_if_refhold_cnt
) 
1102     out_string 
+= dl_if_summary_format_string
.format("Total releases : ", dl_if
.dldbg_if_refrele_cnt
) 
1104     while (cnt 
< IF_REF_TRACE_HIST_SIZE
): 
1106         while (ix 
< CTRACE_STACK_SIZE
): 
1107             kgm_pc 
= dl_if
.dldbg_if_refhold
[cnt
].pc
[ix
] 
1110                     out_string 
+= "\nHold [" + str(int(cnt
)) + "] (thread " + hex(dl_if
.dldbg_if_refhold
[cnt
].th
) + "):\n" 
1111                 out_string 
+= str(int(ix 
+ 1)) + ": " 
1112                 out_string 
+= GetSourceInformationForAddress(kgm_pc
) 
1117     while (cnt 
< IF_REF_TRACE_HIST_SIZE
): 
1119         while (ix 
< CTRACE_STACK_SIZE
): 
1120             kgm_pc 
= dl_if
.dldbg_if_refrele
[cnt
].pc
[ix
] 
1123                     out_string 
+= "\nRelease [" + str(int(cnt
)) + "] (thread " + hex(dl_if
.dldbg_if_refrele
[cnt
].th
) + "):\n" 
1124                 out_string 
+= str(int(ix 
+ 1)) + ": " 
1125                 out_string 
+= GetSourceInformationForAddress(kgm_pc
) 
1130 # EndMacro: ifpref_showdbg 
1132 # Macro: ndpr_showdbg 
1133 @lldb_command('ndpr_showdbg') 
1134 def ndprShowDebug(cmd_args
=None): 
1135     """ Print the debug information of a nd_prefix structure 
1137     if (cmd_args 
== None or len(cmd_args
) == 0): 
1138             print "Missing argument 0 in user function." 
1142     ndpr 
= kern
.GetValueFromAddress(cmd_args
[0], 'nd_prefix_dbg *') 
1143     ndpr_summary_format_string 
= "{0:s} {1:d}" 
1144     out_string 
+= ndpr_summary_format_string
.format("Total holds : ", ndpr
.ndpr_refhold_cnt
) 
1145     out_string 
+= ndpr_summary_format_string
.format("Total releases : ", ndpr
.ndpr_refrele_cnt
) 
1147     while (cnt 
< NDPR_TRACE_HIST_SIZE
): 
1149         while (ix 
< CTRACE_STACK_SIZE
): 
1150             kgm_pc 
= ndpr
.ndpr_refhold
[cnt
].pc
[ix
] 
1153                     out_string 
+= "\nHold [" + str(int(cnt
)) + "] (thread " + hex(ndpr
.ndpr_refhold
[cnt
].th
) + "):\n" 
1154                 out_string 
+= str(int(ix 
+ 1)) + ": " 
1155                 out_string 
+= GetSourceInformationForAddress(kgm_pc
) 
1160     while (cnt 
< NDPR_TRACE_HIST_SIZE
): 
1162         while (ix 
< CTRACE_STACK_SIZE
): 
1163             kgm_pc 
= ndpr
.ndpr_refrele
[cnt
].pc
[ix
] 
1166                     out_string 
+= "\nRelease [" + str(int(cnt
)) + "] (thread " + hex(ndpr
.ndpr_refrele
[cnt
].th
) + "):\n" 
1167                 out_string 
+= str(int(ix 
+ 1)) + ": " 
1168                 out_string 
+= GetSourceInformationForAddress(kgm_pc
) 
1173 # EndMacro: ndpr_showdbg 
1175 # Macro: nddr_showdbg 
1176 @lldb_command('nddr_showdbg') 
1177 def nddrShowDebug(cmd_args
=None): 
1178     """ Print the debug information of a nd_defrouter structure 
1180     if (cmd_args 
== None or len(cmd_args
) == 0): 
1181             print "Missing argument 0 in user function." 
1185     nddr 
= kern
.GetValueFromAddress(cmd_args
[0], 'nd_defrouter_dbg *') 
1186     nddr_summary_format_string 
= "{0:s} {1:d}" 
1187     out_string 
+= nddr_summary_format_string
.format("Total holds : ", nddr
.nddr_refhold_cnt
) 
1188     out_string 
+= nddr_summary_format_string
.format("Total releases : ", nddr
.nddr_refrele_cnt
) 
1190     while (cnt 
< NDDR_TRACE_HIST_SIZE
): 
1192         while (ix 
< CTRACE_STACK_SIZE
): 
1193             kgm_pc 
= nddr
.nddr_refhold
[cnt
].pc
[ix
] 
1196                     out_string 
+= "\nHold [" + str(int(cnt
)) + "] (thread " + hex(nddr
.nddr_refhold
[cnt
].th
) + "):\n" 
1197                 out_string 
+= str(int(ix 
+ 1)) + ": " 
1198                 out_string 
+= GetSourceInformationForAddress(kgm_pc
) 
1203     while (cnt 
< NDDR_TRACE_HIST_SIZE
): 
1205         while (ix 
< CTRACE_STACK_SIZE
): 
1206             kgm_pc 
= nddr
.nddr_refrele
[cnt
].pc
[ix
] 
1209                     out_string 
+= "\nRelease [" + str(int(cnt
)) + "] (thread " + hex(nddr
.nddr_refrele
[cnt
].th
) + "):\n" 
1210                 out_string 
+= str(int(ix 
+ 1)) + ": " 
1211                 out_string 
+= GetSourceInformationForAddress(kgm_pc
) 
1216 # EndMacro: nddr_showdbg 
1218 # Macro: imo_showdbg 
1219 @lldb_command('imo_showdbg') 
1220 def IpmOptions(cmd_args
=None): 
1221     """ Print the debug information of a ip_moptions structure 
1223     if (cmd_args 
== None or len(cmd_args
) == 0): 
1224             print "Missing argument 0 in user function." 
1228     imo 
= kern
.GetValueFromAddress(cmd_args
[0], 'ip_moptions_dbg *') 
1229     imo_summary_format_string 
= "{0:s} {1:d}" 
1230     out_string 
+= imo_summary_format_string
.format("Total holds : ", imo
.imo_refhold_cnt
) 
1231     out_string 
+= imo_summary_format_string
.format("Total releases : ", imo
.imo_refrele_cnt
) 
1233     while (cnt 
< IMO_TRACE_HIST_SIZE
): 
1235         while (ix 
< CTRACE_STACK_SIZE
): 
1236             kgm_pc 
= imo
.imo_refhold
[cnt
].pc
[ix
] 
1239                     out_string 
+= "\nHold [" + str(int(cnt
)) + "] (thread " + hex(imo
.imo_refhold
[cnt
].th
) + "):\n" 
1240                 out_string 
+= str(int(ix 
+ 1)) + ": " 
1241                 out_string 
+= GetSourceInformationForAddress(kgm_pc
) 
1246     while (cnt 
< IMO_TRACE_HIST_SIZE
): 
1248         while (ix 
< CTRACE_STACK_SIZE
): 
1249             kgm_pc 
= imo
.imo_refrele
[cnt
].pc
[ix
] 
1252                     out_string 
+= "\nRelease [" + str(int(cnt
)) + "] (thread " + hex(imo
.imo_refrele
[cnt
].th
) + "):\n" 
1253                 out_string 
+= str(int(ix 
+ 1)) + ": " 
1254                 out_string 
+= GetSourceInformationForAddress(kgm_pc
) 
1259 # EndMacro: imo_showdbg 
1261 # Macro: im6o_showdbg 
1262 @lldb_command('im6o_showdbg') 
1263 def IpmOptions(cmd_args
=None): 
1264     """ Print the debug information of a ip6_moptions structure 
1266     if (cmd_args 
== None or len(cmd_args
) == 0): 
1267             print "Missing argument 0 in user function." 
1271     im6o 
= kern
.GetValueFromAddress(cmd_args
[0], 'ip6_moptions_dbg *') 
1272     im6o_summary_format_string 
= "{0:s} {1:d}" 
1273     out_string 
+= im6o_summary_format_string
.format("Total holds : ", im6o
.im6o_refhold_cnt
) 
1274     out_string 
+= im6o_summary_format_string
.format("Total releases : ", im6o
.im6o_refrele_cnt
) 
1276     while (cnt 
< IM6O_TRACE_HIST_SIZE
): 
1278         while (ix 
< CTRACE_STACK_SIZE
): 
1279             kgm_pc 
= im6o
.im6o_refhold
[cnt
].pc
[ix
] 
1282                     out_string 
+= "\nHold [" + str(int(cnt
)) + "] (thread " + hex(im6o
.im6o_refhold
[cnt
].th
) + "):\n" 
1283                 out_string 
+= str(int(ix 
+ 1)) + ": " 
1284                 out_string 
+= GetSourceInformationForAddress(kgm_pc
) 
1289     while (cnt 
< IM6O_TRACE_HIST_SIZE
): 
1291         while (ix 
< CTRACE_STACK_SIZE
): 
1292             kgm_pc 
= im6o
.im6o_refrele
[cnt
].pc
[ix
] 
1295                     out_string 
+= "\nRelease [" + str(int(cnt
)) + "] (thread " + hex(im6o
.im6o_refrele
[cnt
].th
) + "):\n" 
1296                 out_string 
+= str(int(ix 
+ 1)) + ": " 
1297                 out_string 
+= GetSourceInformationForAddress(kgm_pc
) 
1302 # EndMacro: im6o_showdbg 
1304 # Macro: rtentry_trash 
1305 @lldb_command('rtentry_trash') 
1306 def RtEntryTrash(cmd_args
=None): 
1307     """ Walk the list of trash route entries 
1310     rt_trash_head 
= kern
.globals.rttrash_head
 
1311     rtd 
= Cast(rt_trash_head
.tqh_first
, 'rtentry_dbg *') 
1312     rt_trash_format_string 
= "{0:4d}: {1:x} {2:3d} {3:6d} {4:6d}" 
1314     while (int(rtd
) != 0): 
1316             if (kern
.ptrsize 
== 8): 
1317                 print "                rtentry ref   hold   rele             dst    gw             parent flags/if\n" 
1318                 print "      ----------------- --- ------ ------ --------------- ----- ------------------ -----------\n" 
1320                 print "        rtentry ref   hold   rele             dst    gw     parent flags/if\n" 
1321                 print "      --------- --- ------ ------ --------------- ----- ---------- -----------\n" 
1322         out_string 
+= rt_trash_format_string
.format(cnt
, rtd
, rtd
.rtd_refhold_cnt 
- rtd
.rtd_refrele_cnt
, rtd
.rtd_refhold_cnt
, rtd
.rtd_refrele_cnt
) + "   " 
1323         out_string 
+= GetRtEntryPrDetailsAsString(rtd
) + "\n" 
1324         rtd 
= rtd
.rtd_trash_link
.tqe_next
 
1327 # EndMacro: rtentry_trash 
1329 # Macro: show_rtentry 
1330 @lldb_command('show_rtentry') 
1331 def ShRtEntry(cmd_args
=None): 
1335     rt 
= kern
.GetValueFromAddress(cmd_args
[0], 'rtentry *') 
1336     out_string 
+= GetRtEntryPrDetailsAsString(rt
) + "\n" 
1338 # EndMacro: show_rtentry 
1340 # Macro: inifa_trash 
1341 @lldb_command('inifa_trash') 
1342 def InIfaTrash(cmd_args
=None): 
1343     """ Walk the list of trash in_ifaddr entries 
1346     ifa_trash_head 
= kern
.globals.inifa_trash_head
 
1347     ifa 
= Cast(ifa_trash_head
.tqh_first
, 'in_ifaddr_dbg *') 
1348     inifa_trash_format_string 
= "{0:4d}: {1:x} {2:3d} {3:6d} {4:6d}" 
1350     while (int(ifa
) != 0): 
1352             if (kern
.ptrsize 
== 8): 
1353                 print "                  in_ifa  ref   hold   rele" 
1354                 print "      ------------------  ---  ------  ----" 
1356                 print "          in_ifa  ref   hold   rele" 
1357                 print "      ----------  ---  ----- ------" 
1358         out_string 
+= inifa_trash_format_string
.format(cnt 
+ 1, ifa
, ifa
.inifa_refhold_cnt 
- ifa
.inifa_refrele_cnt
, ifa
.inifa_refhold_cnt
, ifa
.inifa_refrele_cnt
) + "   " 
1359         out_string 
+= GetSocketAddrAsStringInet(ifa
.inifa
.ia_ifa
.ifa_addr
) + "\n" 
1360         ifa 
= ifa
.inifa_trash_link
.tqe_next
 
1363 # EndMacro: inifa_trash 
1365 # Macro: in6ifa_trash 
1366 @lldb_command('in6ifa_trash') 
1367 def In6IfaTrash(cmd_args
=None): 
1368     """ Walk the list of trash in6_ifaddr entries 
1371     in6ifa_trash_head 
= kern
.globals.in6ifa_trash_head
 
1372     ifa 
= Cast(in6ifa_trash_head
.tqh_first
, 'in6_ifaddr_dbg *') 
1373     in6ifa_trash_format_string 
= "{0:4d}: 0x{1:x} {2:3d} {3:6d} {4:6d}" 
1375     while (int(ifa
) != 0): 
1377             if (kern
.ptrsize 
== 8): 
1378                 print "                 in6_ifa  ref   hold   rele" 
1379                 print "      ------------------  --- ------ ------" 
1381                 print "         in6_ifa  ref   hold   rele" 
1382                 print "      ----------  --- ------ ------" 
1383         out_string 
+= in6ifa_trash_format_string
.format(cnt 
+ 1, ifa
, ifa
.in6ifa_refhold_cnt 
- ifa
.in6ifa_refrele_cnt
, ifa
.in6ifa_refhold_cnt
, ifa
.in6ifa_refrele_cnt
) + "   " 
1384         out_string 
+= GetSocketAddrAsStringInet6(ifa
.in6ifa
.ia_ifa
.ifa_addr
) + "\n" 
1385         ifa 
= ifa
.in6ifa_trash_link
.tqe_next
 
1388 # EndMacro: in6ifa_trash 
1391 @lldb_command('inm_trash') 
1392 def InmTrash(cmd_args
=None): 
1393     """ Walk the list of trash in_multi entries 
1396     inm_trash_head 
= kern
.globals.inm_trash_head
 
1397     inm 
= Cast(inm_trash_head
.tqh_first
, 'in_multi_dbg *') 
1398     inm_trash_format_string 
= "{0:4d}: {1:x} {2:3d} {3:6d} {4:6d}" 
1400     while (int(inm
) != 0): 
1402             if (kern
.ptrsize 
== 8): 
1403                 print "                     inm  ref   hold   rele" 
1404                 print "      ------------------  --- ------ ------" 
1406                 print "             inm  ref   hold   rele" 
1407                 print "      ----------  --- ------ ------" 
1408         out_string 
+= inm_trash_format_string
.format(cnt 
+ 1, inm
, inm
.inm_refhold_cnt 
- inm
.inm_refrele_cnt
, inm
.inm_refhold_cnt
, inm
.inm_refrele_cnt
) + "   " 
1409         out_string 
+= GetInAddrAsString(addressof(inm
.inm
.inm_addr
)) + "\n" 
1410         inm 
= inm
.inm_trash_link
.tqe_next
 
1413 # EndMacro: inm_trash 
1416 @lldb_command('in6m_trash') 
1417 def In6mTrash(cmd_args
=None): 
1418     """ Walk the list of trash in6_multi entries 
1421     in6m_trash_head 
= kern
.globals.in6m_trash_head
 
1422     in6m 
= Cast(in6m_trash_head
.tqh_first
, 'in6_multi_dbg *') 
1423     in6m_trash_format_string 
= "{0:4d}: {1:x} {2:3d} {3:6d} {4:6d}" 
1425     while (int(in6m
) != 0): 
1427             if (kern
.ptrsize 
== 8): 
1428                 print "                    in6m  ref   hold   rele" 
1429                 print "      ------------------  --- ------ ------" 
1431                 print "            in6m  ref   hold   rele" 
1432                 print "      ----------  --- ------ ------" 
1433         out_string 
+= in6m_trash_format_string
.format(cnt 
+ 1, in6m
, in6m
.in6m_refhold_cnt 
- in6m
.in6m_refrele_cnt
, in6m
.in6m_refhold_cnt
, in6m
.in6m_refrele_cnt
) + "   " 
1434         out_string 
+= GetIn6AddrAsString(addressof(in6m
.in6m
.in6m_addr
)) + "\n" 
1435         in6m 
= in6m
.in6m_trash_link
.tqe_next
 
1438 # EndMacro: in6m_trash 
1441 @lldb_command('ifma_trash') 
1442 def IfmaTrash(cmd_args
=None): 
1443     """ Walk the list of trash ifmultiaddr entries 
1446     ifma_trash_head 
= kern
.globals.ifma_trash_head
 
1447     ifma 
= Cast(ifma_trash_head
.tqh_first
, 'ifmultiaddr_dbg *') 
1448     ifma_trash_format_string 
= "{0:4d}: {1:x} {2:3d} {3:6d} {4:6d}" 
1450     while (int(ifma
) != 0): 
1452             if (kern
.ptrsize 
== 8): 
1453                 print "                    ifma  ref   hold   rele" 
1454                 print "      ------------------  --- ------ ------" 
1456                 print "            ifma  ref   hold   rele" 
1457                 print "      ----------  --- ------ ------" 
1458         out_string 
+= ifma_trash_format_string
.format(cnt 
+ 1, ifma
, ifma
.ifma_refhold_cnt 
- ifma
.ifma_refrele_cnt
, ifma
.ifma_refhold_cnt
, ifma
.ifma_refrele_cnt
) + "   " 
1459         out_string 
+= GetSocketAddrAsString(ifma
.ifma
.ifma_addr
) + "\n" 
1460         out_string 
+= " @ " + ifma
.ifma
.ifma_ifp
.if_xname
 
1461         ifma 
= ifma
.ifma_trash_link
.tqe_next
 
1464 # EndMacro: ifma_trash 
1466 def GetInPcb(pcb
, proto
): 
1468     out_string 
+= hex(pcb
) 
1470     if (proto 
== IPPROTO_TCP
): 
1471         out_string 
+=  " tcp" 
1473         if (proto 
== IPPROTO_UDP
): 
1474             out_string 
+= " udp" 
1476             out_string 
+= str(proto
) +  "." 
1477     if (pcb
.inp_vflag 
& INP_IPV4
): 
1479     if (pcb
.inp_vflag 
& INP_IPV6
): 
1482     if (pcb
.inp_vflag 
& INP_IPV4
): 
1484         out_string 
+= GetInAddrAsString(addressof(pcb
.inp_dependladdr
.inp46_local
.ia46_addr4
)) 
1486         out_string 
+= GetIn6AddrAsString((pcb
.inp_dependladdr
.inp6_local
.__u6_addr
.__u6_addr
8)) 
1489     out_string 
+= Getntohs(pcb
.inp_lport
) 
1492     if (pcb
.inp_vflag 
& INP_IPV4
): 
1494         out_string 
+= GetInAddrAsString(addressof(pcb
.inp_dependfaddr
.inp46_foreign
.ia46_addr4
)) 
1496         out_string 
+= GetIn6AddrAsString((pcb
.inp_dependfaddr
.inp6_foreign
.__u6_addr
.__u6_addr
8)) 
1499     out_string 
+= Getntohs(pcb
.inp_fport
) 
1502     if (proto 
== IPPROTO_TCP
): 
1503         out_string 
+= GetTcpState(pcb
.inp_ppcb
) 
1505     if (pcb
.inp_flags 
& INP_RECVOPTS
): 
1506         out_string 
+= "recvopts " 
1507     if (pcb
.inp_flags 
& INP_RECVRETOPTS
): 
1508         out_string 
+= "recvretopts " 
1509     if (pcb
.inp_flags 
& INP_RECVDSTADDR
): 
1510         out_string 
+= "recvdstaddr " 
1511     if (pcb
.inp_flags 
& INP_HDRINCL
): 
1512         out_string 
+= "hdrincl " 
1513     if (pcb
.inp_flags 
& INP_HIGHPORT
): 
1514         out_string 
+= "highport " 
1515     if (pcb
.inp_flags 
& INP_LOWPORT
): 
1516         out_string 
+= "lowport " 
1517     if (pcb
.inp_flags 
& INP_ANONPORT
): 
1518         out_string 
+= "anonport " 
1519     if (pcb
.inp_flags 
& INP_RECVIF
): 
1520         out_string 
+= "recvif " 
1521     if (pcb
.inp_flags 
& INP_MTUDISC
): 
1522         out_string 
+= "mtudisc " 
1523     if (pcb
.inp_flags 
& INP_STRIPHDR
): 
1524         out_string 
+= "striphdr " 
1525     if (pcb
.inp_flags 
& INP_RECV_ANYIF
): 
1526         out_string 
+= "recv_anyif " 
1527     if (pcb
.inp_flags 
& INP_INADDR_ANY
): 
1528         out_string 
+= "inaddr_any " 
1529     if (pcb
.inp_flags 
& INP_RECVTTL
): 
1530         out_string 
+= "recvttl " 
1531     if (pcb
.inp_flags 
& INP_UDP_NOCKSUM
): 
1532         out_string 
+= "nocksum " 
1533     if (pcb
.inp_flags 
& INP_BOUND_IF
): 
1534         out_string 
+= "boundif " 
1535     if (pcb
.inp_flags 
& IN6P_IPV6_V6ONLY
): 
1536         out_string 
+= "v6only " 
1537     if (pcb
.inp_flags 
& IN6P_PKTINFO
): 
1538         out_string 
+= "pktinfo " 
1539     if (pcb
.inp_flags 
& IN6P_HOPLIMIT
): 
1540         out_string 
+= "hoplimit " 
1541     if (pcb
.inp_flags 
& IN6P_HOPOPTS
): 
1542         out_string 
+= "hopopts " 
1543     if (pcb
.inp_flags 
& IN6P_DSTOPTS
): 
1544         out_string 
+= "dstopts " 
1545     if (pcb
.inp_flags 
& IN6P_RTHDR
): 
1546         out_string 
+= "rthdr " 
1547     if (pcb
.inp_flags 
& IN6P_RTHDRDSTOPTS
): 
1548         out_string 
+= "rthdrdstopts " 
1549     if (pcb
.inp_flags 
& IN6P_TCLASS
): 
1550         out_string 
+= "rcv_tclass " 
1551     if (pcb
.inp_flags 
& IN6P_AUTOFLOWLABEL
): 
1552         out_string 
+= "autoflowlabel " 
1553     if (pcb
.inp_flags 
& IN6P_BINDV6ONLY
): 
1554         out_string 
+= "bindv6only " 
1555     if (pcb
.inp_flags 
& IN6P_RFC2292
): 
1556         out_string 
+= "RFC2292 " 
1557     if (pcb
.inp_flags 
& IN6P_MTU
): 
1558         out_string 
+= "rcv_pmtu " 
1559     if (pcb
.inp_flags 
& INP_PKTINFO
): 
1560         out_string 
+= "pktinfo " 
1561     if (pcb
.inp_flags 
& INP_FLOW_SUSPENDED
): 
1562         out_string 
+= "suspended " 
1563     if (pcb
.inp_flags 
& INP_NO_IFT_CELLULAR
): 
1564         out_string 
+= "nocellular " 
1565     if (pcb
.inp_flags 
& INP_FLOW_CONTROLLED
): 
1566         out_string 
+= "flowctld " 
1567     if (pcb
.inp_flags 
& INP_FC_FEEDBACK
): 
1568         out_string 
+= "fcfeedback " 
1569     if (pcb
.inp_flags2 
& INP2_TIMEWAIT
): 
1570         out_string 
+= "timewait " 
1571     if (pcb
.inp_flags2 
& INP2_IN_FCTREE
): 
1572         out_string 
+= "in_fctree " 
1573     if (pcb
.inp_flags2 
& INP2_WANT_APP_POLICY
): 
1574         out_string 
+= "want_app_policy " 
1578         out_string 
+= "[so=" + str(so
) + " s=" + str(int(so
.so_snd
.sb_cc
)) + " r=" + str(int(so
.so_rcv
.sb_cc
)) + " usecnt=" + str(int(so
.so_usecount
)) + "] " 
1580     if (pcb
.inp_state 
== 0 or pcb
.inp_state 
== INPCB_STATE_INUSE
): 
1581         out_string 
+= "inuse, " 
1583         if (pcb
.inp_state 
== INPCB_STATE_DEAD
): 
1584             out_string 
+= "dead, " 
1586             out_string 
+= "unknown (" + str(int(pcb
.inp_state
)) + "), " 
1590 def GetPcbInfo(pcbi
, proto
): 
1593     snd_buf 
= unsigned(0) 
1595     rcv_buf 
= unsigned(0) 
1597     out_string 
+= "lastport " + str(int(pcbi
.ipi_lastport
)) + " lastlow " + str(int(pcbi
.ipi_lastlow
)) + " lasthi " + str(int(pcbi
.ipi_lasthi
)) + "\n" 
1598     out_string 
+= "active pcb count is " + str(int(pcbi
.ipi_count
)) + "\n" 
1599     hashsize 
= pcbi
.ipi_hashmask 
+ 1 
1600     out_string 
+= "hash size is " + str(int(hashsize
)) + "\n" 
1601     out_string 
+= str(pcbi
.ipi_hashbase
) + " has the following inpcb(s):\n" 
1602     if (kern
.ptrsize 
== 8): 
1603         out_string 
+= "pcb            proto  source                     address  port  destination               address  port\n" 
1605         out_string 
+= "pcb            proto  source           address  port  destination         address  port\n\n" 
1608     hashbase 
= pcbi
.ipi_hashbase
 
1609     while (i 
< hashsize
): 
1611         pcb 
= cast(head
.lh_first
, 'inpcb *') 
1614             out_string 
+= GetInPcb(pcb
, proto
) + "\n" 
1617                 snd_cc 
+= so
.so_snd
.sb_cc
 
1618                 mp 
= so
.so_snd
.sb_mb
 
1621                     if (mp
.m_hdr
.mh_flags 
& 0x01): 
1622                         snd_buf 
= mp
.M_dat
.MH
.MH_dat
.MH_ext
.ext_size
 
1623                     mp 
= mp
.m_hdr
.mh_next
 
1624                 rcv_cc 
+= so
.so_rcv
.sb_cc
 
1625                 mp 
= so
.so_rcv
.sb_mb
 
1628                     if (mp
.m_hdr
.mh_flags 
& 0x01): 
1629                         rcv_buf 
+= mp
.M_dat
.MH
.MH_dat
.MH_ext
.ext_size
 
1630                     mp 
= mp
.m_hdr
.mh_next
 
1631             pcb 
= cast(pcb
.inp_hash
.le_next
, 'inpcb *') 
1634     out_string 
+= "total seen " + str(int(pcbseen
)) + " snd_cc " + str(int(snd_cc
)) + " rcv_cc " + str(int(rcv_cc
)) + "\n" 
1635     out_string 
+= "total snd_buf " + str(int(snd_buf
)) + " rcv_buf " + str(int(rcv_buf
)) + "\n" 
1636     out_string  
+= "port hash base is " + hex(pcbi
.ipi_porthashbase
) + "\n" 
1639     hashbase 
= pcbi
.ipi_porthashbase
 
1640     while (i 
< hashsize
): 
1642         pcb 
= cast(head
.lh_first
, 'inpcbport *') 
1645             out_string 
+= GetInPcbPort(pcb
) 
1647             pcb 
= cast(pcb
.phd_hash
.le_next
, 'inpcbport *') 
1652 def GetInPcbPort(ppcb
): 
1654     out_string 
+= hex(ppcb
) + ": lport " 
1655     out_string 
+= Getntohs(ppcb
.phd_port
) 
1661     #p = unsigned(int(port) & 0x0000ffff) 
1662     p 
= ((port 
& 0x0000ff00) >> 8) 
1663     p |
= ((port 
& 0x000000ff) << 8) 
1666 # Macro: show_kern_event_pcbinfo 
1667 def GetKernEventPcbInfo(kev_pcb_head
): 
1669     pcb 
= Cast(kev_pcb_head
.lh_first
, 'kern_event_pcb *') 
1670     if (kern
.ptrsize 
== 8): 
1671         kev_pcb_format_string 
= "0x{0:<16x} {1:12d} {2:16d} {3:16d}" 
1672         out_string 
+= "  evp socket         vendor code      class filter      subclass filter\n" 
1673         out_string 
+= "--------------       -----------      ------------      ---------------\n" 
1675         kev_pcb_format_string 
= "0x{0:<8x} {1:12d} {2:16d} {3:16d}" 
1676         out_string 
+= "evp socket       vendor code      class filter      subclass filter\n" 
1677         out_string 
+= "----------       -----------      ------------      ---------------\n" 
1679         out_string 
+= kev_pcb_format_string
.format(pcb
.evp_socket
, pcb
.evp_vendor_code_filter
, pcb
.evp_class_filter
, pcb
.evp_subclass_filter
) 
1681         pcb 
= pcb
.evp_link
.le_next
 
1684 @lldb_command('show_kern_event_pcbinfo') 
1685 def ShowKernEventPcbInfo(cmd_args
=None): 
1686     """ Display the list of Kernel Event protocol control block information 
1688     print GetKernEventPcbInfo(addressof(kern
.globals.kern_event_head
)) 
1689 # EndMacro:  show_kern_event_pcbinfo 
1691 # Macro: show_kern_control_pcbinfo 
1692 def GetKernControlPcbInfo(ctl_head
): 
1694     kctl 
= Cast(ctl_head
.tqh_first
, 'kctl *') 
1695     if (kern
.ptrsize 
== 8):     
1696         kcb_format_string 
= "0x{0:<16x} {1:4d} {2:10d}\n" 
1698         kcb_format_string 
= "0x{0:<8x} {1:4d} {2:10d}\n" 
1699     while unsigned(kctl
) != 0: 
1700         kctl_name 
= "controller: " + str(kctl
.name
) + "\n" 
1701         out_string 
+= kctl_name
 
1702         kcb 
= Cast(kctl
.kcb_head
.tqh_first
, 'ctl_cb *') 
1703         if unsigned(kcb
) != 0: 
1704             if (kern
.ptrsize 
== 8): 
1705                 out_string 
+= "socket               unit       usecount\n" 
1706                 out_string 
+= "------               ----       --------\n" 
1708                 out_string 
+= "socket       unit       usecount\n" 
1709                 out_string 
+= "------       ----       --------\n" 
1710         while unsigned(kcb
) != 0: 
1711             out_string 
+= kcb_format_string
.format(kcb
.so
, kcb
.unit
, kcb
.usecount
)    
1712             kcb 
= kcb
.next
.tqe_next
 
1714         kctl 
= kctl
.next
.tqe_next
 
1717 @lldb_command('show_kern_control_pcbinfo') 
1718 def ShowKernControlPcbInfo(cmd_args
=None): 
1719     """ Display the list of Kernel Control protocol control block information 
1721     print GetKernControlPcbInfo(addressof(kern
.globals.ctl_head
)) 
1722 # EndMacro:  show_kern_control_pcbinfo 
1724 # Macro: show_tcp_pcbinfo 
1725 @lldb_command('show_tcp_pcbinfo') 
1726 def ShowTcpPcbInfo(cmd_args
=None): 
1727     """ Display the list of TCP protocol control block information 
1729     print GetPcbInfo(addressof(kern
.globals.tcbinfo
), IPPROTO_TCP
) 
1730 # EndMacro:  show_tcp_pcbinfo 
1732 # Macro: show_udp_pcbinfo 
1733 @lldb_command('show_udp_pcbinfo') 
1734 def ShowUdpPcbInfo(cmd_args
=None): 
1735     """ Display the list of UDP protocol control block information 
1737     print GetPcbInfo(addressof(kern
.globals.udbinfo
), IPPROTO_UDP
) 
1738 # EndMacro:  show_udp_pcbinfo 
1740 # Macro: show_tcp_timewaitslots 
1741 @lldb_command('show_tcp_timewaitslots') 
1742 def ShowTcpTimeWaitSlots(cmd_args
=None): 
1743     """ Display the list of the TCP protocol control blocks in TIMEWAIT 
1749     if len(cmd_args
) > 0: 
1750         if (int(cmd_args
[0]) == -1): 
1753             slot 
= int(cmd_args
[0]) 
1755     out_string 
+= "time wait slot size " + str(N_TIME_WAIT_SLOTS
) + " cur_tw_slot " + str(int(kern
.globals.cur_tw_slot
)) + "\n" 
1758     while (i 
< N_TIME_WAIT_SLOTS
): 
1760         head 
= kern
.globals.time_wait_slots
[i
] 
1761         if (i 
== slot 
or slot 
== -1): 
1762             pcb0 
= cast(head
.lh_first
, 'inpcb *') 
1765                 pcb0 
= pcb0
.inp_list
.le_next
 
1767             out_string 
+= "  slot " + str(i
) + " count " + str(perslot
) + "\n" 
1769         if (_all 
or i 
== slot
): 
1770             pcb0 
= cast(head
.lh_first
, 'inpcb *') 
1773                 out_string 
+= GetInPcb(pcb0
, IPPROTO_TCP
) 
1775                 pcb0 
= pcb0
.inp_list
.le_next
 
1779 # EndMacro: show_tcp_timewaitslots 
1781 # Macro: show_domains 
1782 @lldb_command('show_domains') 
1783 def ShowDomains(cmd_args
=None): 
1784     """ Display the list of the domains 
1787     domains 
= kern
.globals.domains
 
1788     dp 
= Cast(domains
.tqh_first
, 'domain *') 
1789     ifma_trash_format_string 
= "{0:4d}: {1:x} {2:3d} {3:6d} {4:6d}" 
1792         out_string 
+= "\"" + str(dp
.dom_name
) + "\"" + "[" + str(int(dp
.dom_refs
)) + " refs] domain " + hex(dp
) + "\n" 
1793         out_string 
+= "    family:\t" + str(int(dp
.dom_family
)) + "\n" 
1794         out_string 
+= "    flags:0x\t" + str(int(dp
.dom_flags
)) + "\n" 
1795         out_string 
+= "    rtparams:\toff=" + str(int(dp
.dom_rtoffset
)) + ", maxrtkey=" + str(int(dp
.dom_maxrtkey
)) + "\n" 
1798             out_string 
+= "    init:\t" 
1799             out_string 
+= GetSourceInformationForAddress(dp
.dom_init
) + "\n" 
1800         if (dp
.dom_externalize
): 
1801             out_string 
+= "    externalize:\t" 
1802             out_string 
+= GetSourceInformationForAddress(dp
.dom_externalize
) + "\n" 
1803         if (dp
.dom_dispose
): 
1804             out_string 
+= "    dispose:\t" 
1805             out_string 
+= GetSourceInformationForAddress(dp
.dom_dispose
) + "\n" 
1806         if (dp
.dom_rtattach
): 
1807             out_string 
+= "    rtattach:\t" 
1808             out_string 
+= GetSourceInformationForAddress(dp
.dom_rtattach
) + "\n" 
1810             out_string 
+= "    old:\t" 
1811             out_string 
+= GetSourceInformationForAddress(dp
.dom_old
) + "\n" 
1813         pr 
= Cast(dp
.dom_protosw
.tqh_first
, 'protosw *') 
1816             out_string 
+= "\ttype " + str(int(pr
.pr_type
)) + ", protocol " + str(int(pr
.pr_protocol
)) + ", protosw " + hex(pr
) + "\n" 
1817             out_string 
+= "\t    flags:0x\t" + hex(pr
.pr_flags
) + "\n" 
1819                 out_string 
+= "\t    input:\t" 
1820                 out_string 
+= GetSourceInformationForAddress(pr
.pr_input
) + "\n" 
1822                 out_string 
+= "\t    output:\t" 
1823                 out_string 
+= GetSourceInformationForAddress(pr
.pr_output
) + "\n" 
1824             if (pr
.pr_ctlinput
): 
1825                 out_string 
+= "\t    ctlinput:\t" 
1826                 out_string 
+= GetSourceInformationForAddress(pr
.pr_ctlinput
) + "\n" 
1827             if (pr
.pr_ctloutput
): 
1828                 out_string 
+= "\t    ctloutput:\t" 
1829                 out_string 
+= GetSourceInformationForAddress(pr
.pr_ctloutput
) + "\n" 
1831                 out_string 
+= "\t    init:\t" 
1832                 out_string 
+= GetSourceInformationForAddress(pr
.pr_init
) + "\n" 
1834                 out_string 
+= "\t    drain:\t" 
1835                 out_string 
+= GetSourceInformationForAddress(pr
.pr_drain
) + "\n" 
1837                 out_string 
+= "\t    sysctl:\t" 
1838                 out_string 
+= GetSourceInformationForAddress(pr
.pr_sysctl
) + "\n" 
1840                 out_string 
+= "\t    lock:\t" 
1841                 out_string 
+= GetSourceInformationForAddress(pr
.pr_lock
) + "\n" 
1843                 out_string 
+= "\t    unlock:\t" 
1844                 out_string 
+= GetSourceInformationForAddress(pr
.pr_unlock
) + "\n" 
1846                 out_string 
+= "\t    getlock:\t" 
1847                 out_string 
+= GetSourceInformationForAddress(pr
.pr_getlock
) + "\n" 
1849                 out_string 
+= "\t    old:\t" 
1850                 out_string 
+= GetSourceInformationForAddress(pr
.pr_old
) + "\n" 
1852             out_string 
+= "\t    pru_flags:0x\t" + hex(pru
.pru_flags
) + "\n" 
1853             out_string 
+= "\t    abort:\t" 
1854             out_string 
+= GetSourceInformationForAddress(pru
.pru_abort
) + "\n" 
1855             out_string 
+= "\t    accept:\t" 
1856             out_string 
+= GetSourceInformationForAddress(pru
.pru_accept
) + "\n" 
1857             out_string 
+= "\t    attach:\t" 
1858             out_string 
+= GetSourceInformationForAddress(pru
.pru_attach
) + "\n" 
1859             out_string 
+= "\t    bind:\t" 
1860             out_string 
+= GetSourceInformationForAddress(pru
.pru_bind
) + "\n" 
1861             out_string 
+= "\t    connect:\t" 
1862             out_string 
+= GetSourceInformationForAddress(pru
.pru_connect
) + "\n" 
1863             out_string 
+= "\t    connect2:\t" 
1864             out_string 
+= GetSourceInformationForAddress(pru
.pru_connect2
) + "\n" 
1865             out_string 
+= "\t    connectx:\t" 
1866             out_string 
+= GetSourceInformationForAddress(pru
.pru_connectx
) + "\n" 
1867             out_string 
+= "\t    control:\t" 
1868             out_string 
+= GetSourceInformationForAddress(pru
.pru_control
) + "\n" 
1869             out_string 
+= "\t    detach:\t" 
1870             out_string 
+= GetSourceInformationForAddress(pru
.pru_detach
) + "\n" 
1871             out_string 
+= "\t    disconnect:\t" 
1872             out_string 
+= GetSourceInformationForAddress(pru
.pru_disconnect
) + "\n" 
1873             out_string 
+= "\t    listen:\t" 
1874             out_string 
+= GetSourceInformationForAddress(pru
.pru_listen
) + "\n" 
1875             out_string 
+= "\t    peeloff:\t" 
1876             out_string 
+= GetSourceInformationForAddress(pru
.pru_peeloff
) + "\n" 
1877             out_string 
+= "\t    peeraddr:\t" 
1878             out_string 
+= GetSourceInformationForAddress(pru
.pru_peeraddr
) + "\n" 
1879             out_string 
+= "\t    rcvd:\t" 
1880             out_string 
+= GetSourceInformationForAddress(pru
.pru_rcvd
) + "\n" 
1881             out_string 
+= "\t    rcvoob:\t" 
1882             out_string 
+= GetSourceInformationForAddress(pru
.pru_rcvoob
) + "\n" 
1883             out_string 
+= "\t    send:\t" 
1884             out_string 
+= GetSourceInformationForAddress(pru
.pru_send
) + "\n" 
1885             out_string 
+= "\t    sense:\t" 
1886             out_string 
+= GetSourceInformationForAddress(pru
.pru_sense
) + "\n" 
1887             out_string 
+= "\t    shutdown:\t" 
1888             out_string 
+= GetSourceInformationForAddress(pru
.pru_shutdown
) + "\n" 
1889             out_string 
+= "\t    sockaddr:\t" 
1890             out_string 
+= GetSourceInformationForAddress(pru
.pru_sockaddr
) + "\n" 
1891             out_string 
+= "\t    sopoll:\t" 
1892             out_string 
+= GetSourceInformationForAddress(pru
.pru_sopoll
) + "\n" 
1893             out_string 
+= "\t    soreceive:\t" 
1894             out_string 
+= GetSourceInformationForAddress(pru
.pru_soreceive
) + "\n" 
1895             out_string 
+= "\t    sosend:\t" 
1896             out_string 
+= GetSourceInformationForAddress(pru
.pru_sosend
) + "\n" 
1897             pr 
= pr
.pr_entry
.tqe_next
 
1898         dp 
= dp
.dom_entry
.tqe_next
 
1901 # EndMacro: show_domains