in reply to Re: parsing a terrible /etc/hosts
in thread parsing a terrible /etc/hosts
Not every ip in the hosts file HAS to be 127.0.0.1.
And not every ip in the hosts file has to be an IPv4 address. It has become quite common to see something like "::1 this-machine.lan this-machine" in /etc/hosts - IPv6.
Parsing any hosts file is easy: Read line by line, strip comments (s/#.*//), remove trailing and leading whitespace (s/^\s+//; s/\s+$//;), skip empty lines (length or next), split at whitespace (@tmp=split /\s+/). Splitting must return at least two elements. First element must match an IPv4 or IPv6 address (see Regexp::Common::net), all other elements must be valid host names (again, see Regexp::Common::net).
Alexander
|
|---|