From unknown Fri Nov  6 19:26:49 1992
SUB: Re: FAQ ? : Sun RPC's in perl wanted
SUM: Tom Christiansen <tchrist@convex.COM>, tchrist@convex.COM (Tom Christiansen)->Perl-Users@fuggles.acc.Virginia.EDU

>From the keyboard of peter@micromuse.co.uk (Peter Galbavy):
:This is more then likely an FAQ - but I cannot find an answer:
:
:Is there an implmentation of Sun RPC's in perl (a perl API more than
:anything) ?

Here's a hard-coded hack for a rup inplementation.


    #!/usr/local/bin/perl

    die "usage: $0 hostname\n" unless @ARGV;

    $pat = 'S n C4 x8';

    $stream = 1;
    $datagram = 2;

    $inet = 2;

    $tcp = 6;
    $udp = 17;


    ($name,$aliases,$port) = getservbyname('sunrpc','udp');

    for $host (@ARGV) {

	if ($host =~ /^\d+\./) {
	    @bytes = split(/\./,$host);
	}
	else {
	    ($name,$aliases,$addrtype,$length,@addrs) = gethostbyname($host);
	    die "Can't lookup $host\n" unless $name;
	    @bytes = unpack("C4",$addrs[0]);
	}

	$this = pack($pat,$inet,0,    0,0,0,0);
	$that = pack($pat,$inet,$port,@bytes);

	socket(S,2,$datagram,$udp) || die "socket: $!\n";
	bind(S,$this) || die "bind: $!\n";
	connect(S,$that) || die "connect: $!\n";

	select(S); $| = 1; select(stdout); $| = 1;

	print S pack("N13", 1956, 0, 2, 100000, 2, 5, 0, 0, 0, 0, 100001, 3, 1);

	read(S, $_, 32767);

	@r = unpack("N" . length($_)/4, $_);
	#print join(' ', @r), "\n";
	printf("%-30s %4.2f %4.2f %4.2f\n",
		$name,$r[26]/256, $r[27]/256, $r[28]/256);

	if ($r[0] != 1956) {
	    die "xid error\n";
	} elsif ($r[1] != 1) {
	    die "Not a reply!\n";
	} elsif ($r[2] == 1) {
	    if ($r[3] == 0) {
		    die "Rejected - RPC_MISMATCH\n";
	    } elsif ($r[3] == 1) {
		    die "Rejected - AUTH_ERROR\n";
	    } else {
		    die "Rejected - unknown code\n";
	    }
	} else {
	    print '', (("SUCCESS", "PROG_UNAVAIL", "PROG_MISMATCH", "PROC_UNAVAIL",
		    "GARBAGE_ARGS")[$r[5]]), "\n";
	}

	close S;

    }


--tom
-- 
    Tom Christiansen      tchrist@convex.com      convex!tchrist

Justice is incidental to law and order.
                -- J. Edgar Hoover


