Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

inet_aton

by Anonymous Monk
on Jun 09, 2001 at 19:15 UTC ( #87190=perlquestion: print w/ replies, xml ) Need Help??
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

127.0.0.1 == 0x0100007f, but how to you get that from inet_aton and not the return value?

Comment on inet_aton
(jeffa) Re: inet_aton
by jeffa (Chancellor) on Jun 09, 2001 at 19:29 UTC
    inet_aton() takes a dotted quad and can return the host name using gethostbyaddr(). If you want a dotted quad returned, then use gethostbyname() and inet_ntoa:
    use strict; use Socket; my $p = gethostbyname('localhost'); my $ip = inet_ntoa($p); print "$ip\n";
    Here is a sample use of inet_aton():
    perl -MSocket -le 'print scalar gethostbyaddr(inet_aton("127.0.0.1"),A +F_INET)'
    I hope that answers your question.

    Jeff

    R-R-R--R-R-R--R-R-R--R-R-R--R-R-R--
    L-L--L-L--L-L--L-L--L-L--L-L--L-L--
    
Re: inet_aton
by joe++ (Friar) on Nov 25, 2002 at 12:49 UTC
    Some 14 months go by and I do a Super Search...

    How about this?

    # converts decimal dotted quad string to network ordered long sub dottedquad2long { return unpack('N', inet_aton(shift)); # or # return unpack 'N', pack 'C4', split /\./, shift; # or # my @seg = split(/\./, shift); # return $seg[0]*256**3+$seg[1]*256**2+$seg[2]*256+$seg[3]; }
    Shamelessly stolen from IP Manipulation: An Exercise

    --
    Cheers, Joe

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://87190]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (12)
As of 2014-09-16 13:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (24 votes), past polls