Subject: | Parse Error on Mac (freebsd) |
I received the following error when trying Parse::Netstat on my Mac which is based on the freebsd stack.
parse-netstat: ERROR 400: Can't parse tcp line ...
There were three patterns that failed:
1 - tcp4 0 0 *.* *.* CLOSED
2 - tcp46 0 0 *.80 *.* LISTEN
3 - udp46 0 0 *.* *.*
I modified the code per the diff below and it now handles these scenarios.
65,66c65,68
< $line =~ m!^(?P<proto>tcp[46]?) \s+ (?P<recvq>\d+) \s+ (?P<sendq>\d+)\s+
< (?P<local_host>\S+?)[:.](?P<local_port>\w+)\s+
---
Show quoted text
> #tcp4 0 0 *:* *:* CLOSED
> #tcp46 0 0 192.168.1.33.632 192.168.1.10.2049 CLOSED
> $line =~ m!^(?P<proto>tcp[46]|tcp46?) \s+ (?P<recvq>\d+) \s+ (?P<sendq>\d+)\s+
> (?P<local_host>\S+?)[:.](?P<local_port>\w+|\*)\s+
77c79,80
< $line =~ m!^(?P<proto>udp[46]?) \s+ (?P<recvq>\d+) \s+ (?P<sendq>\d+) \s+
---
Show quoted text> #udp46 0 0 *.879 *.*
> $line =~ m!^(?P<proto>udp[46]|udp46?) \s+ (?P<recvq>\d+) \s+ (?P<sendq>\d+) \s+
Please let me know if you have any questions or want me to test anything else.
Cheers,
LBE