View on
MetaCPAN is shutting down
For details read Perl NOC. After June 25th this page will redirect to
Ray Mroz > LinkLocal-IPv4-Interface-0.19_01 > LinkLocal::IPv4::Interface::Cache



Annotate this POD

Module Version: 0.19_01   Source  


LinkLocal::IPv4::Interface::Cache - IPv4 link-local address caching object.


  use LinkLocal::IPv4::Interface::Cache;

  # Create a cache file object
  my $cache = LinkLocal::IPv4::Interface::Cache->new();
  # Get the last IP cached for a given interface
  my $last_address = $cache->get_last_ip('eth0');
  # Update the cache when an interface has successfully
  # configured a link-local address
  $cache->cache_this_ip( 'eth0', '' );


Implementations of the IPv4 link-local protocol stack will always cache the most recent successfully configured IPv4 link-local addresses in cases where the host has some form of persistant storage. In doing so, the next time that implementation begins the address selection process it will read from its address cache first and attempt to use the last successfully configured address it had previously used on that interface. This has two benefits; the first is that address collision and conflict are less likely during the address selection phase and second is that host interfaces will try and first use link-local addresses which have been successfully configured on them in the past which provides a degree of continuity and address stability in the otherwise unmanaged environment.

This caching object wraps an IO::File, the path to which is determined by the OS on which it is run. At present Linux, Solaris, OS X, Windows and the BSD derivatives are supported. Each cache maintains an IPv4 link-local address for each interface which has been successfully configured with one in the past.


Public Attributes


Private Attributes


The private _cache attribute is an IO::File object which represents the IPv4 link-local address cache for the current implementation. According to the specification, all past successfully configured link-local addresses are cached on an interface by interface basis.




This constructor takes no arguments and returns an instance of a link-local address cache file object which contains all of the most recent successfully configured link-local addresses, by interface, on the system.

Public Methods


get_last_ip() is a public method which takes one argument, a network interface device name (such as 'eth0' for example) and it returns the last successfully configured IPv4 link-local address which was configured on that interface or undef if this interface has never been dynamically configured with a link-local address. MooseX::Params::Validate is in effect on all arguments.


cache_this_ip() is a public method which takes two arguments, a network interface device name (such as 'eth0' for example) and the link-local IPv4 address in dotted-decimal format which is to be cached for that interface as the currently configured IPv4 link-local address but only after it has been successfully probed and configured as per RFC-3927. MooseX::Params::Validate is in effect on all arguments.

Private Methods


_get_hash_from_cache() is a private method which builds a hash from the current link-local cache file containing the most recent successfully configured IPv4 link-local addresses. The hash is structured in an interface => address key/value format. For example:

  eth0 =>
  eth1 =>

This builder method handles the proper initialization of the private _cache attribute, which is iself an IO::File object. It detects the OS on which the implementation is being run and from that, configures the application cache to use the proper location for its environment according to current system type.


_slurp_file() is a method delegate on the getlines() method of an IO::Handle object via IO::File. When called, _slurp_file() returns a list containing the contents of the cache file


_record_ip() is a method delegate on the printf() method of an IO::Handle object via IO::File. This delegate is used to update the cache with the new interface/address mapping.


_refresh_cache() is a method delegate on the seek() method of an IO::Seekable object via IO::File. The _refresh_cache() delegate is used to reset the file pointer so that the stream is at the beginning of the file. This ensures that the next read from the file will have its stream set to the start of the file.


Refer to RFC-3927, Dynamic Configuration of IPv4 Link-Local Adresses, the complete text of which can be found in the top level of the package archive.

perl, LinkLocal::IPv4::Interface, MooseX::Params::Validate, IO::File, Try::Tiny, Moose

This project is also hosted on github at:


What's a bug???


Tony Li Xu, <>


Copyright (C) 2010 Ray Mroz, Tony Li Xu

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <>.

syntax highlighting: