Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
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
Replies are listed 'Best First'.
(jeffa) Re: inet_aton
by jeffa (Bishop) 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 wandering the Monastery: (17)
As of 2015-07-29 16:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (265 votes), past polls