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