#!/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 from the tcpreplay source base directory as: # cat /usr/include/pcap-bpf.h | ./scripts/dlt2name.pl use strict; my $out_c = 'src/common/dlt_names.c'; my $out_h = 'src/common/dlt_names.h'; # open outfile open(OUT_C, ">$out_c") or die("Unable to open $out_c for writing: $!"); open(OUT_H, ">$out_h") or die("Unable to open $out_h 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; $names[$dlt]{name} = $name; } } # print the license info while (my $line = ) { print OUT_C $line; print OUT_H $line; } # prep the header print OUT_C < /* DLT to descriptions */ char *dlt2desc[] = { HEADER for (my $i = 0; $i < $#names; $i ++) { if (! defined $names[$i]) { print OUT_C "\t\t\"Unknown\",\n"; } else { print OUT_C "\t\t\"$names[$i]->{name}\",\n"; } } print OUT_C <