38122021242747404f7f3e02ff4428a7cb884b77Evan Hunt#!/usr/bin/perl
38122021242747404f7f3e02ff4428a7cb884b77Evan Hunt#
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews# Copyright (C) 2015, 2016 Internet Systems Consortium, Inc. ("ISC")
38122021242747404f7f3e02ff4428a7cb884b77Evan Hunt#
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews# This Source Code Form is subject to the terms of the Mozilla Public
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews# License, v. 2.0. If a copy of the MPL was not distributed with this
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews# file, You can obtain one at http://mozilla.org/MPL/2.0/.
38122021242747404f7f3e02ff4428a7cb884b77Evan Hunt
38122021242747404f7f3e02ff4428a7cb884b77Evan Hunt# Converts hex ascii into raw data.
38122021242747404f7f3e02ff4428a7cb884b77Evan Hunt# (This can be used, for example, to construct input for "wire_data -d".)
38122021242747404f7f3e02ff4428a7cb884b77Evan Hunt
38122021242747404f7f3e02ff4428a7cb884b77Evan Huntrequire 5.006.001;
38122021242747404f7f3e02ff4428a7cb884b77Evan Hunt
38122021242747404f7f3e02ff4428a7cb884b77Evan Huntuse strict;
38122021242747404f7f3e02ff4428a7cb884b77Evan Huntuse IO::File;
38122021242747404f7f3e02ff4428a7cb884b77Evan Hunt
38122021242747404f7f3e02ff4428a7cb884b77Evan Huntsub usage {
38122021242747404f7f3e02ff4428a7cb884b77Evan Hunt print ("Usage: packet.pl [file]\n");
38122021242747404f7f3e02ff4428a7cb884b77Evan Hunt exit 1;
38122021242747404f7f3e02ff4428a7cb884b77Evan Hunt}
38122021242747404f7f3e02ff4428a7cb884b77Evan Hunt
38122021242747404f7f3e02ff4428a7cb884b77Evan Huntmy $file = "STDIN";
38122021242747404f7f3e02ff4428a7cb884b77Evan Huntif (@ARGV >= 1) {
38122021242747404f7f3e02ff4428a7cb884b77Evan Hunt my $filename = shift @ARGV;
38122021242747404f7f3e02ff4428a7cb884b77Evan Hunt open FH, "<$filename" or die "$filename: $!";
38122021242747404f7f3e02ff4428a7cb884b77Evan Hunt $file = "FH";
38122021242747404f7f3e02ff4428a7cb884b77Evan Hunt}
38122021242747404f7f3e02ff4428a7cb884b77Evan Hunt
38122021242747404f7f3e02ff4428a7cb884b77Evan Huntmy $input = "";
38122021242747404f7f3e02ff4428a7cb884b77Evan Huntwhile (defined(my $line = <$file>) ) {
38122021242747404f7f3e02ff4428a7cb884b77Evan Hunt chomp $line;
38122021242747404f7f3e02ff4428a7cb884b77Evan Hunt $line =~ s/#.*$//;
38122021242747404f7f3e02ff4428a7cb884b77Evan Hunt $input .= $line;
38122021242747404f7f3e02ff4428a7cb884b77Evan Hunt}
38122021242747404f7f3e02ff4428a7cb884b77Evan Hunt
38122021242747404f7f3e02ff4428a7cb884b77Evan Hunt$input =~ s/\s+//g;
38122021242747404f7f3e02ff4428a7cb884b77Evan Huntmy $data = pack("H*", $input);
38122021242747404f7f3e02ff4428a7cb884b77Evan Huntmy $len = length $data;
38122021242747404f7f3e02ff4428a7cb884b77Evan Hunt
38122021242747404f7f3e02ff4428a7cb884b77Evan Huntbinmode(STDOUT);
38122021242747404f7f3e02ff4428a7cb884b77Evan Huntprint($data);
38122021242747404f7f3e02ff4428a7cb884b77Evan Huntexit(0);