Sys::Hostname::FQDN - Get the short or long hostname


Sys-Hostname-FQDN documentation Contained in the Sys-Hostname-FQDN distribution.

Index


Code Index:

NAME

Top

  Sys::Hostname::FQDN - Get the short or long hostname

SYNOPSIS

Top

  use Sys::Hostname::FQDN qw(
	asciihostinfo
	gethostinfo
	inet_ntoa
	inet_aton
	fqdn
	short
  );

  $host = short();
  $fqdn = fqdn();
  ($name,$aliases,$addrtype,$length,@addrs)=gethostinfo();
  ($name,$aliases,$addrtype,$length,@addrs)=asciihostinfo();
  $dotquad = inet_ntoa($netaddr);
  $netaddr = inet_aton($dotquad);

INSTALLATION

Top

To install this module type the following:

  perl Makefile.PL
  make
  make test
  make install

Solaris users, see the 'hints' subdirectory if you have problems with the build.

DESCRIPTION

Top

Sys::Hostname::FQDN uses the host 'C' library to discover the (usually) short host name, then uses (perl) gethostbyname to extract the real hostname.

The results from gethostbyname are exported as gethostinfo and asciihostinfo as a convenience since they are available. Similarly, the 'C' library functions inet_ntoa and inet_aton are exported.

$host = short();
  returns the host part of this host's FQDN.

$fqdn = fqdn();
  returns the fully qualified host name of this host.

($name,$aliases,$addrtype,$length,@addrs)=gethostinfo();
  returns:
    $name	fully qualifed host name of this host.
    $aliases	alternate names for this host.
    $addrtype	The type of address; always AF_INET at present.
    $length	The length of the address in bytes.
    @addrs	array of network addresses for this host 
		in network byte order.

($name,$aliases,$addrtype,$length,@addrs)=asciihostinfo();
  returns:
    $name	fully qualifed host name of this host.
    $aliases	alternate names for this host.
    $addrtype	The type of address; always AF_INET at present.
    $length	The length of the address in bytes.
    @addrs	array of dot quad IP addresses for this host.

$dotquad = inet_ntoa($netaddr);
  input:	packed network address in network byte order.
  returns:	dot quad IP address.

$netaddr = inet_aton($dotquad);
  input:	dot quad IP address.
  returns:	packed network address in network byte order.

DEPENDENCIES

Top

  none

EXPORT

Top

  None by default

EXPORT_OK

Top

  asciihostinfo
  gethostinfo
  inet_ntoa
  inet_aton
  fqdn
  short

ACKNOWLEDGEMENTS

Top

The workaround for systems that do not have 'inet_aton' is taken directly from Socket.xs in the Perl 5 kit for perl-5.8.0 by Larry Wall, copyright 1989-2002. Thank you Larry for making PERL possible for all of us.

AUTHOR

Top

Michael Robinton <michael@bizsystems.com>

COPYRIGHT AND LICENCE

Top


Sys-Hostname-FQDN documentation Contained in the Sys-Hostname-FQDN distribution.
package Sys::Hostname::FQDN;

#use 5.006;
use strict;
#use warnings;
use Carp;

use vars qw($VERSION @ISA @EXPORT_OK);

$VERSION = do { my @r = (q$Revision: 0.11 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r };

require Exporter;
require DynaLoader;
#use AutoLoader;

@ISA = qw(Exporter DynaLoader);

@EXPORT_OK = qw (
	asciihostinfo
	gethostinfo
	inet_ntoa
	inet_aton
	fqdn
	short
);

bootstrap Sys::Hostname::FQDN $VERSION;

# Preloaded methods go here.

sub DESTROY {};

# Autoload methods go after =cut, and are processed by the autosplit program.

sub short {
  return (split(/\./,&usually_short))[0];
}

sub fqdn {
  return (gethostbyname(&usually_short))[0];
}

sub gethostinfo {
  return gethostbyname(&usually_short);
}

sub asciihostinfo {
  my ($name,$aliases,$addrtype,$length,@addrs) = gethostbyname(&usually_short);
  for(0..$#addrs) {
    $addrs[$_] = inet_ntoa($addrs[$_]);
  }
  return ($name,$aliases,$addrtype,$length,@addrs);
}

1;
__END__