Initial import from FreeBSD RELENG_4:
[dragonfly.git] / contrib / perl5 / t / lib / io_udp.t
1 #!./perl
2
3 BEGIN {
4     unless(grep /blib/, @INC) {
5         chdir 't' if -d 't';
6         @INC = '../lib' if -d '../lib';
7     }
8 }
9
10 use Config;
11
12 BEGIN {
13     if(-d "lib" && -f "TEST") {
14         if ( ($Config{'extensions'} !~ /\bSocket\b/ ||
15               $Config{'extensions'} !~ /\bIO\b/ ||
16               ($^O eq 'os2') || $^O eq 'apollo')    &&
17               !(($^O eq 'VMS') && $Config{d_socket})) {
18             print "1..0\n";
19             exit 0;
20         }
21     }
22 }
23
24 $| = 1;
25 print "1..3\n";
26
27 use Socket;
28 use IO::Socket qw(AF_INET SOCK_DGRAM INADDR_ANY);
29
30     # This can fail if localhost is undefined or the
31     # special 'loopback' address 127.0.0.1 is not configured
32     # on your system. (/etc/rc.config.d/netconfig on HP-UX.)
33     # As a shortcut (not recommended) you could change 'localhost'
34     # here to be the name of this machine eg 'myhost.mycompany.com'.
35
36 $udpa = IO::Socket::INET->new(Proto => 'udp', LocalAddr => 'localhost')
37     or die "$! (maybe your system does not have the 'localhost' address defined)";
38 $udpb = IO::Socket::INET->new(Proto => 'udp', LocalAddr => 'localhost')
39     or die "$! (maybe your system does not have the 'localhost' address defined)";
40
41 print "ok 1\n";
42
43 $udpa->send("ok 2\n",0,$udpb->sockname);
44 $udpb->recv($buf="",5);
45 print $buf;
46 $udpb->send("ok 3\n");
47 $udpa->recv($buf="",5);
48 print $buf;