Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much


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 the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (12)
As of 2016-10-26 17:26 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (344 votes). Check out past polls.