(self, file, family, type_, inodes, filter_pid=None)
Parse /proc/net/tcp* and /proc/net/udp* files.
Parse /proc/net/tcp* and /proc/net/udp* files.
Parse / proc / net / tcp * and / proc / net / udp * files .
def process_inet(self, file, family, type_, inodes, filter_pid=None):
        """Parse /proc/net/tcp* and /proc/net/udp* files."""
        if file.endswith('6') and not os.path.exists(file):
            # IPv6 not supported
            return
        with open_text(file) as f:
            f.readline()  # skip the first line
            for line in f:
                try:
                    _, laddr, raddr, status, _, _, _, _, _, inode = \
                        line.split()[:10]
                except ValueError:
                    raise RuntimeError(
                        "error while parsing %s; malformed line %r" % (
                            file, line))
                if inode in inodes:
                    # # We assume inet sockets are unique, so we error
                    # # out if there are multiple references to the
                    # # same inode. We won't do this for UNIX sockets.
                    # if len(inodes[inode]) > 1 and family != socket.AF_UNIX:
                    #     raise ValueError("ambiguos inode with multiple "
                    #                      "PIDs references")
                    pid, fd = inodes[inode][0]
                else:
                    pid, fd = None, -1
                if filter_pid is not None and filter_pid != pid:
                    continue
                else:
                    if type_ == socket.SOCK_STREAM:
                        status = TCP_STATUSES[status]
                    else:
                        status = _common.CONN_NONE
                    laddr = self.decode_address(laddr, family)
                    raddr = self.decode_address(raddr, family)
                    yield (fd, family, type_, laddr, raddr, status, pid)
def process_inet ( self , file , family , type_ , inodes , filter_pid = None ) : if file . endswith ( '6' ) and not os . path . exists ( file ) : # IPv6 not supported return with open_text ( file ) as f : f . readline ( ) # skip the first line for line in f : try : _ , laddr , raddr , status , _ , _ , _ , _ , _ , inode = line . split ( ) [ : 10 ] except ValueError : raise RuntimeError ( "error while parsing %s; malformed line %r" % ( file , line ) ) if inode in inodes : # # We assume inet sockets are unique, so we error # # out if there are multiple references to the # # same inode. We won't do this for UNIX sockets. # if len(inodes[inode]) > 1 and family != socket.AF_UNIX: #     raise ValueError("ambiguos inode with multiple " #                      "PIDs references") pid , fd = inodes [ inode ] [ 0 ] else : pid , fd = None , - 1 if filter_pid is not None and filter_pid != pid : continue else : if type_ == socket . SOCK_STREAM : status = TCP_STATUSES [ status ] else : status = _common . CONN_NONE laddr = self . decode_address ( laddr , family ) raddr = self . decode_address ( raddr , family ) yield ( fd , family , type_ , laddr , raddr , status , pid )