#!/usr/bin/perl -w
#print STDERR @ARGV, "\n";
$iface=$ARGV[$#ARGV];
if ($iface ne "-XYZZY") {
    $prefix="/var/lib/dhcpcd/dhcpcd-";
    @files=( $prefix . $iface . ".cache",
	     $prefix . $iface . ".info");
    open(IFCONFIG, "/sbin/ifconfig $iface|") or die "ifconfig $iface";
    undef $/;			# enable "slurp" mode
    $_ = <IFCONFIG>;		# whole file now here
    close(IFCONFIG);
    m/HWaddr\s+([^\s]+)/s;
    $hwaddr=$1;

    # Now rename the files and create links
    unlink @files;
    foreach $file (@files) {
	$hwfile = $file . "." . $hwaddr;
	# I don't know whether touching the files is necessary; just in case...
	if ( ! -e $hwfile) {
	    open(TOUCH, ">$hwfile");
	    close(TOUCH);
	}
	symlink($hwfile, $file);
    }
}
exec "/sbin/dhcpcd", @ARGV or die "exec /sbin/dhcpcd";
