gopsutil icon indicating copy to clipboard operation
gopsutil copied to clipboard

replace lsof to platform dependent method

Open shirou opened this issue 9 years ago • 6 comments

#142 , #143 are related to using lsof to get Network connection info.

To replace lsof, we needs at least these functions. inet_ntop porting, sysctl decode functions, and so on are little bit heavy to implement. I will update this issue step by step.

  • [x] Linux (see #169)
    • [x] getting inode list from processes
    • [x] porting socket.inet_ntop to pure golang (linux struct)
    • [x] IPv6
    • [x] Unix Pipe
  • [x] windows
    • [x] needs research
    • [x] rtlIpv4AddressToStringA
    • [x] rtlIpv6AddressToStringA
    • [x] getExtendedTcpTable
  • [ ] darwin
    • [ ] proc_pidinfo and retrieve proc_fdtype
    • [ ] inet_ntop
  • [ ] freebsd
    • [ ] sysctl net.inet.tcp.pcblist for TCP
    • [ ] sysctl net.inet.udp.pcblist for UDP
    • [ ] sysctl net.local.stream.pcblist for socket stream
    • [ ] sysctl net.local.dgram.pcblist for socket dgram
    • [ ] porting inet_ntop to pure golang (freebsd struct)
    • [ ] porting kinfo_file

shirou avatar Feb 25 '16 12:02 shirou

:+1: great to see that you are taking this on!

vrecan avatar Feb 25 '16 18:02 vrecan

looking forward to this, thanks for your work @shirou!

sparrc avatar Feb 26 '16 11:02 sparrc

OK. now I have implemented linux version at #169. The output is same as psutil, but more tests are required.

shirou avatar Mar 05 '16 15:03 shirou

FreeBSD

sysctl net.inet.tcp.pcblist returnes xtcpcb struct. But since it is complicated to parse to golang struct, time should be required.

Darwin

To get NetConnections, proc_pidinfo() is required and it seems to invoke by only CGO. I am thinking net is also use CGO or not. Or, the net.inet.tcp.pcblist is exists on Darwin also, the FreeBSD code may be used on Darwin, too. I will challenge after FreeBSD.

windows

not yet...

v2 migration

It takes a time to implement, I think prioritize v2.

shirou avatar Mar 23 '16 02:03 shirou

Is this dead in the water? I'm seeing flakiness with using lsof where the command never finishes.

NullSoldier avatar Aug 04 '17 02:08 NullSoldier

@NullSoldier what platform do you want to replace lsof?

shirou avatar Aug 07 '17 12:08 shirou