home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.madoka.org
/
2014.12.ftp.madoka.org.tar
/
ftp.madoka.org
/
pub
/
plum
/
2.x
/
plum2_15_4.lzh
/
support
/
pclient
< prev
next >
Wrap
Text File
|
1997-12-13
|
2KB
|
79 lines
#!/bin/perl -w
# $Id: pclient,v 2.4 1997/12/13 23:16:02 hasegawa Exp $
# copyright (c)1997 pupu_j <hasegawa@agusa.nuie.nagoya-u.ac.jp>
$SOCKADDR = 'S n a4 x8';
$PROTO = getprotobyname('tcp');
if ($] < 5) {
foreach $inc (@INC) {
if (-r "$inc/sys/socket.ph") {
eval 'require "sys/socket.ph"';
$SOCKET = "$inc/sys/socket.ph" unless $@;
last;
}
}
} else {
eval 'use Socket';
$SOCKET = 'Socket.pm' unless $@;
}
$AF_INET = eval { &AF_INET } || 2;
$PF_INET = eval { &PF_INET } || 2;
$SOCK_STREAM = eval { &SOCK_STREAM } || 1;
&main(@ARGV);
sub main {
local(@args) = @_;
local($host, $port, $rin, $rout, $serv, $addr, $stdin, $nf, $left, $cbuf, $sbuf, $tmp);
if (@args < 2) {
&usage();
exit(1);
}
($host, $port) = @args;
if ($host =~ /(\d+)\.(\d+)\.(\d+)\.(\d+)/) {
$addr = pack('C4', $1, $2, $3, $4);
} elsif ($host =~ /^\d+$/) {
$addr = pack('N', $host);
} else {
$addr = (gethostbyname($host))[4];
}
defined($addr) || die "$host not found\n";
socket(SOCKET, $PF_INET, $SOCK_STREAM, $PROTO) || die "cannot create socket\n";
connect(SOCKET, pack($SOCKADDR, $AF_INET, $port, $addr)) || die "cannot connect to server\n";
$serv = fileno(SOCKET);
$stdin = fileno(STDIN);
$rin = '';
vec($rin, $serv, 1) = 1;
vec($rin, $stdin, 1) = 1;
select((select(SOCKET), $| = 1)[0]);
select((select(STDIN), $| = 1)[0]);
select((select(STDOUT), $| = 1)[0]);
$cbuf = $sbuf = $tmp = '';
for (;;) {
($nf, $left) = select($rout = $rin, undef, undef, undef);
if (vec($rout, $serv, 1)) {
sysread(SOCKET, $tmp, 1024) || die "connection closed\n";
$sbuf .= $tmp;
while ((($next, $rest) = split(/[\r\n]+/, $sbuf, 2)) == 2) {
print STDOUT $next, "\n";
$sbuf = $rest || '';
}
$sbuf = $next || '';
} elsif (vec($rout, $stdin, 1)) {
sysread(STDIN, $tmp, 1024) || die "connection closed\n";
$cbuf .= $tmp;
while ((($next, $rest) = split(/[\r\n]+/, $cbuf, 2)) == 2) {
print SOCKET $next, "\n";
$cbuf = $rest || '';
}
$cbuf = $next || '';
}
}
}
sub usage {
print 'usage: perl pclient <server> <port>', "\n";
}