1#!/usr/local/bin/perl
2
3use Convert::ASN1 qw(:io);
4use IO::Socket;
5
6print "1..11\n";
7
8my  $result = pack("C*", 0x30, 0x3D, 0x04, 0x04, 0x46, 0x72, 0x65, 0x64,
9			 0x30, 0x13, 0x04, 0x11, 0x41, 0x20, 0x73, 0x74,
10			 0x72, 0x69, 0x6E, 0x67, 0x20, 0x66, 0x6F, 0x72,
11			 0x20, 0x66, 0x72, 0x65, 0x64, 0x04, 0x03, 0x4A,
12			 0x6F, 0x65, 0x30, 0x1B, 0x04, 0x03, 0x68, 0x61,
13			 0x73, 0x04, 0x01, 0x61, 0x04, 0x04, 0x6C, 0x69,
14			 0x73, 0x74, 0x04, 0x02, 0x6F, 0x66, 0x04, 0x07,
15			 0x73, 0x74, 0x72, 0x69, 0x6E, 0x67, 0x73);
16
17($file = $0) =~ s/t$/dat/;
18open(OUT,"> $file");
19asn_write(*OUT, $result);
20asn_write(*OUT, $result);
21close(OUT);
22
23open(IN,"< $file");
24sysread(IN,$buffer,1024);
25close(IN);
26
27print "not " unless $buffer eq $result x 2;
28print "ok 1\n";
29
30open(IN,"< $file");
31asn_read(*IN, $input);
32close(IN);
33
34print "not " unless $input eq $result;
35print "ok 2\n";
36
37open(IN,"< $file");
38
39undef $input;
40$input = asn_get(*IN);
41print "not " unless $input eq $result;
42print "ok 3\n";
43
44print "not " unless asn_ready(*IN);
45print "ok 4\n";
46
47undef $input;
48$input = asn_get(*IN);
49print "not " unless $input eq $result;
50print "ok 5\n";
51
52print "not " if asn_ready(*IN);
53print "ok 6\n";
54
55close(IN);
56
57unlink($file);
58
59my $src = IO::Socket::INET->new(Proto => 'udp');
60my $dst = IO::Socket::INET->new(Proto => 'udp');
61bind($dst, pack_sockaddr_in(0, INADDR_ANY));
62my $host = $dst->sockhost eq '0.0.0.0' ? '127.0.0.1' : $dst->sockhost;
63my $addr = pack_sockaddr_in($dst->sockport, inet_aton($host));
64
65asn_send($src,$result,0,$addr) or print "not ";
66print "ok 7\n";
67
68asn_recv($dst, $in2, 0) or print "not ";
69print "ok 8\n";
70
71print "not " unless $in2 && $in2 eq $result;
72print "ok 9\n";
73
74open(IN,"t/07input.dat") or die "Cannot open 07input.dat: $!\n";
75undef $input;
76my $n = asn_read(*IN,$input);
77print "not " unless $n and $n == length($input);
78print "ok 10\n";
79print "not " unless $n == 1283;
80print "ok 11\n";
81
82