1*0Sstevel@tonic-gate#!./perl 2*0Sstevel@tonic-gate 3*0Sstevel@tonic-gate# Check for presence and correctness of .ph files; for now, 4*0Sstevel@tonic-gate# just socket.ph and pals. 5*0Sstevel@tonic-gate# -- Kurt Starsinic <kstar@isinet.com> 6*0Sstevel@tonic-gate 7*0Sstevel@tonic-gateBEGIN { 8*0Sstevel@tonic-gate chdir 't' if -d 't'; 9*0Sstevel@tonic-gate @INC = '../lib'; 10*0Sstevel@tonic-gate} 11*0Sstevel@tonic-gate 12*0Sstevel@tonic-gate# All the constants which Socket.pm tries to make available: 13*0Sstevel@tonic-gatemy @possibly_defined = qw( 14*0Sstevel@tonic-gate INADDR_ANY INADDR_LOOPBACK INADDR_NONE AF_802 AF_APPLETALK AF_CCITT 15*0Sstevel@tonic-gate AF_CHAOS AF_DATAKIT AF_DECnet AF_DLI AF_ECMA AF_GOSIP AF_HYLINK AF_IMPLINK 16*0Sstevel@tonic-gate AF_INET AF_LAT AF_MAX AF_NBS AF_NIT AF_NS AF_OSI AF_OSINET AF_PUP 17*0Sstevel@tonic-gate AF_SNA AF_UNIX AF_UNSPEC AF_X25 MSG_DONTROUTE MSG_MAXIOVLEN MSG_OOB 18*0Sstevel@tonic-gate MSG_PEEK PF_802 PF_APPLETALK PF_CCITT PF_CHAOS PF_DATAKIT PF_DECnet PF_DLI 19*0Sstevel@tonic-gate PF_ECMA PF_GOSIP PF_HYLINK PF_IMPLINK PF_INET PF_LAT PF_MAX PF_NBS PF_NIT 20*0Sstevel@tonic-gate PF_NS PF_OSI PF_OSINET PF_PUP PF_SNA PF_UNIX PF_UNSPEC PF_X25 SOCK_DGRAM 21*0Sstevel@tonic-gate SOCK_RAW SOCK_RDM SOCK_SEQPACKET SOCK_STREAM SOL_SOCKET SOMAXCONN 22*0Sstevel@tonic-gate SO_ACCEPTCONN SO_BROADCAST SO_DEBUG SO_DONTLINGER SO_DONTROUTE SO_ERROR 23*0Sstevel@tonic-gate SO_KEEPALIVE SO_LINGER SO_OOBINLINE SO_RCVBUF SO_RCVLOWAT SO_RCVTIMEO 24*0Sstevel@tonic-gate SO_REUSEADDR SO_SNDBUF SO_SNDLOWAT SO_SNDTIMEO SO_TYPE SO_USELOOPBACK 25*0Sstevel@tonic-gate); 26*0Sstevel@tonic-gate 27*0Sstevel@tonic-gate 28*0Sstevel@tonic-gate# The libraries which I'm going to require: 29*0Sstevel@tonic-gatemy @libs = qw(Socket "sys/types.ph" "sys/socket.ph" "netinet/in.ph"); 30*0Sstevel@tonic-gate 31*0Sstevel@tonic-gate 32*0Sstevel@tonic-gate# These are defined by Socket.pm even if the C header files don't define them: 33*0Sstevel@tonic-gatemy %ok_to_miss = ( 34*0Sstevel@tonic-gate INADDR_NONE => 1, 35*0Sstevel@tonic-gate INADDR_LOOPBACK => 1, 36*0Sstevel@tonic-gate); 37*0Sstevel@tonic-gate 38*0Sstevel@tonic-gate 39*0Sstevel@tonic-gatemy $total_tests = scalar @libs + scalar @possibly_defined; 40*0Sstevel@tonic-gatemy $i = 0; 41*0Sstevel@tonic-gate 42*0Sstevel@tonic-gateprint "1..$total_tests\n"; 43*0Sstevel@tonic-gate 44*0Sstevel@tonic-gate 45*0Sstevel@tonic-gateforeach (@libs) { 46*0Sstevel@tonic-gate $i++; 47*0Sstevel@tonic-gate 48*0Sstevel@tonic-gate if (eval "require $_" ) { 49*0Sstevel@tonic-gate print "ok $i\n"; 50*0Sstevel@tonic-gate } else { 51*0Sstevel@tonic-gate print "# Skipping tests; $_ may be missing\n"; 52*0Sstevel@tonic-gate foreach ($i .. $total_tests) { print "ok $_\n" } 53*0Sstevel@tonic-gate exit; 54*0Sstevel@tonic-gate } 55*0Sstevel@tonic-gate} 56*0Sstevel@tonic-gate 57*0Sstevel@tonic-gate 58*0Sstevel@tonic-gateforeach (@possibly_defined) { 59*0Sstevel@tonic-gate $i++; 60*0Sstevel@tonic-gate 61*0Sstevel@tonic-gate $pm_val = eval "Socket::$_()"; 62*0Sstevel@tonic-gate $ph_val = eval "main::$_()"; 63*0Sstevel@tonic-gate 64*0Sstevel@tonic-gate if (defined $pm_val and !defined $ph_val) { 65*0Sstevel@tonic-gate if ($ok_to_miss{$_}) { print "ok $i\n" } 66*0Sstevel@tonic-gate else { print "not ok $i\n" } 67*0Sstevel@tonic-gate next; 68*0Sstevel@tonic-gate } elsif (defined $ph_val and !defined $pm_val) { 69*0Sstevel@tonic-gate print "not ok $i\n"; 70*0Sstevel@tonic-gate next; 71*0Sstevel@tonic-gate } 72*0Sstevel@tonic-gate 73*0Sstevel@tonic-gate # Socket.pm converts these to network byte order, so we convert the 74*0Sstevel@tonic-gate # socket.ph version to match; note that these cases skip the following 75*0Sstevel@tonic-gate # `elsif', which is only applied to _numeric_ values, not literal 76*0Sstevel@tonic-gate # bitmasks. 77*0Sstevel@tonic-gate if ($_ eq 'INADDR_ANY' 78*0Sstevel@tonic-gate or $_ eq 'INADDR_LOOPBACK' 79*0Sstevel@tonic-gate or $_ eq 'INADDR_NONE') { 80*0Sstevel@tonic-gate $ph_val = pack("N*", $ph_val); # htonl(3) equivalent 81*0Sstevel@tonic-gate } 82*0Sstevel@tonic-gate 83*0Sstevel@tonic-gate # Since Socket.pm and socket.ph wave their hands over macros differently, 84*0Sstevel@tonic-gate # they could return functionally equivalent bitmaps with different numeric 85*0Sstevel@tonic-gate # interpretations (due to sign extension). The only apparent case of this 86*0Sstevel@tonic-gate # is SO_DONTLINGER (only on Solaris, and deprecated, at that): 87*0Sstevel@tonic-gate elsif ($pm_val != $ph_val) { 88*0Sstevel@tonic-gate $pm_val = oct(sprintf "0x%lx", $pm_val); 89*0Sstevel@tonic-gate $ph_val = oct(sprintf "0x%lx", $ph_val); 90*0Sstevel@tonic-gate } 91*0Sstevel@tonic-gate 92*0Sstevel@tonic-gate if ($pm_val == $ph_val) { print "ok $i\n" } 93*0Sstevel@tonic-gate else { print "not ok $i\n" } 94*0Sstevel@tonic-gate} 95*0Sstevel@tonic-gate 96*0Sstevel@tonic-gate 97