@@ -1534,15 +1534,17 @@ function networkConnections(callback) {
1534
1534
} ) ;
1535
1535
}
1536
1536
if ( _darwin ) {
1537
- // let cmd = 'netstat -natv | grep "ESTABLISHED\\|SYN_SENT\\|SYN_RECV\\|FIN_WAIT1\\|FIN_WAIT2\\|TIME_WAIT\\|CLOSE\\|CLOSE_WAIT\\|LAST_ACK\\|LISTEN\\|CLOSING\\|UNKNOWN"';
1538
- let cmd = 'netstat -natvln | grep "tcp4\\|tcp6\\|udp4\\|udp6"' ;
1537
+ let cmd = 'netstat -natvln | grep "tcp4\\|tcp6\\|udp4\\|udp6\\|Recv-Q"' ;
1539
1538
const states = 'ESTABLISHED|SYN_SENT|SYN_RECV|FIN_WAIT1|FIN_WAIT_1|FIN_WAIT2|FIN_WAIT_2|TIME_WAIT|CLOSE|CLOSE_WAIT|LAST_ACK|LISTEN|CLOSING|UNKNOWN' ;
1540
1539
exec ( cmd , { maxBuffer : 1024 * 20000 } , function ( error , stdout ) {
1541
1540
if ( ! error ) {
1542
1541
exec ( 'ps -axo pid,command' , { maxBuffer : 1024 * 20000 } , function ( err2 , stdout2 ) {
1543
1542
let processes = stdout2 . toString ( ) . split ( '\n' ) ;
1544
1543
processes = processes . map ( ( line => { return line . trim ( ) . replace ( / + / g, ' ' ) ; } ) ) ;
1545
1544
let lines = stdout . toString ( ) . split ( '\n' ) ;
1545
+ const header = lines [ 0 ] ;
1546
+ const hasTransferred = header . indexOf ( 'rxbytes' ) > - 1 ;
1547
+ lines . shift ( ) ;
1546
1548
1547
1549
lines . forEach ( function ( line ) {
1548
1550
line = line . replace ( / + / g, ' ' ) . split ( ' ' ) ;
@@ -1565,7 +1567,7 @@ function networkConnections(callback) {
1565
1567
}
1566
1568
const hasState = states . indexOf ( line [ 5 ] ) >= 0 ;
1567
1569
let connstate = hasState ? line [ 5 ] : 'UNKNOWN' ;
1568
- let pid = parseInt ( line [ 8 + ( hasState ? 0 : - 1 ) ] , 10 ) ;
1570
+ let pid = parseInt ( line [ 8 + ( hasState ? 0 : - 1 ) + ( hasTransferred ? 2 : 0 ) ] , 10 ) ;
1569
1571
if ( connstate ) {
1570
1572
result . push ( {
1571
1573
protocol : line [ 0 ] ,
0 commit comments