1#!/usr/bin/perl
2
3# Copyright (C) Internet Systems Consortium, Inc. ("ISC")
4#
5# SPDX-License-Identifier: MPL-2.0
6#
7# This Source Code Form is subject to the terms of the Mozilla Public
8# License, v. 2.0.  If a copy of the MPL was not distributed with this
9# file, you can obtain one at https://mozilla.org/MPL/2.0/.
10#
11# See the COPYRIGHT file distributed with this work for additional
12# information regarding copyright ownership.
13
14# Converts hex ascii into raw data.
15# (This can be used, for example, to construct input for "wire_data -d".)
16
17require 5.006.001;
18
19use strict;
20use IO::File;
21
22sub usage {
23    print ("Usage: packet.pl [file]\n");
24    exit 1;
25}
26
27my $file = "STDIN";
28if (@ARGV >= 1) {
29    my $filename = shift @ARGV;
30    open FH, "<$filename" or die "$filename: $!";
31    $file = "FH";
32}
33
34my $input = "";
35while (defined(my $line = <$file>) ) {
36    chomp $line;
37    $line =~ s/#.*$//;
38    $input .= $line;
39}
40
41$input =~ s/\s+//g;
42my $data = pack("H*", $input);
43my $len = length $data;
44
45binmode(STDOUT);
46print($data);
47exit(0);
48