#!/usr/bin/perl -w # Parses the bpf.h header file to generate the dlt_names.h header # which maps the DLT types to the DLT string name # run as: # cat /usr/include/net/bpf.h | ./scripts/dlt2name.pl use strict; my $outfile = "dlt_names.h"; # open outfile open(OUT, ">$outfile") or die("Unable to open $outfile for writing: $!"); # read STDIN # some DLT types aren't in a format we can parse easily or just doesn't # exist in my /usr/include/net/bpf.h file so we list them here my %known = (107 => 'BSD/OS Frame Relay', 108 => 'OpenBSD Loopback', 113 => 'Linux Cooked Sockets', 114 => 'Apple LocalTalk', 115 => 'Acorn Econet', 116 => 'OpenBSD IPFilter', 117 => 'OpenBSD PF Log/SuSE 6.3 LANE 802.3', 118 => 'Cisco IOS', 119 => '802.11 Prism Header', 120 => '802.11 Aironet Header', 121 => 'Siemens HiPath HDLC', 122 => 'IP over Fibre Channel' ); my @names = ( ); # put our known DLT types in names since the format of bpf.h is # inconsistent foreach my $dlt (keys %known) { $names[$dlt] = { name => $known{$dlt} }; } while (my $line = ) { if ($line =~ /^\#define\s+(DLT_[a-zA-Z0-9_]+)\s+(\d+)/) { my $key = $1; my $dlt = $2; my $name = $names[$dlt]->{name} ? $names[$dlt]->{name} : ""; if ($line =~ /\/\*\s+(.*)\s+\*\//) { $name = $1; } $names[$dlt] = { key => $key, name => $name }; } } # prep the header print OUT (<{name}\",\n"; } } print OUT "\t\tNULL\n};\n"; print OUT "\#define DLT2DESC_LEN $#names\n"; close OUT; exit 0;