in reply to unsigned int in the host format and raw socket
sub parse_ipv4 { local *_ = \(@_ ? $_[0] : $_); return unpack('N', pack('C4', split(/\./))); }
Update: What follows is an alternative implementation that accepts domain names ("www.perlmonks.org") as well as IP addresses:
use Socket (); sub parse_ipv4 { local *_ = \(@_ ? $_[0] : $_); my $packed = Socket::inet_aton($_); return unless defined $packed; return unpack('N', $packed); }
print(parse_ipv4('202.227.44.16'), "\n"); # 3403885584
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: unsigned int in the host format and raw socket
by doctor_moron (Scribe) on Jun 30, 2005 at 18:32 UTC | |
by ikegami (Patriarch) on Jun 30, 2005 at 18:47 UTC | |
by doctor_moron (Scribe) on Jun 30, 2005 at 19:07 UTC |