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


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: == 0x0100007f, but how to you get that from inet_aton and not the return value?

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(""),A +F_INET)'
    I hope that answers your question.


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?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://87190]
Approved by root
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (2)
As of 2017-11-18 03:05 GMT
Find Nodes?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:

    Results (277 votes). Check out past polls.