#!/usr/bin/perl

use Packet::Definitions;

# here we create the 'if_msghdr' struct
# found in /usr/include/net/if.h
#
# it contains a nested struct which also
# contains a nested struct in itself

my $defs = 
{
  ifm_msglen	=> 1,
  ifm_version	=> 2,
  ifm_type	=> 3,
  ifm_addrs	=> 4,
  ifm_flags	=> 5,
  ifm_index	=> 6,
  ifm_data	=>
  {
    ifi_type		=> 1,
    ifi_physical	=> 2,
    ifi_addrlen		=> 3,
    ifi_hdrlen		=> 4,
    ifi_recvquota	=> 5,
    # there are many others, we'll let them fill in automagically with nulls
    ifi_lastchange	=>
    {
      tv_sec	=> 1,
      tv_usec	=> 2,
    }
  }
};

my $if_msghdr = &Packet::Definitions::if_msghdr    ($defs);
my $hashref   = &Packet::Definitions::unp_if_msghdr($if_msghdr);

&recurse($hashref);

sub recurse {
  my %y = %{$_[0]};
  my $sp = $_[1];

  foreach (keys(%y)) {
    if (ref($y{$_}) eq "HASH") {
      print " " x $sp;
      print "$_\t-> {\n";
      &recurse($y{$_}, $sp+2);
      print " " x $sp;
      print "}\n";
    }
    else {
      print " " x $sp;
      print "$_\t-> $y{$_}\n";
    }
  }
}
