Perl getnetbyaddr Function

Advertisements


Description

This function returns the information for the network specified by ADDR and type ADDRTYPE in a list context: ($name, $aliases, $addrtype, $net)

Syntax

Following is the simple syntax for this function:

getnetbyaddr ADDR, ADDRTYPE

Return Value

This function returns undef on error otherwise Network address in scalar context and empty list on error otherwise Network record (name, aliases, address type, network address) in list context.

Example

Following is the example code showing its basic usage:

#!/usr/bin/perl

use Socket;

$iaddr = inet_aton("127.1"); # or whatever address
($name, $aliases, $addrtype, $net)  = getnetbyaddr($iaddr, AF_INET);

print "Name = $name\n";
print "Aliases = $aliases\n";
print "Addrtype = $addrtype\n";
print "Net = $net\n";

When above code is executed, it produced following result

Name = default
Aliases = 
Addrtype = 2
Net = 0


Advertisements
Advertisements